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

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

Issue 2836863002: [Offline pages] Removing active_request_ from request coordinator (Closed)
Patch Set: Removing extra dcheck Created 3 years, 8 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 74d0f08af3773e979efb8e6c79bc350401de8e94..93c05e457efb4be89980dcea1b6e3d09994bef40 100644
--- a/chrome/browser/android/offline_pages/background_loader_offliner.cc
+++ b/chrome/browser/android/offline_pages/background_loader_offliner.cc
@@ -190,32 +190,33 @@ bool BackgroundLoaderOffliner::LoadAndSave(
}
void BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
+ DCHECK(pending_request_);
+ // We ignore the case where pending_request_ is not set, but given the checks
+ // in RequestCoordinator this should not happen.
+ if (!pending_request_)
Pete Williamson 2017/04/24 17:41:37 I know it shouldn't happen, but if it does somehow
fgorski 2017/04/24 21:40:58 Done. I addressed that by changing the interface o
+ return;
+
// TODO(chili): We are not able to cancel a pending
// OfflinePageModel::SaveSnapshot() operation. We will notify caller that
// cancel completed once the SavePage operation returns.
- if (!pending_request_) {
- callback.Run(0LL);
- return;
- }
-
if (save_state_ != NONE) {
save_state_ = DELETE_AFTER_SAVE;
cancel_callback_ = callback;
return;
}
- int64_t request_id = pending_request_->request_id();
+ SavePageRequest canceled_request(*pending_request_.get());
ResetState();
- callback.Run(request_id);
+ callback.Run(canceled_request);
}
-bool BackgroundLoaderOffliner::HandleTimeout(const SavePageRequest& request) {
+bool BackgroundLoaderOffliner::HandleTimeout(int64_t request_id) {
if (pending_request_) {
- DCHECK(request.request_id() == pending_request_->request_id());
- if (is_low_bar_met_ &&
- (request.started_attempt_count() + 1 >= policy_->GetMaxStartedTries() ||
- request.completed_attempt_count() + 1 >=
- policy_->GetMaxCompletedTries())) {
+ DCHECK(request_id == pending_request_->request_id());
+ if (is_low_bar_met_ && (pending_request_->started_attempt_count() + 1 >=
Pete Williamson 2017/04/24 17:41:37 nit - the new line wraps make the code a bit more
fgorski 2017/04/24 21:40:58 It was through git cl format.
+ policy_->GetMaxStartedTries() ||
+ pending_request_->completed_attempt_count() + 1 >=
+ policy_->GetMaxCompletedTries())) {
// If we are already in the middle of a save operation, let it finish
// but do not return SAVED_ON_LAST_RETRY
if (save_state_ == NONE) {
@@ -402,7 +403,7 @@ void BackgroundLoaderOffliner::OnPageSaved(SavePageResult save_result,
if (save_state_ == DELETE_AFTER_SAVE) {
save_state_ = NONE;
- cancel_callback_.Run(request.request_id());
+ cancel_callback_.Run(request);
return;
}
@@ -446,23 +447,25 @@ void BackgroundLoaderOffliner::OnApplicationStateChange(
application_state ==
base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
DVLOG(1) << "App became active, canceling current offlining request";
- SavePageRequest* request = pending_request_.get();
- // This works because Bind will make a copy of request, and we
- // should not have to worry about reset being called before cancel callback.
Cancel(base::Bind(
&BackgroundLoaderOffliner::HandleApplicationStateChangeCancel,
- weak_ptr_factory_.GetWeakPtr(), *request));
+ weak_ptr_factory_.GetWeakPtr()));
}
}
void BackgroundLoaderOffliner::HandleApplicationStateChangeCancel(
- const SavePageRequest& request,
- int64_t offline_id) {
+ const SavePageRequest& canceled_request) {
+ DCHECK_EQ(pending_request_->request_id(), canceled_request.request_id());
// If for some reason the request was reset during while waiting for callback
// ignore the completion callback.
- if (pending_request_ && pending_request_->request_id() != offline_id)
+ if (pending_request_ &&
+ pending_request_->request_id() != canceled_request.request_id()) {
return;
- completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED);
+ }
+ // TODO(chili, petewil): So where is the reset state called, and might that be
chili 2017/04/24 17:44:53 The reset state is handled in the cancel: Applica
fgorski 2017/04/24 21:40:58 The problem is that pending_request_ is already re
+ // the reason for wez's problems?
+ completion_callback_.Run(canceled_request,
Pete Williamson 2017/04/24 17:41:37 Was Wez using the background loader offliner? (I
fgorski 2017/04/24 21:40:58 Per our discussion it wasn't the bug filed by wez,
+ RequestStatus::FOREGROUND_CANCELED);
}
void BackgroundLoaderOffliner::AddLoadingSignal(const char* signal_name) {

Powered by Google App Engine
This is Rietveld 408576698