summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuyen Chau Nguyen <hello@chau-nguyen.de>2018-10-31 09:50:13 +0100
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-11-15 12:19:48 -0800
commit9a606caf0b33d5dba33e33ce3fb59724e1849eb1 (patch)
treec37a39c05f185ea4cd20275b538afdf34e892f2d
parente25111dba7b3d9c5d09437feb85404e6eabb9875 (diff)
downloadqtlocation-mapboxgl-9a606caf0b33d5dba33e33ce3fb59724e1849eb1.tar.gz
[core] define number of concurrent downloads in online file source variable
-rw-r--r--include/mbgl/storage/online_file_source.hpp4
-rw-r--r--platform/android/src/http_file_source.cpp4
-rw-r--r--platform/darwin/src/http_file_source.mm4
-rw-r--r--platform/default/http_file_source.cpp4
-rw-r--r--platform/default/mbgl/storage/offline_download.cpp6
-rw-r--r--platform/default/mbgl/storage/offline_download.hpp5
-rw-r--r--platform/default/online_file_source.cpp35
-rw-r--r--platform/qt/src/http_file_source.cpp4
-rw-r--r--src/mbgl/storage/http_file_source.hpp2
-rw-r--r--test/storage/online_file_source.test.cpp4
10 files changed, 30 insertions, 42 deletions
diff --git a/include/mbgl/storage/online_file_source.hpp b/include/mbgl/storage/online_file_source.hpp
index b921413490..b2e9b43e5d 100644
--- a/include/mbgl/storage/online_file_source.hpp
+++ b/include/mbgl/storage/online_file_source.hpp
@@ -24,9 +24,11 @@ public:
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
+ void setMaximumConcurrentRequests(uint32_t);
+ uint32_t getMaximumConcurrentRequests() const;
+
// For testing only.
void setOnlineStatus(bool);
- void setMaximumConcurrentRequestsOverride(uint32_t);
private:
friend class OnlineFileRequest;
diff --git a/platform/android/src/http_file_source.cpp b/platform/android/src/http_file_source.cpp
index bb6fc90e45..e7826e38a9 100644
--- a/platform/android/src/http_file_source.cpp
+++ b/platform/android/src/http_file_source.cpp
@@ -188,8 +188,4 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
return std::make_unique<HTTPRequest>(*impl->env, resource, callback);
}
-uint32_t HTTPFileSource::maximumConcurrentRequests() {
- return 20;
-}
-
} // namespace mbgl
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm
index 9726f6064f..f11d44ea54 100644
--- a/platform/darwin/src/http_file_source.mm
+++ b/platform/darwin/src/http_file_source.mm
@@ -193,10 +193,6 @@ HTTPFileSource::HTTPFileSource()
HTTPFileSource::~HTTPFileSource() = default;
-uint32_t HTTPFileSource::maximumConcurrentRequests() {
- return 20;
-}
-
std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, Callback callback) {
auto request = std::make_unique<HTTPRequest>(callback);
auto shared = request->shared; // Explicit copy so that it also gets copied into the completion handler block below.
diff --git a/platform/default/http_file_source.cpp b/platform/default/http_file_source.cpp
index 9166d92fb7..213b53de98 100644
--- a/platform/default/http_file_source.cpp
+++ b/platform/default/http_file_source.cpp
@@ -492,8 +492,4 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
return std::make_unique<HTTPRequest>(impl.get(), resource, callback);
}
-uint32_t HTTPFileSource::maximumConcurrentRequests() {
- return 20;
-}
-
} // namespace mbgl
diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp
index 6524697546..c97797a5a2 100644
--- a/platform/default/mbgl/storage/offline_download.cpp
+++ b/platform/default/mbgl/storage/offline_download.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/storage/file_source.hpp>
+#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/storage/offline_database.hpp>
#include <mbgl/storage/offline_download.hpp>
#include <mbgl/storage/resource.hpp>
@@ -84,7 +84,7 @@ uint64_t tileCount(const OfflineRegionDefinition& definition, style::SourceType
OfflineDownload::OfflineDownload(int64_t id_,
OfflineRegionDefinition&& definition_,
OfflineDatabase& offlineDatabase_,
- FileSource& onlineFileSource_)
+ OnlineFileSource& onlineFileSource_)
: id(id_),
definition(definition_),
offlineDatabase(offlineDatabase_),
@@ -340,7 +340,7 @@ void OfflineDownload::continueDownload() {
return;
}
- while (!resourcesRemaining.empty() && requests.size() < HTTPFileSource::maximumConcurrentRequests()) {
+ while (!resourcesRemaining.empty() && requests.size() < onlineFileSource.getMaximumConcurrentRequests()) {
ensureResource(resourcesRemaining.front());
resourcesRemaining.pop_front();
}
diff --git a/platform/default/mbgl/storage/offline_download.hpp b/platform/default/mbgl/storage/offline_download.hpp
index cffac1665b..1e77ff1d35 100644
--- a/platform/default/mbgl/storage/offline_download.hpp
+++ b/platform/default/mbgl/storage/offline_download.hpp
@@ -2,6 +2,7 @@
#include <mbgl/storage/offline.hpp>
#include <mbgl/storage/resource.hpp>
+#include <mbgl/storage/online_file_source.hpp>
#include <list>
#include <unordered_set>
@@ -27,7 +28,7 @@ class Parser;
*/
class OfflineDownload {
public:
- OfflineDownload(int64_t id, OfflineRegionDefinition&&, OfflineDatabase& offline, FileSource& online);
+ OfflineDownload(int64_t id, OfflineRegionDefinition&&, OfflineDatabase& offline, OnlineFileSource& online);
~OfflineDownload();
void setObserver(std::unique_ptr<OfflineRegionObserver>);
@@ -52,7 +53,7 @@ private:
int64_t id;
OfflineRegionDefinition definition;
OfflineDatabase& offlineDatabase;
- FileSource& onlineFileSource;
+ OnlineFileSource& onlineFileSource;
OfflineRegionStatus status;
std::unique_ptr<OfflineRegionObserver> observer;
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 6c930b3fec..fce1c3e2b6 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -25,6 +25,8 @@
namespace mbgl {
+static uint32_t DEFAULT_MAXIMUM_CONCURRENT_REQUESTS = 20;
+
class OnlineFileRequest : public AsyncRequest {
public:
using Callback = std::function<void (Response)>;
@@ -64,6 +66,7 @@ class OnlineFileSource::Impl {
public:
Impl() {
NetworkStatus::Subscribe(&reachability);
+ setMaximumConcurrentRequests(DEFAULT_MAXIMUM_CONCURRENT_REQUESTS);
}
~Impl() {
@@ -156,21 +159,16 @@ public:
networkIsReachableAgain();
}
- void setMaximumConcurrentRequestsOverride(const uint32_t maximumConcurrentRequestsOverride_) {
- maximumConcurrentRequestsOverride = maximumConcurrentRequestsOverride_;
+ uint32_t getMaximumConcurrentRequests() const {
+ return maximumConcurrentRequests;
}
-private:
-
- uint32_t getMaximumConcurrentRequests() const {
- if (maximumConcurrentRequestsOverride > 0) {
- return maximumConcurrentRequestsOverride;
- }
- else {
- return HTTPFileSource::maximumConcurrentRequests();
- }
+ void setMaximumConcurrentRequests(uint32_t maximumConcurrentRequests_) {
+ maximumConcurrentRequests = maximumConcurrentRequests_;
}
+private:
+
void networkIsReachableAgain() {
for (auto& request : allRequests) {
request->networkIsReachableAgain();
@@ -260,7 +258,7 @@ private:
std::unordered_set<OnlineFileRequest*> activeRequests;
bool online = true;
- uint32_t maximumConcurrentRequestsOverride = 0;
+ uint32_t maximumConcurrentRequests;
HTTPFileSource httpFileSource;
util::AsyncTask reachability { std::bind(&Impl::networkIsReachableAgain, this) };
};
@@ -472,14 +470,19 @@ ActorRef<OnlineFileRequest> OnlineFileRequest::actor() {
return ActorRef<OnlineFileRequest>(*this, mailbox);
}
+void OnlineFileSource::setMaximumConcurrentRequests(uint32_t maximumConcurrentRequests_) {
+ impl->setMaximumConcurrentRequests(maximumConcurrentRequests_);
+}
+
+uint32_t OnlineFileSource::getMaximumConcurrentRequests() const {
+ return impl->getMaximumConcurrentRequests();
+}
+
+
// For testing only:
void OnlineFileSource::setOnlineStatus(const bool status) {
impl->setOnlineStatus(status);
}
-void OnlineFileSource::setMaximumConcurrentRequestsOverride(const uint32_t maximumConcurrentRequestsOverride) {
- impl->setMaximumConcurrentRequestsOverride(maximumConcurrentRequestsOverride);
-}
-
} // namespace mbgl
diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp
index f4fb0749a6..b8553a5a55 100644
--- a/platform/qt/src/http_file_source.cpp
+++ b/platform/qt/src/http_file_source.cpp
@@ -98,8 +98,4 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
return std::make_unique<HTTPRequest>(impl.get(), resource, callback);
}
-uint32_t HTTPFileSource::maximumConcurrentRequests() {
- return 20;
-}
-
} // namespace mbgl
diff --git a/src/mbgl/storage/http_file_source.hpp b/src/mbgl/storage/http_file_source.hpp
index 47976f972e..09834aa4dc 100644
--- a/src/mbgl/storage/http_file_source.hpp
+++ b/src/mbgl/storage/http_file_source.hpp
@@ -11,8 +11,6 @@ public:
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
- static uint32_t maximumConcurrentRequests();
-
class Impl;
private:
diff --git a/test/storage/online_file_source.test.cpp b/test/storage/online_file_source.test.cpp
index 39582543ef..36d6f63a77 100644
--- a/test/storage/online_file_source.test.cpp
+++ b/test/storage/online_file_source.test.cpp
@@ -433,7 +433,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequests)) {
std::size_t response_counter = 0;
const std::size_t NUM_REQUESTS = 3;
- fs.setMaximumConcurrentRequestsOverride(1);
+ fs.setMaximumConcurrentRequests(1);
NetworkStatus::Set(NetworkStatus::Status::Offline);
@@ -473,7 +473,7 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequestsMany)) {
int correct_regular = 0;
- fs.setMaximumConcurrentRequestsOverride(1);
+ fs.setMaximumConcurrentRequests(1);
NetworkStatus::Set(NetworkStatus::Status::Offline);