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

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: test fix: replace snapshot controller at the right place Created 3 years, 7 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/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 10 matching lines...) Expand all
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/mhtml_extra_parts.h" 22 #include "content/public/browser/mhtml_extra_parts.h"
23 #include "content/public/browser/navigation_handle.h" 23 #include "content/public/browser/navigation_handle.h"
24 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_user_data.h" 26 #include "content/public/browser/web_contents_user_data.h"
27 27
28 namespace offline_pages { 28 namespace offline_pages {
29 29
30 namespace { 30 namespace {
31 const long kOfflinePageDelayMs = 2000;
32 const long kOfflineDomContentLoadedMs = 25000;
33 const char kContentType[] = "text/plain"; 31 const char kContentType[] = "text/plain";
34 const char kContentTransferEncodingBinary[] = 32 const char kContentTransferEncodingBinary[] =
35 "Content-Transfer-Encoding: binary"; 33 "Content-Transfer-Encoding: binary";
36 const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1"; 34 const char kXHeaderForSignals[] = "X-Chrome-Loading-Metrics-Data: 1";
37 35
38 class OfflinerData : public content::WebContentsUserData<OfflinerData> { 36 class OfflinerData : public content::WebContentsUserData<OfflinerData> {
39 public: 37 public:
40 static void AddToWebContents(content::WebContents* webcontents, 38 static void AddToWebContents(content::WebContents* webcontents,
41 BackgroundLoaderOffliner* offliner) { 39 BackgroundLoaderOffliner* offliner) {
42 DCHECK(offliner); 40 DCHECK(offliner);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 BackgroundLoaderOffliner::BackgroundLoaderOffliner( 85 BackgroundLoaderOffliner::BackgroundLoaderOffliner(
88 content::BrowserContext* browser_context, 86 content::BrowserContext* browser_context,
89 const OfflinerPolicy* policy, 87 const OfflinerPolicy* policy,
90 OfflinePageModel* offline_page_model) 88 OfflinePageModel* offline_page_model)
91 : browser_context_(browser_context), 89 : browser_context_(browser_context),
92 offline_page_model_(offline_page_model), 90 offline_page_model_(offline_page_model),
93 policy_(policy), 91 policy_(policy),
94 is_low_end_device_(base::SysInfo::IsLowEndDevice()), 92 is_low_end_device_(base::SysInfo::IsLowEndDevice()),
95 save_state_(NONE), 93 save_state_(NONE),
96 page_load_state_(SUCCESS), 94 page_load_state_(SUCCESS),
97 page_delay_ms_(kOfflinePageDelayMs),
98 network_bytes_(0LL), 95 network_bytes_(0LL),
99 is_low_bar_met_(false), 96 is_low_bar_met_(false),
100 did_snapshot_on_last_retry_(false), 97 did_snapshot_on_last_retry_(false),
101 weak_ptr_factory_(this) { 98 weak_ptr_factory_(this) {
102 DCHECK(offline_page_model_); 99 DCHECK(offline_page_model_);
103 DCHECK(browser_context_); 100 DCHECK(browser_context_);
104 } 101 }
105 102
106 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {} 103 BackgroundLoaderOffliner::~BackgroundLoaderOffliner() {}
107 104
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 progress_callback_ = progress_callback; 183 progress_callback_ = progress_callback;
187 184
188 // Listen for app foreground/background change. 185 // Listen for app foreground/background change.
189 app_listener_.reset(new base::android::ApplicationStatusListener( 186 app_listener_.reset(new base::android::ApplicationStatusListener(
190 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange, 187 base::Bind(&BackgroundLoaderOffliner::OnApplicationStateChange,
191 weak_ptr_factory_.GetWeakPtr()))); 188 weak_ptr_factory_.GetWeakPtr())));
192 189
193 // Load page attempt. 190 // Load page attempt.
194 loader_.get()->LoadPage(request.url()); 191 loader_.get()->LoadPage(request.url());
195 192
196 snapshot_controller_.reset( 193 snapshot_controller_ = SnapshotController::CreateForBackgroundOfflining(
197 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this, 194 base::ThreadTaskRunnerHandle::Get(), this);
198 kOfflineDomContentLoadedMs, page_delay_ms_));
199 195
200 return true; 196 return true;
201 } 197 }
202 198
203 bool BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) { 199 bool BackgroundLoaderOffliner::Cancel(const CancelCallback& callback) {
204 DCHECK(pending_request_); 200 DCHECK(pending_request_);
205 // We ignore the case where pending_request_ is not set, but given the checks 201 // We ignore the case where pending_request_ is not set, but given the checks
206 // in RequestCoordinator this should not happen. 202 // in RequestCoordinator this should not happen.
207 if (!pending_request_) 203 if (!pending_request_)
208 return false; 204 return false;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 switch (navigation_handle->GetNetErrorCode()) { 302 switch (navigation_handle->GetNetErrorCode()) {
307 case net::ERR_INTERNET_DISCONNECTED: 303 case net::ERR_INTERNET_DISCONNECTED:
308 page_load_state_ = DELAY_RETRY; 304 page_load_state_ = DELAY_RETRY;
309 break; 305 break;
310 default: 306 default:
311 page_load_state_ = RETRIABLE; 307 page_load_state_ = RETRIABLE;
312 } 308 }
313 } 309 }
314 } 310 }
315 311
316 void BackgroundLoaderOffliner::SetPageDelayForTest(long delay_ms) { 312 void BackgroundLoaderOffliner::SetSnapshotControllerForTest(
317 page_delay_ms_ = delay_ms; 313 std::unique_ptr<SnapshotController> controller) {
314 snapshot_controller_ = std::move(controller);
318 } 315 }
319 316
320 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) { 317 void BackgroundLoaderOffliner::OnNetworkBytesChanged(int64_t bytes) {
321 if (pending_request_ && save_state_ != SAVING) { 318 if (pending_request_ && save_state_ != SAVING) {
322 network_bytes_ += bytes; 319 network_bytes_ += bytes;
323 progress_callback_.Run(*pending_request_, network_bytes_); 320 progress_callback_.Run(*pending_request_, network_bytes_);
324 } 321 }
325 } 322 }
326 323
327 void BackgroundLoaderOffliner::StartSnapshot() { 324 void BackgroundLoaderOffliner::StartSnapshot() {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // Given the choice between int and double, we choose to implicitly convert to 486 // Given the choice between int and double, we choose to implicitly convert to
490 // a double since it maintains more precision (we can get a longer time in 487 // a double since it maintains more precision (we can get a longer time in
491 // milliseconds than we can with a 2 bit int, 53 bits vs 32). 488 // milliseconds than we can with a 2 bit int, 53 bits vs 32).
492 double delay = delay_so_far.InMilliseconds(); 489 double delay = delay_so_far.InMilliseconds();
493 signal_data_.SetDouble(signal_name, delay); 490 signal_data_.SetDouble(signal_name, delay);
494 } 491 }
495 492
496 } // namespace offline_pages 493 } // namespace offline_pages
497 494
498 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData); 495 DEFINE_WEB_CONTENTS_USER_DATA_KEY(offline_pages::OfflinerData);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698