| OLD | NEW |
| 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 "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 // Whether to report DomContentLoaded event to the snapshot controller. |
| 20 bool kConsiderDclForSnapshot = false; |
| 21 // The delay to wait for snapshotting after DomContentLoaded event if |
| 22 // kConsiderDclForSnapshot is true. |
| 19 long kOfflinePageDclDelayMs = 25000; | 23 long kOfflinePageDclDelayMs = 25000; |
| 24 // The delay to wait for snapshotting after OnLoad event. |
| 20 long kOfflinePageOnloadDelayMs = 2000; | 25 long kOfflinePageOnloadDelayMs = 2000; |
| 21 } // namespace | 26 } // namespace |
| 22 | 27 |
| 23 | 28 |
| 24 namespace offline_pages { | 29 namespace offline_pages { |
| 25 | 30 |
| 26 | 31 |
| 27 // Classifies the appropriate RequestStatus for for the given prerender | 32 // Classifies the appropriate RequestStatus for for the given prerender |
| 28 // FinalStatus. | 33 // FinalStatus. |
| 29 Offliner::RequestStatus ClassifyFinalStatus( | 34 Offliner::RequestStatus ClassifyFinalStatus( |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // when to consider it really LOADED. | 136 // when to consider it really LOADED. |
| 132 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); | 137 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); |
| 133 } | 138 } |
| 134 | 139 |
| 135 void PrerenderingLoader::OnPrerenderDomContentLoaded() { | 140 void PrerenderingLoader::OnPrerenderDomContentLoaded() { |
| 136 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 137 DCHECK(!IsIdle()); | 142 DCHECK(!IsIdle()); |
| 138 if (!adapter_->GetWebContents()) { | 143 if (!adapter_->GetWebContents()) { |
| 139 // Without a WebContents object at this point, we are done. | 144 // Without a WebContents object at this point, we are done. |
| 140 HandleLoadingStopped(); | 145 HandleLoadingStopped(); |
| 146 } else if (kConsiderDclForSnapshot) { |
| 147 // Inform SnapshotController of DomContentLoaded event so it can |
| 148 // determine when to consider it really LOADED (e.g., some multiple |
| 149 // second delay from this event). |
| 150 snapshot_controller_->DocumentAvailableInMainFrame(); |
| 141 } | 151 } |
| 142 } | 152 } |
| 143 | 153 |
| 144 void PrerenderingLoader::OnPrerenderStop() { | 154 void PrerenderingLoader::OnPrerenderStop() { |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 155 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 146 HandleLoadingStopped(); | 156 HandleLoadingStopped(); |
| 147 } | 157 } |
| 148 | 158 |
| 149 void PrerenderingLoader::StartSnapshot() { | 159 void PrerenderingLoader::StartSnapshot() { |
| 150 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void PrerenderingLoader::CancelPrerender() { | 237 void PrerenderingLoader::CancelPrerender() { |
| 228 if (adapter_->IsActive()) { | 238 if (adapter_->IsActive()) { |
| 229 adapter_->DestroyActive(); | 239 adapter_->DestroyActive(); |
| 230 } | 240 } |
| 231 snapshot_controller_.reset(nullptr); | 241 snapshot_controller_.reset(nullptr); |
| 232 session_contents_.reset(nullptr); | 242 session_contents_.reset(nullptr); |
| 233 state_ = State::IDLE; | 243 state_ = State::IDLE; |
| 234 } | 244 } |
| 235 | 245 |
| 236 } // namespace offline_pages | 246 } // namespace offline_pages |
| OLD | NEW |