| 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 { | |
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 content::WebContents::CreateParams(browser_context_))); | 111 content::WebContents::CreateParams(browser_context_))); |
| 124 content::SessionStorageNamespace* sessionStorageNamespace = | 112 content::SessionStorageNamespace* sessionStorageNamespace = |
| 125 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); | 113 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); |
| 126 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); | 114 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); |
| 127 bool accepted = adapter_->StartPrerender( | 115 bool accepted = adapter_->StartPrerender( |
| 128 browser_context_, url, sessionStorageNamespace, renderWindowSize); | 116 browser_context_, url, sessionStorageNamespace, renderWindowSize); |
| 129 if (!accepted) | 117 if (!accepted) |
| 130 return false; | 118 return false; |
| 131 | 119 |
| 132 DCHECK(adapter_->IsActive()); | 120 DCHECK(adapter_->IsActive()); |
| 133 snapshot_controller_.reset( | 121 snapshot_controller_ = SnapshotController::CreateForBackgroundOfflining( |
| 134 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this, | 122 base::ThreadTaskRunnerHandle::Get(), this); |
| 135 kOfflinePageDclDelayMs, | |
| 136 kOfflinePageOnloadDelayMs)); | |
| 137 load_done_callback_ = load_done_callback; | 123 load_done_callback_ = load_done_callback; |
| 138 progress_callback_ = progress_callback; | 124 progress_callback_ = progress_callback; |
| 139 session_contents_.swap(new_web_contents); | 125 session_contents_.swap(new_web_contents); |
| 140 state_ = State::LOADING; | 126 state_ = State::LOADING; |
| 141 return true; | 127 return true; |
| 142 } | 128 } |
| 143 | 129 |
| 144 void PrerenderingLoader::StopLoading() { | 130 void PrerenderingLoader::StopLoading() { |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 131 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 146 CancelPrerender(); | 132 CancelPrerender(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 175 } | 161 } |
| 176 | 162 |
| 177 void PrerenderingLoader::OnPrerenderDomContentLoaded() { | 163 void PrerenderingLoader::OnPrerenderDomContentLoaded() { |
| 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 179 DCHECK(!IsIdle()); | 165 DCHECK(!IsIdle()); |
| 180 if (!adapter_->GetWebContents()) { | 166 if (!adapter_->GetWebContents()) { |
| 181 // Without a WebContents object at this point, we are done. | 167 // Without a WebContents object at this point, we are done. |
| 182 HandleLoadingStopped(); | 168 HandleLoadingStopped(); |
| 183 } else { | 169 } else { |
| 184 is_lowbar_met_ = true; | 170 is_lowbar_met_ = true; |
| 185 if (kConsiderDclForSnapshot) { | 171 // Inform SnapshotController of DomContentLoaded event so it can |
| 186 // Inform SnapshotController of DomContentLoaded event so it can | 172 // determine when to consider it really LOADED (e.g., some multiple |
| 187 // determine when to consider it really LOADED (e.g., some multiple | 173 // second delay from this event). |
| 188 // second delay from this event). | 174 snapshot_controller_->DocumentAvailableInMainFrame(); |
| 189 snapshot_controller_->DocumentAvailableInMainFrame(); | |
| 190 } | |
| 191 | 175 |
| 192 // Add this signal to signal_data_. | 176 // Add this signal to signal_data_. |
| 193 AddLoadingSignal("OnDomContentLoaded"); | 177 AddLoadingSignal("OnDomContentLoaded"); |
| 194 } | 178 } |
| 195 } | 179 } |
| 196 | 180 |
| 197 void PrerenderingLoader::OnPrerenderStop() { | 181 void PrerenderingLoader::OnPrerenderStop() { |
| 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 199 HandleLoadingStopped(); | 183 HandleLoadingStopped(); |
| 200 } | 184 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (adapter_->IsActive()) { | 279 if (adapter_->IsActive()) { |
| 296 adapter_->DestroyActive(); | 280 adapter_->DestroyActive(); |
| 297 } | 281 } |
| 298 snapshot_controller_.reset(nullptr); | 282 snapshot_controller_.reset(nullptr); |
| 299 session_contents_.reset(nullptr); | 283 session_contents_.reset(nullptr); |
| 300 state_ = State::IDLE; | 284 state_ = State::IDLE; |
| 301 is_lowbar_met_ = false; | 285 is_lowbar_met_ = false; |
| 302 } | 286 } |
| 303 | 287 |
| 304 } // namespace offline_pages | 288 } // namespace offline_pages |
| OLD | NEW |