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..9d7ddfe8fa8e7dd2f9b8895f6d390ba2137199a8 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)), |
+ : offliner_(nullptr), |
+ policy_(std::move(policy)), |
factory_(std::move(factory)), |
queue_(std::move(queue)), |
scheduler_(std::move(scheduler)), |
@@ -88,10 +89,19 @@ void RequestCoordinator::RequestQueueEmpty() { |
bool RequestCoordinator::StartProcessing( |
const DeviceConditions& device_conditions, |
const base::Callback<void(bool)>& callback) { |
+ started_ = false; |
+ cancelled_ = false; |
Pete Williamson
2016/06/22 22:53:22
FYI - there may be some overlap with the is_busy_
chili
2016/06/23 05:42:06
nit - we seem to have different spellings of cance
Pete Williamson
2016/06/23 16:46:13
When I checked with a dictionary, both were legit,
|
scheduler_callback_ = callback; |
// TODO(petewil): Check existing conditions (should be passed down from |
// BackgroundTask) |
+ GetOffliner(); |
+ if (!offliner_) { |
+ DVLOG(0) << "Unable to create Offliner. " |
+ << "Cannot background offline page."; |
+ return false; |
+ } |
+ |
TryNextRequest(); |
// TODO(petewil): Should return true if the caller should expect a |
@@ -112,30 +122,36 @@ void RequestCoordinator::TryNextRequest() { |
} |
void RequestCoordinator::StopProcessing() { |
+ cancelled_ = true; |
+ if (offliner_ && started_) |
+ offliner_->Cancel(); |
} |
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) { |
+ if (cancelled_) |
+ return; |
+ started_ = true; |
+ |
+ GetOffliner(); |
+ if (!offliner_) { |
DVLOG(0) << "Unable to create Offliner. " |
<< "Cannot background offline page."; |
return; |
} |
// Start the load and save process in the offliner (Async). |
- offliner->LoadAndSave(request, |
- base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
- weak_ptr_factory_.GetWeakPtr())); |
+ offliner_->LoadAndSave(request, |
+ base::Bind(&RequestCoordinator::OfflinerDoneCallback, |
+ weak_ptr_factory_.GetWeakPtr())); |
} |
void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
Offliner::RequestStatus status) { |
DVLOG(2) << "offliner finished, saved: " |
- << (status == Offliner::RequestStatus::SAVED) << ", " |
- << __FUNCTION__; |
+ << (status == Offliner::RequestStatus::SAVED) << ", status: " |
+ << (int) status << ", " << __FUNCTION__; |
last_offlining_status_ = status; |
+ started_ = false; |
// If the request succeeded, remove it from the Queue and maybe schedule |
// another one. |
@@ -151,4 +167,10 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
} |
} |
+void RequestCoordinator::GetOffliner() { |
+ if (!offliner_) { |
+ offliner_ = factory_->GetOffliner(policy_.get()); |
+ } |
+} |
+ |
} // namespace offline_pages |