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

Unified Diff: chrome/browser/android/offline_pages/background_loader_offliner.cc

Issue 2715433006: [Offline Pages] Turn Offliner::Cancel into an async operation to resolve conflicting assumptions (Closed)
Patch Set: Created 3 years, 10 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: chrome/browser/android/offline_pages/background_loader_offliner.cc
diff --git a/chrome/browser/android/offline_pages/background_loader_offliner.cc b/chrome/browser/android/offline_pages/background_loader_offliner.cc
index 732a4eca3a09ec77bba2bbc4366e30faed6f2413..1bdd2410da38929de7c40758514cbf6b7e5cfe34 100644
--- a/chrome/browser/android/offline_pages/background_loader_offliner.cc
+++ b/chrome/browser/android/offline_pages/background_loader_offliner.cc
@@ -109,18 +109,23 @@ bool BackgroundLoaderOffliner::LoadAndSave(const SavePageRequest& request,
return true;
}
-void BackgroundLoaderOffliner::Cancel() {
+void BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
// TODO(chili): We are not able to cancel a pending
// OfflinePageModel::SavePage() operation. We just ignore the callback.
fgorski 2017/02/27 18:07:25 Is this TODO valid after your change?
chili 2017/02/28 00:44:14 TODO still somewhat valid, since this is simply ge
- if (!pending_request_)
+ if (!pending_request_) {
+ callback.Run(0L);
return;
+ }
if (save_state_ != NONE) {
save_state_ = DELETE_AFTER_SAVE;
+ cancel_callback_ = callback;
return;
}
+ int64_t request_id = pending_request_->request_id();
ResetState();
+ callback.Run(request_id);
}
void BackgroundLoaderOffliner::DidStopLoading() {
@@ -236,6 +241,7 @@ void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result,
if (save_state_ == DELETE_AFTER_SAVE) {
save_state_ = NONE;
+ cancel_callback_.Run(request.request_id());
return;
}
@@ -270,9 +276,15 @@ void BackgroundLoaderOffliner::OnApplicationStateChange(
base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
DVLOG(1) << "App became active, canceling current offlining request";
SavePageRequest* request = pending_request_.get();
- Cancel();
- completion_callback_.Run(*request, RequestStatus::FOREGROUND_CANCELED);
+ Cancel(base::Bind(
fgorski 2017/02/27 18:07:25 Please document that it works, because Bind will m
chili 2017/02/28 00:44:14 Done.
+ &BackgroundLoaderOffliner::HandleApplicationStateChangeCancel,
+ weak_ptr_factory_.GetWeakPtr(), *request));
}
}
+void BackgroundLoaderOffliner::HandleApplicationStateChangeCancel(
+ const SavePageRequest& request,
+ int64_t offline_id) {
fgorski 2017/02/27 18:07:25 I don't understand the signature to the cancel cal
chili 2017/02/28 00:44:14 Added a check. The cancel callback was mainly for
+ completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED);
+}
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698