| 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" |
| 11 #include "chrome/browser/android/offline_pages/offliner_helper.h" | 11 #include "chrome/browser/android/offline_pages/offliner_helper.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "components/offline_pages/core/background/offliner_policy.h" | 13 #include "components/offline_pages/core/background/offliner_policy.h" |
| 14 #include "components/offline_pages/core/background/save_page_request.h" | 14 #include "components/offline_pages/core/background/save_page_request.h" |
| 15 #include "components/offline_pages/core/client_namespace_constants.h" | 15 #include "components/offline_pages/core/client_namespace_constants.h" |
| 16 #include "components/offline_pages/core/downloads/download_ui_adapter.h" | 16 #include "components/offline_pages/core/downloads/download_ui_adapter.h" |
| 17 #include "components/offline_pages/core/offline_page_model.h" | 17 #include "components/offline_pages/core/offline_page_model.h" |
| 18 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 | 20 |
| 21 namespace offline_pages { | 21 namespace offline_pages { |
| 22 namespace { | |
| 23 const char kDownloadUIAdapterKey[] = "download-ui-adapter"; | |
| 24 } | |
| 25 | 22 |
| 26 PrerenderingOffliner::PrerenderingOffliner( | 23 PrerenderingOffliner::PrerenderingOffliner( |
| 27 content::BrowserContext* browser_context, | 24 content::BrowserContext* browser_context, |
| 28 const OfflinerPolicy* policy, | 25 const OfflinerPolicy* policy, |
| 29 OfflinePageModel* offline_page_model) | 26 OfflinePageModel* offline_page_model) |
| 30 : browser_context_(browser_context), | 27 : browser_context_(browser_context), |
| 31 policy_(policy), | 28 policy_(policy), |
| 32 offline_page_model_(offline_page_model), | 29 offline_page_model_(offline_page_model), |
| 33 pending_request_(nullptr), | 30 pending_request_(nullptr), |
| 34 is_low_end_device_(base::SysInfo::IsLowEndDevice()), | 31 is_low_end_device_(base::SysInfo::IsLowEndDevice()), |
| 35 app_listener_(nullptr), | 32 app_listener_(nullptr), |
| 36 weak_ptr_factory_(this) {} | 33 weak_ptr_factory_(this) {} |
| 37 | 34 |
| 38 PrerenderingOffliner::~PrerenderingOffliner() {} | 35 PrerenderingOffliner::~PrerenderingOffliner() {} |
| 39 | 36 |
| 40 void PrerenderingOffliner::OnNetworkProgress(const SavePageRequest& request, | 37 void PrerenderingOffliner::OnNetworkProgress(const SavePageRequest& request, |
| 41 int64_t bytes) { | 38 int64_t bytes) { |
| 42 if (!pending_request_) | 39 if (!pending_request_) |
| 43 return; | 40 return; |
| 44 | 41 DownloadUIAdapter* ui_adapter = |
| 45 DownloadUIAdapter* ui_adapter = static_cast<DownloadUIAdapter*>( | 42 DownloadUIAdapter::FromOfflinePageModel(offline_page_model_); |
| 46 offline_page_model_->GetUserData(kDownloadUIAdapterKey)); | |
| 47 | |
| 48 if (!ui_adapter) | 43 if (!ui_adapter) |
| 49 return; | 44 return; |
| 50 | 45 |
| 51 ui_adapter->UpdateProgress(request.request_id(), bytes); | 46 ui_adapter->UpdateProgress(request.request_id(), bytes); |
| 52 } | 47 } |
| 53 | 48 |
| 54 void PrerenderingOffliner::OnLoadPageDone( | 49 void PrerenderingOffliner::OnLoadPageDone( |
| 55 const SavePageRequest& request, | 50 const SavePageRequest& request, |
| 56 Offliner::RequestStatus load_status, | 51 Offliner::RequestStatus load_status, |
| 57 content::WebContents* web_contents) { | 52 content::WebContents* web_contents) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { | 269 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { |
| 275 DVLOG(1) << "App became active, canceling current offlining request"; | 270 DVLOG(1) << "App became active, canceling current offlining request"; |
| 276 SavePageRequest* request = pending_request_.get(); | 271 SavePageRequest* request = pending_request_.get(); |
| 277 Cancel(); | 272 Cancel(); |
| 278 completion_callback_.Run(*request, | 273 completion_callback_.Run(*request, |
| 279 Offliner::RequestStatus::FOREGROUND_CANCELED); | 274 Offliner::RequestStatus::FOREGROUND_CANCELED); |
| 280 } | 275 } |
| 281 } | 276 } |
| 282 | 277 |
| 283 } // namespace offline_pages | 278 } // namespace offline_pages |
| OLD | NEW |