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

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

Issue 2742833004: Fix the Download Notifications for Offline Pages to indicate bytes loaded. (Closed)
Patch Set: 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/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
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
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 application_state == 326 application_state ==
323 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { 327 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
324 DVLOG(1) << "App became active, canceling current offlining request"; 328 DVLOG(1) << "App became active, canceling current offlining request";
325 SavePageRequest* request = pending_request_.get(); 329 SavePageRequest* request = pending_request_.get();
326 Cancel(); 330 Cancel();
327 completion_callback_.Run(*request, RequestStatus::FOREGROUND_CANCELED); 331 completion_callback_.Run(*request, RequestStatus::FOREGROUND_CANCELED);
328 } 332 }
329 } 333 }
330 334
331 } // namespace offline_pages 335 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698