| 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..408dc1dbb9ddeaa8c6d4868a1a8815bc3b3e4c16 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> PopNextPendingRequest() {
|
| DCHECK(!pending_requests_.empty());
|
|
|
| auto request = pending_requests_.front();
|
| @@ -83,7 +83,7 @@ class BackgroundFetchDataManager::RegistrationData {
|
|
|
| // Marks the |request| as having completed. Verifies that the |request| is
|
| // currently active and moves it to the |completed_requests_| vector.
|
| - void MarkRequestAsComplete(BackgroundFetchRequestInfo* request) {
|
| + bool MarkRequestAsComplete(BackgroundFetchRequestInfo* request) {
|
| const auto iter = std::find_if(
|
| active_requests_.begin(), active_requests_.end(),
|
| [&request](scoped_refptr<BackgroundFetchRequestInfo> active_request) {
|
| @@ -95,6 +95,10 @@ class BackgroundFetchDataManager::RegistrationData {
|
|
|
| completed_requests_.push_back(*iter);
|
| active_requests_.erase(iter);
|
| +
|
| + bool has_pending_or_active_requests =
|
| + !pending_requests_.empty() || !active_requests_.empty();
|
| + return has_pending_or_active_requests;
|
| }
|
|
|
| // Returns the vector with all completed requests part of this registration.
|
| @@ -146,31 +150,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::PopNextRequest(
|
| + 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->PopNextPendingRequest();
|
| +
|
| + std::move(callback).Run(std::move(next_request));
|
| }
|
|
|
| void BackgroundFetchDataManager::MarkRequestAsStarted(
|
| @@ -186,23 +192,20 @@ void BackgroundFetchDataManager::MarkRequestAsStarted(
|
| registration_data->MarkRequestAsStarted(request, download_guid);
|
| }
|
|
|
| -void BackgroundFetchDataManager::MarkRequestAsCompleteAndGetNextRequest(
|
| +void BackgroundFetchDataManager::MarkRequestAsComplete(
|
| const BackgroundFetchRegistrationId& registration_id,
|
| BackgroundFetchRequestInfo* request,
|
| - NextRequestCallback callback) {
|
| + MarkedCompleteCallback callback) {
|
| DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
|
|
| auto iter = registrations_.find(registration_id);
|
| DCHECK(iter != registrations_.end());
|
|
|
| RegistrationData* registration_data = iter->second.get();
|
| - registration_data->MarkRequestAsComplete(request);
|
| + bool has_pending_or_active_requests =
|
| + 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));
|
| + std::move(callback).Run(has_pending_or_active_requests);
|
| }
|
|
|
| void BackgroundFetchDataManager::GetSettledFetchesForRegistration(
|
|
|