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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h" 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 9 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
10 #include "chrome/browser/android/offline_pages/offliner_helper.h" 10 #include "chrome/browser/android/offline_pages/offliner_helper.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 app_listener_.reset(new base::android::ApplicationStatusListener( 102 app_listener_.reset(new base::android::ApplicationStatusListener(
103 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange, 103 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange,
104 weak_ptr_factory_.GetWeakPtr()))); 104 weak_ptr_factory_.GetWeakPtr())));
105 105
106 // Load page attempt. 106 // Load page attempt.
107 loader_.get()->LoadPage(request.url()); 107 loader_.get()->LoadPage(request.url());
108 108
109 return true; 109 return true;
110 } 110 }
111 111
112 void BackgroundLoaderOffliner::Cancel() { 112 void BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
113 // TODO(chili): We are not able to cancel a pending 113 // TODO(chili): We are not able to cancel a pending
114 // OfflinePageModel::SavePage() operation. We just ignore the callback. 114 // 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
115 if (!pending_request_) 115 if (!pending_request_) {
116 callback.Run(0L);
116 return; 117 return;
118 }
117 119
118 if (save_state_ != NONE) { 120 if (save_state_ != NONE) {
119 save_state_ = DELETE_AFTER_SAVE; 121 save_state_ = DELETE_AFTER_SAVE;
122 cancel_callback_ = callback;
120 return; 123 return;
121 } 124 }
122 125
126 int64_t request_id = pending_request_->request_id();
123 ResetState(); 127 ResetState();
128 callback.Run(request_id);
124 } 129 }
125 130
126 void BackgroundLoaderOffliner::DidStopLoading() { 131 void BackgroundLoaderOffliner::DidStopLoading() {
127 if (!pending_request_.get()) { 132 if (!pending_request_.get()) {
128 DVLOG(1) << "DidStopLoading called even though no pending request."; 133 DVLOG(1) << "DidStopLoading called even though no pending request.";
129 return; 134 return;
130 } 135 }
131 136
132 SavePageRequest request(*pending_request_.get()); 137 SavePageRequest request(*pending_request_.get());
133 // If there was an error navigating to page, return loading failed. 138 // If there was an error navigating to page, return loading failed.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result, 234 void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result,
230 int64_t offline_id) { 235 int64_t offline_id) {
231 if (!pending_request_) 236 if (!pending_request_)
232 return; 237 return;
233 238
234 SavePageRequest request(*pending_request_.get()); 239 SavePageRequest request(*pending_request_.get());
235 ResetState(); 240 ResetState();
236 241
237 if (save_state_ == DELETE_AFTER_SAVE) { 242 if (save_state_ == DELETE_AFTER_SAVE) {
238 save_state_ = NONE; 243 save_state_ = NONE;
244 cancel_callback_.Run(request.request_id());
239 return; 245 return;
240 } 246 }
241 247
242 save_state_ = NONE; 248 save_state_ = NONE;
243 249
244 Offliner::RequestStatus save_status; 250 Offliner::RequestStatus save_status;
245 if (save_result == SavePageResult::SUCCESS) 251 if (save_result == SavePageResult::SUCCESS)
246 save_status = RequestStatus::SAVED; 252 save_status = RequestStatus::SAVED;
247 else 253 else
248 save_status = RequestStatus::SAVE_FAILED; 254 save_status = RequestStatus::SAVE_FAILED;
(...skipping 14 matching lines...) Expand all
263 content::WebContentsObserver::Observe(loader_.get()->web_contents()); 269 content::WebContentsObserver::Observe(loader_.get()->web_contents());
264 } 270 }
265 271
266 void BackgroundLoaderOffliner::OnApplicationStateChange( 272 void BackgroundLoaderOffliner::OnApplicationStateChange(
267 base::android::ApplicationState application_state) { 273 base::android::ApplicationState application_state) {
268 if (pending_request_ && is_low_end_device_ && 274 if (pending_request_ && is_low_end_device_ &&
269 application_state == 275 application_state ==
270 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { 276 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
271 DVLOG(1) << "App became active, canceling current offlining request"; 277 DVLOG(1) << "App became active, canceling current offlining request";
272 SavePageRequest* request = pending_request_.get(); 278 SavePageRequest* request = pending_request_.get();
273 Cancel(); 279 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.
274 completion_callback_.Run(*request, RequestStatus::FOREGROUND_CANCELED); 280 &BackgroundLoaderOffliner::HandleApplicationStateChangeCancel,
281 weak_ptr_factory_.GetWeakPtr(), *request));
275 } 282 }
276 } 283 }
277 284
285 void BackgroundLoaderOffliner::HandleApplicationStateChangeCancel(
286 const SavePageRequest& request,
287 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
288 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED);
289 }
278 } // namespace offline_pages 290 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698