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

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

Issue 2822023002: [Offline pages]: Move logic for whether to consider the DocumentAvailableInMainFrame signal to the … (Closed)
Patch Set: code review changes Created 3 years, 8 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"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "components/offline_pages/core/background/offliner_policy.h" 12 #include "components/offline_pages/core/background/offliner_policy.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/offline_page_model.h" 15 #include "components/offline_pages/core/offline_page_model.h"
16 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/navigation_handle.h" 17 #include "content/public/browser/navigation_handle.h"
18 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_user_data.h" 20 #include "content/public/browser/web_contents_user_data.h"
21 21
22 namespace offline_pages { 22 namespace offline_pages {
23 23
24 namespace { 24 namespace {
25 const long kOfflinePageDelayMs = 2000;
26 const long kOfflineDomContentLoadedMs = 25000;
27 25
28 class OfflinerData : public content::WebContentsUserData<OfflinerData> { 26 class OfflinerData : public content::WebContentsUserData<OfflinerData> {
29 public: 27 public:
30 static void AddToWebContents(content::WebContents* webcontents, 28 static void AddToWebContents(content::WebContents* webcontents,
31 BackgroundLoaderOffliner* offliner) { 29 BackgroundLoaderOffliner* offliner) {
32 DCHECK(offliner); 30 DCHECK(offliner);
33 webcontents->SetUserData(UserDataKey(), std::unique_ptr<OfflinerData>( 31 webcontents->SetUserData(UserDataKey(), std::unique_ptr<OfflinerData>(
34 new OfflinerData(offliner))); 32 new OfflinerData(offliner)));
35 } 33 }
36 34
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 BackgroundLoaderOffliner::BackgroundLoaderOffliner( 67 BackgroundLoaderOffliner::BackgroundLoaderOffliner(
70 content::BrowserContext* browser_context, 68 content::BrowserContext* browser_context,
71 const OfflinerPolicy* policy, 69 const OfflinerPolicy* policy,
72 OfflinePageModel* offline_page_model) 70 OfflinePageModel* offline_page_model)
73 : browser_context_(browser_context), 71 : browser_context_(browser_context),
74 offline_page_model_(offline_page_model), 72 offline_page_model_(offline_page_model),
75 policy_(policy), 73 policy_(policy),
76 is_low_end_device_(base::SysInfo::IsLowEndDevice()), 74 is_low_end_device_(base::SysInfo::IsLowEndDevice()),
77 save_state_(NONE), 75 save_state_(NONE),
78 page_load_state_(SUCCESS), 76 page_load_state_(SUCCESS),
79 page_delay_ms_(kOfflinePageDelayMs),
80 network_bytes_(0LL), 77 network_bytes_(0LL),
81 weak_ptr_factory_(this) { 78 weak_ptr_factory_(this) {
82 DCHECK(offline_page_model_); 79 DCHECK(offline_page_model_);
83 DCHECK(browser_context_); 80 DCHECK(browser_context_);
84 } 81 }
85 82
86 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {} 83 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {}
87 84
88 // static 85 // static
89 BackgroundLoaderOffliner* BackgroundLoaderOffliner::FromWebContents( 86 BackgroundLoaderOffliner* BackgroundLoaderOffliner::FromWebContents(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 progress_callback_ = progress_callback; 160 progress_callback_ = progress_callback;
164 161
165 // Listen for app foreground/background change. 162 // Listen for app foreground/background change.
166 app_listener_.reset(new base::android::ApplicationStatusListener( 163 app_listener_.reset(new base::android::ApplicationStatusListener(
167 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange, 164 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange,
168 weak_ptr_factory_.GetWeakPtr()))); 165 weak_ptr_factory_.GetWeakPtr())));
169 166
170 // Load page attempt. 167 // Load page attempt.
171 loader_.get()->LoadPage(request.url()); 168 loader_.get()->LoadPage(request.url());
172 169
173 snapshot_controller_.reset( 170 snapshot_controller_.reset(SnapshotController::CreateForBackgroundOfflining(
174 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this, 171 base::ThreadTaskRunnerHandle::Get(), this));
175 kOfflineDomContentLoadedMs, page_delay_ms_));
176 172
177 return true; 173 return true;
178 } 174 }
179 175
180 void BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) { 176 void BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
181 // TODO(chili): We are not able to cancel a pending 177 // TODO(chili): We are not able to cancel a pending
182 // OfflinePageModel::SaveSnapshot() operation. We will notify caller that 178 // OfflinePageModel::SaveSnapshot() operation. We will notify caller that
183 // cancel completed once the SavePage operation returns. 179 // cancel completed once the SavePage operation returns.
184 if (!pending_request_) { 180 if (!pending_request_) {
185 callback.Run(0LL); 181 callback.Run(0LL);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 switch (navigation_handle->GetNetErrorCode()) { 266 switch (navigation_handle->GetNetErrorCode()) {
271 case net::ERR_INTERNET_DISCONNECTED: 267 case net::ERR_INTERNET_DISCONNECTED:
272 page_load_state_ = DELAY_RETRY; 268 page_load_state_ = DELAY_RETRY;
273 break; 269 break;
274 default: 270 default:
275 page_load_state_ = RETRIABLE; 271 page_load_state_ = RETRIABLE;
276 } 272 }
277 } 273 }
278 } 274 }
279 275
280 void BackgroundLoaderOffliner::SetPageDelayForTest(long delay_ms) { 276 void BackgroundLoaderOffliner::SetSnapshotControllerForTest(
fgorski 2017/04/21 16:05:10 +1 one to the use of injection that way! I think t
chili 2017/04/24 20:34:14 Done.
281 page_delay_ms_ = delay_ms; 277 SnapshotController* controller) {
278 snapshot_controller_.reset(controller);
282 } 279 }
283 280
284 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { 281 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) {
285 if (pending_request_ && save_state_ != SAVING) { 282 if (pending_request_ && save_state_ != SAVING) {
286 network_bytes_ += bytes; 283 network_bytes_ += bytes;
287 progress_callback_.Run(*pending_request_, network_bytes_); 284 progress_callback_.Run(*pending_request_, network_bytes_);
288 } 285 }
289 } 286 }
290 287
291 void BackgroundLoaderOffliner::StartSnapshot() { 288 void BackgroundLoaderOffliner::StartSnapshot() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 int64_t offline_id) { 410 int64_t offline_id) {
414 // If for some reason the request was reset during while waiting for callback 411 // If for some reason the request was reset during while waiting for callback
415 // ignore the completion callback. 412 // ignore the completion callback.
416 if (pending_request_ && pending_request_->request_id() != offline_id) 413 if (pending_request_ && pending_request_->request_id() != offline_id)
417 return; 414 return;
418 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED); 415 completion_callback_.Run(request, RequestStatus::FOREGROUND_CANCELED);
419 } 416 }
420 } // namespace offline_pages 417 } // namespace offline_pages
421 418
422 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 419 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698