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

Unified Diff: content/browser/background_fetch/background_fetch_job_controller.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_job_controller.cc
diff --git a/content/browser/background_fetch/background_fetch_job_controller.cc b/content/browser/background_fetch/background_fetch_job_controller.cc
index 1032fa2e70bcb75cc3dc4bb7213a26aa07c25d77..9aeaf65772f89b1f4bc596720e905defd32d74bc 100644
--- a/content/browser/background_fetch/background_fetch_job_controller.cc
+++ b/content/browser/background_fetch/background_fetch_job_controller.cc
@@ -260,22 +260,28 @@ BackgroundFetchJobController::~BackgroundFetchJobController() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
};
-void BackgroundFetchJobController::Start(
- std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
+void BackgroundFetchJobController::Start() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- DCHECK_LE(initial_requests.size(), kMaximumBackgroundFetchParallelRequests);
DCHECK_EQ(state_, State::INITIALIZED);
state_ = State::FETCHING;
- for (const auto& request : initial_requests)
- StartRequest(request);
+ // TODO(johnme): Enforce kMaximumBackgroundFetchParallelRequests globally
+ // and/or per origin rather than per fetch.
Peter Beverloo 2017/07/11 16:10:55 Please file a bug for this - scheduling will be a
johnme 2017/07/12 13:13:10 Done.
+ for (size_t i = 0; i < kMaximumBackgroundFetchParallelRequests; i++) {
+ data_manager_->ActivateNextRequest(
+ registration_id_,
+ base::BindOnce(&BackgroundFetchJobController::StartRequest,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
}
void BackgroundFetchJobController::StartRequest(
scoped_refptr<BackgroundFetchRequestInfo> request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_EQ(state_, State::FETCHING);
+ if (!request)
+ return; // No more pending requests to start.
Peter Beverloo 2017/07/11 16:10:55 Please document that this bail-out is only applica
johnme 2017/07/12 13:13:10 Done.
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&Core::StartRequest, ui_core_ptr_,
std::move(request), traffic_annotation_));
@@ -297,7 +303,7 @@ void BackgroundFetchJobController::DidCompleteRequest(
// no more pending requests to avoid marking this job as completed too early.
pending_completed_file_acknowledgements_++;
- data_manager_->MarkRequestAsCompleteAndGetNextRequest(
+ data_manager_->MarkRequestAsCompleteAndActivateNextRequest(
Peter Beverloo 2017/07/11 16:10:55 What about splitting up MarkRequestAsComplete so t
johnme 2017/07/12 13:13:10 Done (yeah, I'd been considering that; initially I
registration_id_, request.get(),
base::BindOnce(&BackgroundFetchJobController::DidGetNextRequest,
weak_ptr_factory_.GetWeakPtr()));

Powered by Google App Engine
This is Rietveld 408576698