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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_offliner.cc

Issue 2818783002: [Offline pages]: Implement background loader to save on last retry, and record last retry success U… (Closed)
Patch Set: request coordinator update 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 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/prerendering_offliner.h" 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" 10 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // Clear pending request and app listener here and then inform loader we 152 // Clear pending request and app listener here and then inform loader we
153 // are done with WebContents. 153 // are done with WebContents.
154 pending_request_.reset(nullptr); 154 pending_request_.reset(nullptr);
155 app_listener_.reset(nullptr); 155 app_listener_.reset(nullptr);
156 GetOrCreateLoader()->StopLoading(); 156 GetOrCreateLoader()->StopLoading();
157 157
158 // Determine status and run the completion callback. 158 // Determine status and run the completion callback.
159 Offliner::RequestStatus save_status; 159 Offliner::RequestStatus save_status;
160 if (save_result == SavePageResult::SUCCESS) { 160 if (save_result == SavePageResult::SUCCESS) {
161 save_status = RequestStatus::SAVED; 161 if (saved_on_last_retry_)
Pete Williamson 2017/04/13 22:57:15 Should we clear this in the ctor just for complete
fgorski 2017/04/14 05:15:57 If by clear you mean initialize: +1 ... And Cathy
chili 2017/04/15 00:34:59 Done. This actually caused a test failure T___T
162 save_status = RequestStatus::SAVED_ON_LAST_RETRY;
163 else
164 save_status = RequestStatus::SAVED;
162 } else { 165 } else {
163 // TODO(dougarnett): Consider reflecting some recommendation to retry the 166 // TODO(dougarnett): Consider reflecting some recommendation to retry the
164 // request based on specific save error cases. 167 // request based on specific save error cases.
165 save_status = RequestStatus::SAVE_FAILED; 168 save_status = RequestStatus::SAVE_FAILED;
166 } 169 }
170 saved_on_last_retry_ = false;
167 completion_callback_.Run(request, save_status); 171 completion_callback_.Run(request, save_status);
168 } 172 }
169 173
170 bool PrerenderingOffliner::LoadAndSave( 174 bool PrerenderingOffliner::LoadAndSave(
171 const SavePageRequest& request, 175 const SavePageRequest& request,
172 const CompletionCallback& completion_callback, 176 const CompletionCallback& completion_callback,
173 const ProgressCallback& progress_callback) { 177 const ProgressCallback& progress_callback) {
174 DCHECK(!pending_request_.get()); 178 DCHECK(!pending_request_.get());
175 179
176 if (pending_request_) { 180 if (pending_request_) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 callback.Run(request_id); 265 callback.Run(request_id);
262 } 266 }
263 267
264 bool PrerenderingOffliner::HandleTimeout(const SavePageRequest& request) { 268 bool PrerenderingOffliner::HandleTimeout(const SavePageRequest& request) {
265 if (pending_request_) { 269 if (pending_request_) {
266 DCHECK(request.request_id() == pending_request_->request_id()); 270 DCHECK(request.request_id() == pending_request_->request_id());
267 if (GetOrCreateLoader()->IsLowbarMet() && 271 if (GetOrCreateLoader()->IsLowbarMet() &&
268 (request.started_attempt_count() + 1 >= policy_->GetMaxStartedTries() || 272 (request.started_attempt_count() + 1 >= policy_->GetMaxStartedTries() ||
269 request.completed_attempt_count() + 1 >= 273 request.completed_attempt_count() + 1 >=
270 policy_->GetMaxCompletedTries())) { 274 policy_->GetMaxCompletedTries())) {
275 saved_on_last_retry_ = true;
271 GetOrCreateLoader()->StartSnapshot(); 276 GetOrCreateLoader()->StartSnapshot();
272 return true; 277 return true;
273 } 278 }
274 } 279 }
275 return false; 280 return false;
276 } 281 }
277 282
278 void PrerenderingOffliner::SetLoaderForTesting( 283 void PrerenderingOffliner::SetLoaderForTesting(
279 std::unique_ptr<PrerenderingLoader> loader) { 284 std::unique_ptr<PrerenderingLoader> loader) {
280 DCHECK(!loader_); 285 DCHECK(!loader_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 void PrerenderingOffliner::HandleApplicationStateChangeCancel( 328 void PrerenderingOffliner::HandleApplicationStateChangeCancel(
324 const SavePageRequest& request, 329 const SavePageRequest& request,
325 int64_t offline_id) { 330 int64_t offline_id) {
326 // This shouldn't be immediate, but account for case where request was reset 331 // This shouldn't be immediate, but account for case where request was reset
327 // while waiting for callback. 332 // while waiting for callback.
328 if (pending_request_ && pending_request_->request_id() != offline_id) 333 if (pending_request_ && pending_request_->request_id() != offline_id)
329 return; 334 return;
330 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); 335 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED);
331 } 336 }
332 } // namespace offline_pages 337 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698