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

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

Issue 2091473004: Add the ability to cancel prerender reqeusts and tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment changes per DougArnett Created 4 years, 6 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 41bde51e8ad7870b2e847f95b04429bec738a17c..05ce9ffe9f656143119f54df05814fd7d91a7ccf 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,6 +97,7 @@ 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)
@@ -115,6 +118,9 @@ void RequestCoordinator::TryNextRequest() {
}
void RequestCoordinator::StopProcessing() {
+ is_canceled_ = true;
+ if (offliner_ && is_busy_)
+ offliner_->Cancel();
}
Scheduler::TriggerConditions const&
@@ -123,9 +129,13 @@ 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) {
+ // Check that offlining didn't get cancelled while performing some async
+ // steps.
+ if (is_canceled_)
+ return;
+
+ GetOffliner();
+ if (!offliner_) {
DVLOG(0) << "Unable to create Offliner. "
<< "Cannot background offline page.";
return;
@@ -135,16 +145,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 +173,10 @@ void RequestCoordinator::OfflinerDoneCallback(const SavePageRequest& request,
}
}
+void RequestCoordinator::GetOffliner() {
+ if (!offliner_) {
+ offliner_ = factory_->GetOffliner(policy_.get());
+ }
+}
+
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698