Chromium Code Reviews| 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 d7798c4c5b26e9bbda7b181d86aec2a11033d958..a980601e700092b09674b9e44937c2e728a54159 100644 |
| --- a/components/offline_pages/background/request_coordinator.cc |
| +++ b/components/offline_pages/background/request_coordinator.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/bind.h" |
| #include "base/callback.h" |
| #include "base/logging.h" |
| +#include "base/time/time.h" |
| #include "components/offline_pages/background/offliner_factory.h" |
| #include "components/offline_pages/background/offliner_policy.h" |
| #include "components/offline_pages/background/request_picker.h" |
| @@ -24,6 +25,12 @@ const Scheduler::TriggerConditions kUserRequestTriggerConditions( |
| false /* require_power_connected */, |
| 50 /* minimum_battery_percentage */, |
| false /* require_unmetered_network */); |
| + |
| +// Timeout is 3 minutes based on the size of Marshmallow doze mode |
| +// maintenance window. TODO(petewil): Find the optimal timeout based |
|
dougarnett
2016/06/30 19:16:48
maybe line break before TODO
dewittj
2016/06/30 20:38:33
Please make a bug specifically to find this number
Pete Williamson
2016/07/01 17:16:54
Done.
Pete Williamson
2016/07/01 17:16:55
Done.
|
| +// on data for 2G connections and common EM websites. |
|
dougarnett
2016/06/30 19:16:48
another TODO might be to move this value into Poli
Pete Williamson
2016/07/01 17:16:55
Done.
|
| +long OFFLINER_TIMEOUT_SECONDS = 180; |
|
dewittj
2016/06/30 20:38:33
If this is exactly the marshmallow timeout, then t
Pete Williamson
2016/07/01 17:16:54
Done.
|
| + |
| } // namespace |
| RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| @@ -32,6 +39,7 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
| std::unique_ptr<Scheduler> scheduler) |
| : is_busy_(false), |
| is_canceled_(false), |
| + offliner_timeout_(OFFLINER_TIMEOUT_SECONDS), |
| offliner_(nullptr), |
| policy_(std::move(policy)), |
| factory_(std::move(factory)), |
| @@ -81,6 +89,9 @@ void RequestCoordinator::StopProcessing() { |
| is_canceled_ = true; |
| if (offliner_ && is_busy_) |
| offliner_->Cancel(); |
| + |
| + // Return control to the scheduler when there is no more to do. |
|
dougarnett
2016/06/30 19:16:48
Think this comment needs some rewording. Perhaps
/
Pete Williamson
2016/07/01 17:16:55
Done (changed here and in RequestQueueEmpty)
|
| + scheduler_callback_.Run(true); |
| } |
| // Returns true if the caller should expect a callback, false otherwise. For |
| @@ -143,6 +154,11 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
| offliner_->LoadAndSave(request, |
| base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
| weak_ptr_factory_.GetWeakPtr())); |
| + |
| + // Start a watchdog timer to catch pre-renders running too long |
| + watchdog_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromSeconds(offliner_timeout_), this, |
| + &RequestCoordinator::StopProcessing); |
| } |
| void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| @@ -155,6 +171,7 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
| "Saved", |
| request.request_id()); |
| last_offlining_status_ = status; |
| + watchdog_timer_.Stop(); |
| is_busy_ = false; |