Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: content/browser/background_fetch/background_fetch_data_manager.cc

Issue 2978603003: [Background Fetch] Tidy up getting/activating pending requests (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/background_fetch/background_fetch_data_manager.cc
diff --git a/content/browser/background_fetch/background_fetch_data_manager.cc b/content/browser/background_fetch/background_fetch_data_manager.cc
index 52c5ae50b97d6c4709bc380eef5611aa7b66ed2b..8e9adc64fcf7127c13a23e03bddf0723a25099b5 100644
--- a/content/browser/background_fetch/background_fetch_data_manager.cc
+++ b/content/browser/background_fetch/background_fetch_data_manager.cc
@@ -54,7 +54,7 @@ class BackgroundFetchDataManager::RegistrationData {
bool HasPendingRequests() const { return !pending_requests_.empty(); }
// Consumes a request from the queue that is to be fetched.
- scoped_refptr<BackgroundFetchRequestInfo> GetPendingRequest() {
+ scoped_refptr<BackgroundFetchRequestInfo> ActivateNextPendingRequest() {
DCHECK(!pending_requests_.empty());
auto request = pending_requests_.front();
@@ -146,31 +146,33 @@ void BackgroundFetchDataManager::CreateRegistration(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (registrations_.find(registration_id) != registrations_.end()) {
- std::move(callback).Run(
- blink::mojom::BackgroundFetchError::DUPLICATED_TAG,
- std::vector<scoped_refptr<BackgroundFetchRequestInfo>>());
+ std::move(callback).Run(blink::mojom::BackgroundFetchError::DUPLICATED_TAG);
return;
}
- std::unique_ptr<RegistrationData> registration_data =
- base::MakeUnique<RegistrationData>(requests, options);
+ // Create the |RegistrationData|, and store it for easy access.
+ registrations_.insert(std::make_pair(
+ registration_id, base::MakeUnique<RegistrationData>(requests, options)));
- // Create a vector with the initial requests to feed the Job Controller with.
- std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests;
- for (size_t i = 0; i < kMaximumBackgroundFetchParallelRequests; ++i) {
- if (!registration_data->HasPendingRequests())
- break;
+ // Inform the |callback| of the newly created registration.
+ std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE);
+}
- initial_requests.push_back(registration_data->GetPendingRequest());
- }
+void BackgroundFetchDataManager::ActivateNextRequest(
+ const BackgroundFetchRegistrationId& registration_id,
+ NextRequestCallback callback) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- // Store the created |registration_data| so that we can easily access it.
- registrations_.insert(
- std::make_pair(registration_id, std::move(registration_data)));
+ auto iter = registrations_.find(registration_id);
+ DCHECK(iter != registrations_.end());
- // Inform the |callback| of the newly created registration.
- std::move(callback).Run(blink::mojom::BackgroundFetchError::NONE,
- std::move(initial_requests));
+ RegistrationData* registration_data = iter->second.get();
+
+ scoped_refptr<BackgroundFetchRequestInfo> next_request;
+ if (registration_data->HasPendingRequests())
+ next_request = registration_data->ActivateNextPendingRequest();
+
+ std::move(callback).Run(std::move(next_request));
}
void BackgroundFetchDataManager::MarkRequestAsStarted(
@@ -186,7 +188,7 @@ void BackgroundFetchDataManager::MarkRequestAsStarted(
registration_data->MarkRequestAsStarted(request, download_guid);
}
-void BackgroundFetchDataManager::MarkRequestAsCompleteAndGetNextRequest(
+void BackgroundFetchDataManager::MarkRequestAsCompleteAndActivateNextRequest(
const BackgroundFetchRegistrationId& registration_id,
BackgroundFetchRequestInfo* request,
NextRequestCallback callback) {
@@ -198,11 +200,7 @@ void BackgroundFetchDataManager::MarkRequestAsCompleteAndGetNextRequest(
RegistrationData* registration_data = iter->second.get();
registration_data->MarkRequestAsComplete(request);
- scoped_refptr<BackgroundFetchRequestInfo> next_request;
- if (registration_data->HasPendingRequests())
- next_request = registration_data->GetPendingRequest();
-
- std::move(callback).Run(std::move(next_request));
+ ActivateNextRequest(registration_id, std::move(callback));
}
void BackgroundFetchDataManager::GetSettledFetchesForRegistration(

Powered by Google App Engine
This is Rietveld 408576698