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

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

Issue 2637563002: [Offline Pages] Snapshotting on timeout of last retry. (Closed)
Patch Set: Created 3 years, 11 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"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 case prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED: 72 case prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED:
73 case prerender::FINAL_STATUS_WINDOW_PRINT: 73 case prerender::FINAL_STATUS_WINDOW_PRINT:
74 default: 74 default:
75 return Offliner::RequestStatus::LOADING_FAILED; 75 return Offliner::RequestStatus::LOADING_FAILED;
76 } 76 }
77 } 77 }
78 78
79 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context) 79 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context)
80 : state_(State::IDLE), 80 : state_(State::IDLE),
81 snapshot_controller_(nullptr), 81 snapshot_controller_(nullptr),
82 browser_context_(browser_context) { 82 browser_context_(browser_context),
83 is_lowbar_met_(false) {
83 adapter_.reset(new PrerenderAdapter(this)); 84 adapter_.reset(new PrerenderAdapter(this));
84 } 85 }
85 86
86 PrerenderingLoader::~PrerenderingLoader() { 87 PrerenderingLoader::~PrerenderingLoader() {
87 CancelPrerender(); 88 CancelPrerender();
88 } 89 }
89 90
90 bool PrerenderingLoader::LoadPage(const GURL& url, 91 bool PrerenderingLoader::LoadPage(const GURL& url,
91 const LoadPageCallback& callback) { 92 const LoadPageCallback& callback) {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // when to consider it really LOADED. 151 // when to consider it really LOADED.
151 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); 152 snapshot_controller_->DocumentOnLoadCompletedInMainFrame();
152 } 153 }
153 154
154 void PrerenderingLoader::OnPrerenderDomContentLoaded() { 155 void PrerenderingLoader::OnPrerenderDomContentLoaded() {
155 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
156 DCHECK(!IsIdle()); 157 DCHECK(!IsIdle());
157 if (!adapter_->GetWebContents()) { 158 if (!adapter_->GetWebContents()) {
158 // Without a WebContents object at this point, we are done. 159 // Without a WebContents object at this point, we are done.
159 HandleLoadingStopped(); 160 HandleLoadingStopped();
160 } else if (kConsiderDclForSnapshot) { 161 } else {
161 // Inform SnapshotController of DomContentLoaded event so it can 162 is_lowbar_met_ = true;
162 // determine when to consider it really LOADED (e.g., some multiple 163 if (kConsiderDclForSnapshot) {
163 // second delay from this event). 164 // Inform SnapshotController of DomContentLoaded event so it can
164 snapshot_controller_->DocumentAvailableInMainFrame(); 165 // determine when to consider it really LOADED (e.g., some multiple
166 // second delay from this event).
167 snapshot_controller_->DocumentAvailableInMainFrame();
168 }
165 } 169 }
166 } 170 }
167 171
168 void PrerenderingLoader::OnPrerenderStop() { 172 void PrerenderingLoader::OnPrerenderStop() {
169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 173 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
170 HandleLoadingStopped(); 174 HandleLoadingStopped();
171 } 175 }
172 176
173 void PrerenderingLoader::StartSnapshot() { 177 void PrerenderingLoader::StartSnapshot() {
174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
175 HandleLoadEvent(); 179 HandleLoadEvent();
176 } 180 }
177 181
182 bool PrerenderingLoader::IsLowbarMet() {
183 return is_lowbar_met_;
184 }
185
178 void PrerenderingLoader::HandleLoadEvent() { 186 void PrerenderingLoader::HandleLoadEvent() {
179 // If still loading, check if the load succeeded or not, then update 187 // If still loading, check if the load succeeded or not, then update
180 // the internal state (LOADED for success or IDLE for failure) and post 188 // the internal state (LOADED for success or IDLE for failure) and post
181 // callback. 189 // callback.
182 // Note: it is possible to receive a load event (e.g., if timeout-based) 190 // Note: it is possible to receive a load event (e.g., if timeout-based)
183 // after the request has completed via another path (e.g., canceled) so 191 // after the request has completed via another path (e.g., canceled) so
184 // the Loader may be idle at this point. 192 // the Loader may be idle at this point.
185 193
186 if (IsIdle() || IsLoaded()) 194 if (IsIdle() || IsLoaded())
187 return; 195 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Now clean up the active prerendering operation detail. 245 // Now clean up the active prerendering operation detail.
238 adapter_->DestroyActive(); 246 adapter_->DestroyActive();
239 } else { 247 } else {
240 // No access to FinalStatus so classify as retryable failure. 248 // No access to FinalStatus so classify as retryable failure.
241 request_status = Offliner::RequestStatus::LOADING_FAILED; 249 request_status = Offliner::RequestStatus::LOADING_FAILED;
242 } 250 }
243 251
244 snapshot_controller_.reset(nullptr); 252 snapshot_controller_.reset(nullptr);
245 session_contents_.reset(nullptr); 253 session_contents_.reset(nullptr);
246 state_ = State::IDLE; 254 state_ = State::IDLE;
255 is_lowbar_met_ = false;
247 base::ThreadTaskRunnerHandle::Get()->PostTask( 256 base::ThreadTaskRunnerHandle::Get()->PostTask(
248 FROM_HERE, base::Bind(callback_, request_status, nullptr)); 257 FROM_HERE, base::Bind(callback_, request_status, nullptr));
249 } 258 }
250 259
251 void PrerenderingLoader::CancelPrerender() { 260 void PrerenderingLoader::CancelPrerender() {
252 if (adapter_->IsActive()) { 261 if (adapter_->IsActive()) {
253 adapter_->DestroyActive(); 262 adapter_->DestroyActive();
254 } 263 }
255 snapshot_controller_.reset(nullptr); 264 snapshot_controller_.reset(nullptr);
256 session_contents_.reset(nullptr); 265 session_contents_.reset(nullptr);
257 state_ = State::IDLE; 266 state_ = State::IDLE;
267 is_lowbar_met_ = false;
258 } 268 }
259 269
260 } // namespace offline_pages 270 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698