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

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

Issue 2317893002: [Offline Pages] Close race condition of multiple StartProcessing callers. (Closed)
Patch Set: Pete feedback - clear starting flag in deadbeat timeout case Created 4 years, 3 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 ffd1768e056cb126da16755b518dbb9ae50a69f8..2754ec0884408c04b3c52fdffedfefe042d2531c 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -79,6 +79,7 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
std::unique_ptr<RequestQueue> queue,
std::unique_ptr<Scheduler> scheduler)
: is_busy_(false),
+ is_starting_(false),
is_stopped_(false),
use_test_connection_type_(false),
test_connection_type_(),
@@ -345,7 +346,9 @@ bool RequestCoordinator::StartProcessing(
const DeviceConditions& device_conditions,
const base::Callback<void(bool)>& callback) {
current_conditions_.reset(new DeviceConditions(device_conditions));
- if (is_busy_) return false;
+ if (is_starting_ || is_busy_)
+ return false;
+ is_starting_ = true;
// Mark the time at which we started processing so we can check our time
// budget.
@@ -383,6 +386,8 @@ void RequestCoordinator::TryNextRequest() {
if (base::Time::Now() - operation_start_time_ >
base::TimeDelta::FromSeconds(
policy_->GetBackgroundProcessingTimeBudgetSeconds())) {
+ is_starting_ = false;
+
// Let the scheduler know we are done processing.
scheduler_callback_.Run(true);
@@ -400,12 +405,19 @@ void RequestCoordinator::TryNextRequest() {
// Called by the request picker when a request has been picked.
void RequestCoordinator::RequestPicked(const SavePageRequest& request) {
- // Send the request on to the offliner.
- SendRequestToOffliner(request);
+ is_starting_ = false;
+
+ // Make sure we were not stopped while picking.
+ if (!is_stopped_) {
+ // Send the request on to the offliner.
+ SendRequestToOffliner(request);
+ }
}
void RequestCoordinator::RequestNotPicked(
bool non_user_requested_tasks_remaining) {
+ is_starting_ = false;
+
// Clear the outstanding "safety" task in the scheduler.
scheduler_->Unschedule();

Powered by Google App Engine
This is Rietveld 408576698