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

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

Issue 2716013003: Fixes to enable indication of bytes downloaded for Offline Pages in Download Home. (Closed)
Patch Set: more Created 3 years, 9 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"
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/save_page_request.h" 13 #include "components/offline_pages/core/background/save_page_request.h"
14 #include "components/offline_pages/core/client_namespace_constants.h" 14 #include "components/offline_pages/core/client_namespace_constants.h"
15 #include "components/offline_pages/core/downloads/download_ui_adapter.h" 15 #include "components/offline_pages/core/downloads/download_ui_adapter.h"
16 #include "components/offline_pages/core/offline_page_model.h" 16 #include "components/offline_pages/core/offline_page_model.h"
17 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 19
20 namespace offline_pages { 20 namespace offline_pages {
21 namespace {
22 const char kDownloadUIAdapterKey[] = "download-ui-adapter";
23 }
24 21
25 PrerenderingOffliner::PrerenderingOffliner( 22 PrerenderingOffliner::PrerenderingOffliner(
26 content::BrowserContext* browser_context, 23 content::BrowserContext* browser_context,
27 const OfflinerPolicy* policy, 24 const OfflinerPolicy* policy,
28 OfflinePageModel* offline_page_model) 25 OfflinePageModel* offline_page_model)
29 : browser_context_(browser_context), 26 : browser_context_(browser_context),
30 offline_page_model_(offline_page_model), 27 offline_page_model_(offline_page_model),
31 pending_request_(nullptr), 28 pending_request_(nullptr),
32 is_low_end_device_(base::SysInfo::IsLowEndDevice()), 29 is_low_end_device_(base::SysInfo::IsLowEndDevice()),
33 app_listener_(nullptr), 30 app_listener_(nullptr),
34 weak_ptr_factory_(this) {} 31 weak_ptr_factory_(this) {}
35 32
36 PrerenderingOffliner::~PrerenderingOffliner() {} 33 PrerenderingOffliner::~PrerenderingOffliner() {}
37 34
38 void PrerenderingOffliner::OnNetworkProgress(const SavePageRequest& request, 35 void PrerenderingOffliner::OnNetworkProgress(const SavePageRequest& request,
39 int64_t bytes) { 36 int64_t bytes) {
40 if (!pending_request_) 37 if (!pending_request_)
41 return; 38 return;
42 39 DownloadUIAdapter* ui_adapter =
43 DownloadUIAdapter* ui_adapter = static_cast<DownloadUIAdapter*>( 40 DownloadUIAdapter::FromOfflinePageModel(offline_page_model_);
Pete Williamson 2017/02/27 16:13:56 Should we be making a similar change to the backgr
fgorski 2017/02/27 16:22:55 Yes, if similar implementation is in place it caus
Dmitry Titov 2017/02/27 20:02:17 If you mean adding the ability for Background Load
44 offline_page_model_->GetUserData(kDownloadUIAdapterKey));
45
46 if (!ui_adapter) 41 if (!ui_adapter)
47 return; 42 return;
48 43
49 ui_adapter->UpdateProgress(request.request_id(), bytes); 44 ui_adapter->UpdateProgress(request.request_id(), bytes);
50 } 45 }
51 46
52 void PrerenderingOffliner::OnLoadPageDone( 47 void PrerenderingOffliner::OnLoadPageDone(
53 const SavePageRequest& request, 48 const SavePageRequest& request,
54 Offliner::RequestStatus load_status, 49 Offliner::RequestStatus load_status,
55 content::WebContents* web_contents) { 50 content::WebContents* web_contents) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { 253 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
259 DVLOG(1) << "App became active, canceling current offlining request"; 254 DVLOG(1) << "App became active, canceling current offlining request";
260 SavePageRequest* request = pending_request_.get(); 255 SavePageRequest* request = pending_request_.get();
261 Cancel(); 256 Cancel();
262 completion_callback_.Run(*request, 257 completion_callback_.Run(*request,
263 Offliner::RequestStatus::FOREGROUND_CANCELED); 258 Offliner::RequestStatus::FOREGROUND_CANCELED);
264 } 259 }
265 } 260 }
266 261
267 } // namespace offline_pages 262 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698