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

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

Issue 2178143002: Check time budget before starting new requests, and unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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: 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 a78d58cbdcfe24663f5e444c1777d3ab4155c104..f120ffb1fb37f914ed857fadce06200b9bb9e9f6 100644
--- a/components/offline_pages/background/request_coordinator.cc
+++ b/components/offline_pages/background/request_coordinator.cc
@@ -35,14 +35,6 @@ const Scheduler::TriggerConditions kUserRequestTriggerConditions(
false /* require_power_connected */,
50 /* minimum_battery_percentage */,
false /* require_unmetered_network */);
-
-// Timeout is 2.5 minutes based on the size of Marshmallow doze mode
-// maintenance window (3 minutes)
-// TODO(petewil): Find the optimal timeout based on data for 2G connections and
-// common EM websites. crbug.com/625204
-// TODO(petewil): Move this value into the policy object.
-long OFFLINER_TIMEOUT_SECONDS = 150;
-
} // namespace
RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
@@ -51,13 +43,15 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy,
std::unique_ptr<Scheduler> scheduler)
: is_busy_(false),
is_canceled_(false),
- offliner_timeout_(base::TimeDelta::FromSeconds(OFFLINER_TIMEOUT_SECONDS)),
offliner_(nullptr),
+ operation_start_time_(base::Time::Now()),
jianli 2016/07/25 21:50:38 It seems to me that this initialization was not ne
Pete Williamson 2016/07/25 22:01:33 Done.
policy_(std::move(policy)),
factory_(std::move(factory)),
queue_(std::move(queue)),
scheduler_(std::move(scheduler)),
last_offlining_status_(Offliner::RequestStatus::UNKNOWN),
+ offliner_timeout_(base::TimeDelta::FromSeconds(
+ policy_->GetSinglePageTimeBudgetInSeconds())),
weak_ptr_factory_(this) {
DCHECK(policy_ != nullptr);
picker_.reset(new RequestPicker(queue_.get(), policy_.get()));
@@ -128,6 +122,10 @@ bool RequestCoordinator::StartProcessing(
current_conditions_.reset(new DeviceConditions(device_conditions));
if (is_busy_) return false;
+ // Mark the time at which we started processing so we can check our time
+ // budget.
+ operation_start_time_ = base::Time::Now();
+
is_canceled_ = false;
scheduler_callback_ = callback;
// TODO(petewil): Check existing conditions (should be passed down from
@@ -139,6 +137,15 @@ bool RequestCoordinator::StartProcessing(
}
void RequestCoordinator::TryNextRequest() {
+ // If there is no time left in the budget, return to the scheduler, but leave
+ // the "safety" task, so we get called again next time.
jianli 2016/07/25 21:50:38 I found it hard to understand what the "safety" ta
Pete Williamson 2016/07/25 22:01:33 Done. I was referring to something in the design
+ if (base::Time::Now() - operation_start_time_ >
+ base::TimeDelta::FromSeconds(
+ policy_->GetBackgroundProcessingTimeBudgetSeconds())) {
+ // Let the scheduler know we are done processing.
+ scheduler_callback_.Run(true);
jianli 2016/07/25 21:50:38 Do we need to return here?
Pete Williamson 2016/07/25 22:01:33 Oh my goodness, you're right! Added.
+ }
+
// Choose a request to process that meets the available conditions.
// This is an async call, and returns right away.
picker_->ChooseNextRequest(
@@ -229,8 +236,6 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
weak_ptr_factory_.GetWeakPtr()));
}
- // TODO(petewil): Check time budget. Return to the scheduler if we are out.
- // Start another request if we have time.
TryNextRequest();
}

Powered by Google App Engine
This is Rietveld 408576698