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 41bde51e8ad7870b2e847f95b04429bec738a17c..ae50f7e0855d6722ed216d7bca5198b930fe20d9 100644 |
--- a/components/offline_pages/background/request_coordinator.cc |
+++ b/components/offline_pages/background/request_coordinator.cc |
@@ -31,6 +31,8 @@ RequestCoordinator::RequestCoordinator(std::unique_ptr<OfflinerPolicy> policy, |
std::unique_ptr<RequestQueue> queue, |
std::unique_ptr<Scheduler> scheduler) |
: is_busy_(false), |
+ is_canceled_(false), |
+ offliner_(nullptr), |
policy_(std::move(policy)), |
factory_(std::move(factory)), |
queue_(std::move(queue)), |
@@ -95,10 +97,18 @@ bool RequestCoordinator::StartProcessing( |
const base::Callback<void(bool)>& callback) { |
if (is_busy_) return false; |
+ is_canceled_ = false; |
scheduler_callback_ = callback; |
// TODO(petewil): Check existing conditions (should be passed down from |
// BackgroundTask) |
+ GetOffliner(); |
dougarnett
2016/06/23 17:19:17
I wonder about this check here. Maybe you can say
Pete Williamson
2016/06/23 17:54:53
My thought here was that if we can't get an offlin
|
+ if (!offliner_) { |
+ DVLOG(0) << "Unable to create Offliner. " |
+ << "Cannot background offline page."; |
+ return false; |
+ } |
+ |
TryNextRequest(); |
return true; |
@@ -115,6 +125,9 @@ void RequestCoordinator::TryNextRequest() { |
} |
void RequestCoordinator::StopProcessing() { |
+ is_canceled_ = true; |
+ if (offliner_ && is_busy_) |
+ offliner_->Cancel(); |
} |
Scheduler::TriggerConditions const& |
@@ -123,9 +136,11 @@ RequestCoordinator::GetTriggerConditionsForUserRequest() { |
} |
void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
- // TODO(petewil): When we have multiple offliners, we need to pick one. |
- Offliner* offliner = factory_->GetOffliner(policy_.get()); |
- if (!offliner) { |
+ if (is_canceled_) |
dougarnett
2016/06/23 17:19:17
// Be sure processing hasn't been canceled.
Pete Williamson
2016/06/23 17:54:53
Comment added (I worded it slightly differently).
|
+ return; |
+ |
+ GetOffliner(); |
+ if (!offliner_) { |
DVLOG(0) << "Unable to create Offliner. " |
<< "Cannot background offline page."; |
return; |
@@ -135,16 +150,16 @@ void RequestCoordinator::SendRequestToOffliner(const SavePageRequest& request) { |
is_busy_ = true; |
// 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; |
is_busy_ = false; |
@@ -163,4 +178,10 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request, |
} |
} |
+void RequestCoordinator::GetOffliner() { |
+ if (!offliner_) { |
+ offliner_ = factory_->GetOffliner(policy_.get()); |
+ } |
+} |
+ |
} // namespace offline_pages |