| 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/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 21 matching lines...) Expand all Loading... |
| 32 save_state_(NONE), | 32 save_state_(NONE), |
| 33 page_load_state_(SUCCESS), | 33 page_load_state_(SUCCESS), |
| 34 page_delay_ms_(kOfflinePageDelayMs), | 34 page_delay_ms_(kOfflinePageDelayMs), |
| 35 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
| 36 DCHECK(offline_page_model_); | 36 DCHECK(offline_page_model_); |
| 37 DCHECK(browser_context_); | 37 DCHECK(browser_context_); |
| 38 } | 38 } |
| 39 | 39 |
| 40 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {} | 40 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {} |
| 41 | 41 |
| 42 bool BackgroundLoaderOffliner::LoadAndSave(const SavePageRequest& request, | 42 // TODO(dimich): Invoke progress_callback as appropriate. |
| 43 const CompletionCallback& callback) { | 43 bool BackgroundLoaderOffliner::LoadAndSave( |
| 44 DCHECK(callback); | 44 const SavePageRequest& request, |
| 45 const CompletionCallback& completion_callback, |
| 46 const ProgressCallback& progress_callback) { |
| 47 DCHECK(completion_callback); |
| 48 DCHECK(progress_callback); |
| 45 | 49 |
| 46 if (pending_request_) { | 50 if (pending_request_) { |
| 47 DVLOG(1) << "Already have pending request"; | 51 DVLOG(1) << "Already have pending request"; |
| 48 return false; | 52 return false; |
| 49 } | 53 } |
| 50 | 54 |
| 51 // Do not allow loading for custom tabs clients if 3rd party cookies blocked. | 55 // Do not allow loading for custom tabs clients if 3rd party cookies blocked. |
| 52 // TODO(dewittj): Revise api to specify policy rather than hard code to | 56 // TODO(dewittj): Revise api to specify policy rather than hard code to |
| 53 // name_space. | 57 // name_space. |
| 54 if (request.client_id().name_space == kCCTNamespace && | 58 if (request.client_id().name_space == kCCTNamespace && |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 101 } |
| 98 | 102 |
| 99 if (!loader_) | 103 if (!loader_) |
| 100 ResetState(); | 104 ResetState(); |
| 101 | 105 |
| 102 // Invalidate ptrs for all delayed/saving tasks. | 106 // Invalidate ptrs for all delayed/saving tasks. |
| 103 weak_ptr_factory_.InvalidateWeakPtrs(); | 107 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 104 | 108 |
| 105 // Track copy of pending request. | 109 // Track copy of pending request. |
| 106 pending_request_.reset(new SavePageRequest(request)); | 110 pending_request_.reset(new SavePageRequest(request)); |
| 107 completion_callback_ = callback; | 111 completion_callback_ = completion_callback; |
| 108 | 112 |
| 109 // Listen for app foreground/background change. | 113 // Listen for app foreground/background change. |
| 110 app_listener_.reset(new base::android::ApplicationStatusListener( | 114 app_listener_.reset(new base::android::ApplicationStatusListener( |
| 111 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange, | 115 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange, |
| 112 weak_ptr_factory_.GetWeakPtr()))); | 116 weak_ptr_factory_.GetWeakPtr()))); |
| 113 | 117 |
| 114 // Load page attempt. | 118 // Load page attempt. |
| 115 loader_.get()->LoadPage(request.url()); | 119 loader_.get()->LoadPage(request.url()); |
| 116 | 120 |
| 117 return true; | 121 return true; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 void BackgroundLoaderOffliner::HandleApplicationStateChangeCancel( | 360 void BackgroundLoaderOffliner::HandleApplicationStateChangeCancel( |
| 357 const SavePageRequest& request, | 361 const SavePageRequest& request, |
| 358 int64_t offline_id) { | 362 int64_t offline_id) { |
| 359 // If for some reason the request was reset during while waiting for callback | 363 // If for some reason the request was reset during while waiting for callback |
| 360 // ignore the completion callback. | 364 // ignore the completion callback. |
| 361 if (pending_request_ && pending_request_->request_id() != offline_id) | 365 if (pending_request_ && pending_request_->request_id() != offline_id) |
| 362 return; | 366 return; |
| 363 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); | 367 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); |
| 364 } | 368 } |
| 365 } // namespace offline_pages | 369 } // namespace offline_pages |
| OLD | NEW |