Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 PrerenderingOffliner::PrerenderingOffliner( | 32 PrerenderingOffliner::PrerenderingOffliner( |
| 33 content::BrowserContext* browser_context, | 33 content::BrowserContext* browser_context, |
| 34 const OfflinerPolicy* policy, | 34 const OfflinerPolicy* policy, |
| 35 OfflinePageModel* offline_page_model) | 35 OfflinePageModel* offline_page_model) |
| 36 : browser_context_(browser_context), | 36 : browser_context_(browser_context), |
| 37 policy_(policy), | 37 policy_(policy), |
| 38 offline_page_model_(offline_page_model), | 38 offline_page_model_(offline_page_model), |
| 39 pending_request_(nullptr), | 39 pending_request_(nullptr), |
| 40 is_low_end_device_(base::SysInfo::IsLowEndDevice()), | 40 is_low_end_device_(base::SysInfo::IsLowEndDevice()), |
| 41 saved_on_last_retry_(false), | |
| 41 app_listener_(nullptr), | 42 app_listener_(nullptr), |
| 42 weak_ptr_factory_(this) {} | 43 weak_ptr_factory_(this) {} |
| 43 | 44 |
| 44 PrerenderingOffliner::~PrerenderingOffliner() {} | 45 PrerenderingOffliner::~PrerenderingOffliner() {} |
| 45 | 46 |
| 46 void PrerenderingOffliner::OnNetworkProgress(const SavePageRequest& request, | 47 void PrerenderingOffliner::OnNetworkProgress(const SavePageRequest& request, |
| 47 int64_t bytes) { | 48 int64_t bytes) { |
| 48 if (!pending_request_ || !progress_callback_) | 49 if (!pending_request_ || !progress_callback_) |
| 49 return; | 50 return; |
| 50 | 51 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 152 |
| 152 // Clear pending request and app listener here and then inform loader we | 153 // Clear pending request and app listener here and then inform loader we |
| 153 // are done with WebContents. | 154 // are done with WebContents. |
| 154 pending_request_.reset(nullptr); | 155 pending_request_.reset(nullptr); |
| 155 app_listener_.reset(nullptr); | 156 app_listener_.reset(nullptr); |
| 156 GetOrCreateLoader()->StopLoading(); | 157 GetOrCreateLoader()->StopLoading(); |
| 157 | 158 |
| 158 // Determine status and run the completion callback. | 159 // Determine status and run the completion callback. |
| 159 Offliner::RequestStatus save_status; | 160 Offliner::RequestStatus save_status; |
| 160 if (save_result == SavePageResult::SUCCESS) { | 161 if (save_result == SavePageResult::SUCCESS) { |
| 161 save_status = RequestStatus::SAVED; | 162 if (saved_on_last_retry_) |
| 163 save_status = RequestStatus::SAVED_ON_LAST_RETRY; | |
| 164 else | |
| 165 save_status = RequestStatus::SAVED; | |
| 162 } else { | 166 } else { |
| 163 // TODO(dougarnett): Consider reflecting some recommendation to retry the | 167 // TODO(dougarnett): Consider reflecting some recommendation to retry the |
| 164 // request based on specific save error cases. | 168 // request based on specific save error cases. |
| 165 save_status = RequestStatus::SAVE_FAILED; | 169 save_status = RequestStatus::SAVE_FAILED; |
| 166 } | 170 } |
| 171 saved_on_last_retry_ = false; | |
|
fgorski
2017/04/17 17:48:59
Would a single prerendering offliner be used for m
chili
2017/04/17 19:37:52
Good point. Added an additional clearing when we f
| |
| 167 completion_callback_.Run(request, save_status); | 172 completion_callback_.Run(request, save_status); |
| 168 } | 173 } |
| 169 | 174 |
| 170 bool PrerenderingOffliner::LoadAndSave( | 175 bool PrerenderingOffliner::LoadAndSave( |
| 171 const SavePageRequest& request, | 176 const SavePageRequest& request, |
| 172 const CompletionCallback& completion_callback, | 177 const CompletionCallback& completion_callback, |
| 173 const ProgressCallback& progress_callback) { | 178 const ProgressCallback& progress_callback) { |
| 174 DCHECK(!pending_request_.get()); | 179 DCHECK(!pending_request_.get()); |
| 175 | 180 |
| 176 if (pending_request_) { | 181 if (pending_request_) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 callback.Run(request_id); | 266 callback.Run(request_id); |
| 262 } | 267 } |
| 263 | 268 |
| 264 bool PrerenderingOffliner::HandleTimeout(const SavePageRequest& request) { | 269 bool PrerenderingOffliner::HandleTimeout(const SavePageRequest& request) { |
| 265 if (pending_request_) { | 270 if (pending_request_) { |
| 266 DCHECK(request.request_id() == pending_request_->request_id()); | 271 DCHECK(request.request_id() == pending_request_->request_id()); |
| 267 if (GetOrCreateLoader()->IsLowbarMet() && | 272 if (GetOrCreateLoader()->IsLowbarMet() && |
| 268 (request.started_attempt_count() + 1 >= policy_->GetMaxStartedTries() || | 273 (request.started_attempt_count() + 1 >= policy_->GetMaxStartedTries() || |
| 269 request.completed_attempt_count() + 1 >= | 274 request.completed_attempt_count() + 1 >= |
| 270 policy_->GetMaxCompletedTries())) { | 275 policy_->GetMaxCompletedTries())) { |
| 276 saved_on_last_retry_ = true; | |
| 271 GetOrCreateLoader()->StartSnapshot(); | 277 GetOrCreateLoader()->StartSnapshot(); |
| 272 return true; | 278 return true; |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 return false; | 281 return false; |
| 276 } | 282 } |
| 277 | 283 |
| 278 void PrerenderingOffliner::SetLoaderForTesting( | 284 void PrerenderingOffliner::SetLoaderForTesting( |
| 279 std::unique_ptr<PrerenderingLoader> loader) { | 285 std::unique_ptr<PrerenderingLoader> loader) { |
| 280 DCHECK(!loader_); | 286 DCHECK(!loader_); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 void PrerenderingOffliner::HandleApplicationStateChangeCancel( | 329 void PrerenderingOffliner::HandleApplicationStateChangeCancel( |
| 324 const SavePageRequest& request, | 330 const SavePageRequest& request, |
| 325 int64_t offline_id) { | 331 int64_t offline_id) { |
| 326 // This shouldn't be immediate, but account for case where request was reset | 332 // This shouldn't be immediate, but account for case where request was reset |
| 327 // while waiting for callback. | 333 // while waiting for callback. |
| 328 if (pending_request_ && pending_request_->request_id() != offline_id) | 334 if (pending_request_ && pending_request_->request_id() != offline_id) |
| 329 return; | 335 return; |
| 330 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); | 336 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); |
| 331 } | 337 } |
| 332 } // namespace offline_pages | 338 } // namespace offline_pages |
| OLD | NEW |