Chromium Code Reviews| 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 "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 { | 19 namespace { |
| 20 // Whether to report DomContentLoaded event to the snapshot controller. | 20 // The delay to wait for snapshotting after DomContentLoaded event. |
|
romax
2017/04/19 17:40:29
seems like the delay can also be used as the boole
chili
2017/04/19 21:10:14
I would rather not use delay as a boolean. Delay i
| |
| 21 bool kConsiderDclForSnapshot = false; | |
| 22 // The delay to wait for snapshotting after DomContentLoaded event if | |
| 23 // kConsiderDclForSnapshot is true. | |
| 24 long kOfflinePageDclDelayMs = 25000; | 21 long kOfflinePageDclDelayMs = 25000; |
|
fgorski
2017/04/20 16:39:05
Since you are already changing this file, I recomm
chili
2017/04/21 00:12:54
Done.
| |
| 25 // The delay to wait for snapshotting after OnLoad event. | 22 // The delay to wait for snapshotting after OnLoad event. |
| 26 long kOfflinePageOnloadDelayMs = 2000; | 23 long kOfflinePageOnloadDelayMs = 2000; |
| 27 } // namespace | 24 } // namespace |
| 28 | 25 |
| 29 | 26 |
| 30 namespace offline_pages { | 27 namespace offline_pages { |
| 31 | 28 |
| 32 | 29 |
| 33 // Classifies the appropriate RequestStatus for for the given prerender | 30 // Classifies the appropriate RequestStatus for for the given prerender |
| 34 // FinalStatus. | 31 // FinalStatus. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 content::WebContents::CreateParams(browser_context_))); | 120 content::WebContents::CreateParams(browser_context_))); |
| 124 content::SessionStorageNamespace* sessionStorageNamespace = | 121 content::SessionStorageNamespace* sessionStorageNamespace = |
| 125 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); | 122 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); |
| 126 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); | 123 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); |
| 127 bool accepted = adapter_->StartPrerender( | 124 bool accepted = adapter_->StartPrerender( |
| 128 browser_context_, url, sessionStorageNamespace, renderWindowSize); | 125 browser_context_, url, sessionStorageNamespace, renderWindowSize); |
| 129 if (!accepted) | 126 if (!accepted) |
| 130 return false; | 127 return false; |
| 131 | 128 |
| 132 DCHECK(adapter_->IsActive()); | 129 DCHECK(adapter_->IsActive()); |
| 133 snapshot_controller_.reset( | 130 snapshot_controller_.reset(new SnapshotController( |
| 134 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this, | 131 base::ThreadTaskRunnerHandle::Get(), this, kOfflinePageDclDelayMs, |
| 135 kOfflinePageDclDelayMs, | 132 kOfflinePageOnloadDelayMs, |
| 136 kOfflinePageOnloadDelayMs)); | 133 false /* consider_document_available_for_snapshot */)); |
|
fgorski
2017/04/20 16:39:05
The fact that for both background cases we are pas
chili
2017/04/21 00:12:54
Done.
| |
| 137 load_done_callback_ = load_done_callback; | 134 load_done_callback_ = load_done_callback; |
| 138 progress_callback_ = progress_callback; | 135 progress_callback_ = progress_callback; |
| 139 session_contents_.swap(new_web_contents); | 136 session_contents_.swap(new_web_contents); |
| 140 state_ = State::LOADING; | 137 state_ = State::LOADING; |
| 141 return true; | 138 return true; |
| 142 } | 139 } |
| 143 | 140 |
| 144 void PrerenderingLoader::StopLoading() { | 141 void PrerenderingLoader::StopLoading() { |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 142 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 146 CancelPrerender(); | 143 CancelPrerender(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 175 } | 172 } |
| 176 | 173 |
| 177 void PrerenderingLoader::OnPrerenderDomContentLoaded() { | 174 void PrerenderingLoader::OnPrerenderDomContentLoaded() { |
| 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 175 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 179 DCHECK(!IsIdle()); | 176 DCHECK(!IsIdle()); |
| 180 if (!adapter_->GetWebContents()) { | 177 if (!adapter_->GetWebContents()) { |
| 181 // Without a WebContents object at this point, we are done. | 178 // Without a WebContents object at this point, we are done. |
| 182 HandleLoadingStopped(); | 179 HandleLoadingStopped(); |
| 183 } else { | 180 } else { |
| 184 is_lowbar_met_ = true; | 181 is_lowbar_met_ = true; |
| 185 if (kConsiderDclForSnapshot) { | 182 // Inform SnapshotController of DomContentLoaded event so it can |
| 186 // Inform SnapshotController of DomContentLoaded event so it can | 183 // determine when to consider it really LOADED (e.g., some multiple |
| 187 // determine when to consider it really LOADED (e.g., some multiple | 184 // second delay from this event). |
| 188 // second delay from this event). | 185 snapshot_controller_->DocumentAvailableInMainFrame(); |
| 189 snapshot_controller_->DocumentAvailableInMainFrame(); | |
| 190 } | |
| 191 | 186 |
| 192 // Add this signal to signal_data_. | 187 // Add this signal to signal_data_. |
| 193 AddLoadingSignal("OnDomContentLoaded"); | 188 AddLoadingSignal("OnDomContentLoaded"); |
| 194 } | 189 } |
| 195 } | 190 } |
| 196 | 191 |
| 197 void PrerenderingLoader::OnPrerenderStop() { | 192 void PrerenderingLoader::OnPrerenderStop() { |
| 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 199 HandleLoadingStopped(); | 194 HandleLoadingStopped(); |
| 200 } | 195 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 if (adapter_->IsActive()) { | 290 if (adapter_->IsActive()) { |
| 296 adapter_->DestroyActive(); | 291 adapter_->DestroyActive(); |
| 297 } | 292 } |
| 298 snapshot_controller_.reset(nullptr); | 293 snapshot_controller_.reset(nullptr); |
| 299 session_contents_.reset(nullptr); | 294 session_contents_.reset(nullptr); |
| 300 state_ = State::IDLE; | 295 state_ = State::IDLE; |
| 301 is_lowbar_met_ = false; | 296 is_lowbar_met_ = false; |
| 302 } | 297 } |
| 303 | 298 |
| 304 } // namespace offline_pages | 299 } // namespace offline_pages |
| OLD | NEW |