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

Unified Diff: components/offline_pages/background/request_coordinator.cc

Issue 2078113002: Don't start a second pre-render if one is in progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redo unit test to use StartProcessing Created 4 years, 6 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: components/offline_pages/background/request_coordinator.cc
diff --git a/components/offline_pages/background/request_coordinator.cc b/components/offline_pages/background/request_coordinator.cc
index d5e87d26a47a8fd93aa7af30aa2dacef1ad23837..4a52f781abec56288589ce78f8fe1b69d2940776 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -22,7 +22,8 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
std::unique_ptr<OfflinerFactory> factory,
std::unique_ptr<RequestQueue> queue,
std::unique_ptr<Scheduler> scheduler)
- : policy_(std::move(policy)),
+ : is_busy_(false),
+ policy_(std::move(policy)),
factory_(std::move(factory)),
queue_(std::move(queue)),
scheduler_(std::move(scheduler)),
@@ -50,11 +51,6 @@ bool RequestCoordinator::SavePageLater(
queue_->AddRequest(request,
base::Bind(&RequestCoordinator::AddRequestResultCallback,
weak_ptr_factory_.GetWeakPtr()));
- // TODO(petewil): Do I need to persist the request in case the add fails?
-
- // TODO(petewil): Make a new chromium command line switch to send the request
- // immediately for testing. It should call SendRequestToOffliner()
-
return true;
}
@@ -85,19 +81,19 @@ void RequestCoordinator::RequestQueueEmpty() {
scheduler_callback_.Run(true);
}
+// Returns true if the caller should expect a callback, false otherwise. For
+// instance, this would return false if a request is already in progress.
bool RequestCoordinator::StartProcessing(
const DeviceConditions& device_conditions,
const base::Callback<void(bool)>& callback) {
+ if (is_busy_) return false;
+
scheduler_callback_ = callback;
// TODO(petewil): Check existing conditions (should be passed down from
// BackgroundTask)
TryNextRequest();
- // TODO(petewil): Should return true if the caller should expect a
- // callback. Return false if there is already a request running.
- // Probably best to do this when I prevent multiple instances from
- // running at the same time.
return true;
}
@@ -115,7 +111,6 @@ void RequestCoordinator::StopProcessing() {
}
void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) {
- // TODO(petewil): Ensure only one offliner at a time is used.
// TODO(petewil): When we have multiple offliners, we need to pick one.
Offliner* offliner = factory_->GetOffliner(policy_.get());
if (!offliner) {
@@ -124,6 +119,9 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) {
return;
}
+ DCHECK(!is_busy_);
+ is_busy_ = true;
+
// Start the load and save process in the offliner (Async).
offliner->LoadAndSave(request,
base::Bind(&RequestCoordinator::OfflinerDoneCallback,
@@ -137,6 +135,8 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
<< __FUNCTION__;
last_offlining_status_ = status;
+ is_busy_ = false;
+
// If the request succeeded, remove it from the Queue and maybe schedule
// another one.
if (status == Offliner::RequestStatus::SAVED) {

Powered by Google App Engine
This is Rietveld 408576698