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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader.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/prerendering_loader.h" 5 #include "chrome/browser/android/offline_pages/prerendering_loader.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "net/base/network_change_notifier.h" 16 #include "net/base/network_change_notifier.h"
17 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
18 18
19 namespace {
20 // Whether to report DomContentLoaded event to the snapshot controller.
21 bool kConsiderDclForSnapshot = false;
22 // The delay to wait for snapshotting after DomContentLoaded event if
23 // kConsiderDclForSnapshot is true.
24 long kOfflinePageDclDelayMs = 25000;
25 // The delay to wait for snapshotting after OnLoad event.
26 long kOfflinePageOnloadDelayMs = 2000;
27 } // namespace
28
29
30 namespace offline_pages { 19 namespace offline_pages {
31 20
32
33 // Classifies the appropriate RequestStatus for for the given prerender 21 // Classifies the appropriate RequestStatus for for the given prerender
34 // FinalStatus. 22 // FinalStatus.
35 Offliner::RequestStatus ClassifyFinalStatus( 23 Offliner::RequestStatus ClassifyFinalStatus(
36 prerender::FinalStatus final_status) { 24 prerender::FinalStatus final_status) {
37 switch (final_status) { 25 switch (final_status) {
38 // Identify aborted/canceled operations. 26 // Identify aborted/canceled operations.
39 27
40 case prerender::FINAL_STATUS_CANCELLED: 28 case prerender::FINAL_STATUS_CANCELLED:
41 // TODO(dougarnett): Reconsider if/when get better granularity (642768) 29 // TODO(dougarnett): Reconsider if/when get better granularity (642768)
42 case prerender::FINAL_STATUS_UNSUPPORTED_SCHEME: 30 case prerender::FINAL_STATUS_UNSUPPORTED_SCHEME:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 content::WebContents::CreateParams(browser_context_))); 109 content::WebContents::CreateParams(browser_context_)));
122 content::SessionStorageNamespace* sessionStorageNamespace = 110 content::SessionStorageNamespace* sessionStorageNamespace =
123 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); 111 new_web_contents->GetController().GetDefaultSessionStorageNamespace();
124 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); 112 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size();
125 bool accepted = adapter_->StartPrerender( 113 bool accepted = adapter_->StartPrerender(
126 browser_context_, url, sessionStorageNamespace, renderWindowSize); 114 browser_context_, url, sessionStorageNamespace, renderWindowSize);
127 if (!accepted) 115 if (!accepted)
128 return false; 116 return false;
129 117
130 DCHECK(adapter_->IsActive()); 118 DCHECK(adapter_->IsActive());
131 snapshot_controller_.reset( 119 snapshot_controller_ = SnapshotController::CreateForBackgroundOfflining(
132 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this, 120 base::ThreadTaskRunnerHandle::Get(), this);
133 kOfflinePageDclDelayMs,
134 kOfflinePageOnloadDelayMs));
135 load_done_callback_ = load_done_callback; 121 load_done_callback_ = load_done_callback;
136 progress_callback_ = progress_callback; 122 progress_callback_ = progress_callback;
137 session_contents_.swap(new_web_contents); 123 session_contents_.swap(new_web_contents);
138 state_ = State::LOADING; 124 state_ = State::LOADING;
139 return true; 125 return true;
140 } 126 }
141 127
142 void PrerenderingLoader::StopLoading() { 128 void PrerenderingLoader::StopLoading() {
143 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 129 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
144 CancelPrerender(); 130 CancelPrerender();
(...skipping 28 matching lines...) Expand all
173 } 159 }
174 160
175 void PrerenderingLoader::OnPrerenderDomContentLoaded() { 161 void PrerenderingLoader::OnPrerenderDomContentLoaded() {
176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 162 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
177 DCHECK(!IsIdle()); 163 DCHECK(!IsIdle());
178 if (!adapter_->GetWebContents()) { 164 if (!adapter_->GetWebContents()) {
179 // Without a WebContents object at this point, we are done. 165 // Without a WebContents object at this point, we are done.
180 HandleLoadingStopped(); 166 HandleLoadingStopped();
181 } else { 167 } else {
182 is_lowbar_met_ = true; 168 is_lowbar_met_ = true;
183 if (kConsiderDclForSnapshot) { 169 // Inform SnapshotController of DomContentLoaded event so it can
184 // Inform SnapshotController of DomContentLoaded event so it can 170 // determine when to consider it really LOADED (e.g., some multiple
185 // determine when to consider it really LOADED (e.g., some multiple 171 // second delay from this event).
186 // second delay from this event). 172 snapshot_controller_->DocumentAvailableInMainFrame();
187 snapshot_controller_->DocumentAvailableInMainFrame();
188 }
189 173
190 // Add this signal to signal_data_. 174 // Add this signal to signal_data_.
191 AddLoadingSignal("OnDomContentLoaded"); 175 AddLoadingSignal("OnDomContentLoaded");
192 } 176 }
193 } 177 }
194 178
195 void PrerenderingLoader::OnPrerenderStop() { 179 void PrerenderingLoader::OnPrerenderStop() {
196 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 180 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
197 HandleLoadingStopped(); 181 HandleLoadingStopped();
198 } 182 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (adapter_->IsActive()) { 277 if (adapter_->IsActive()) {
294 adapter_->DestroyActive(); 278 adapter_->DestroyActive();
295 } 279 }
296 snapshot_controller_.reset(nullptr); 280 snapshot_controller_.reset(nullptr);
297 session_contents_.reset(nullptr); 281 session_contents_.reset(nullptr);
298 state_ = State::IDLE; 282 state_ = State::IDLE;
299 is_lowbar_met_ = false; 283 is_lowbar_met_ = false;
300 } 284 }
301 285
302 } // namespace offline_pages 286 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698