| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 bool accepted = adapter_->StartPrerender( | 51 bool accepted = adapter_->StartPrerender( |
| 52 browser_context_, url, sessionStorageNamespace, renderWindowSize); | 52 browser_context_, url, sessionStorageNamespace, renderWindowSize); |
| 53 if (!accepted) | 53 if (!accepted) |
| 54 return false; | 54 return false; |
| 55 | 55 |
| 56 DCHECK(adapter_->IsActive()); | 56 DCHECK(adapter_->IsActive()); |
| 57 snapshot_controller_.reset( | 57 snapshot_controller_.reset( |
| 58 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this)); | 58 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this)); |
| 59 callback_ = callback; | 59 callback_ = callback; |
| 60 session_contents_.swap(new_web_contents); | 60 session_contents_.swap(new_web_contents); |
| 61 state_ = State::PENDING; | 61 state_ = State::LOADING; |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void PrerenderingLoader::StopLoading() { | 65 void PrerenderingLoader::StopLoading() { |
| 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 67 CancelPrerender(); | 67 CancelPrerender(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool PrerenderingLoader::CanPrerender() { | 70 bool PrerenderingLoader::CanPrerender() { |
| 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 72 return adapter_->CanPrerender(); | 72 return adapter_->CanPrerender(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool PrerenderingLoader::IsIdle() { | 75 bool PrerenderingLoader::IsIdle() { |
| 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 77 return state_ == State::IDLE; | 77 return state_ == State::IDLE; |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool PrerenderingLoader::IsLoaded() { | 80 bool PrerenderingLoader::IsLoaded() { |
| 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 82 return state_ == State::LOADED; | 82 return state_ == State::LOADED; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void PrerenderingLoader::SetAdapterForTesting( | 85 void PrerenderingLoader::SetAdapterForTesting( |
| 86 std::unique_ptr<PrerenderAdapter> prerender_adapter) { | 86 std::unique_ptr<PrerenderAdapter> prerender_adapter) { |
| 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 88 adapter_ = std::move(prerender_adapter); | 88 adapter_ = std::move(prerender_adapter); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void PrerenderingLoader::OnPrerenderStart() { | |
| 92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 93 DCHECK(state_ == State::PENDING); | |
| 94 state_ = State::LOADING; | |
| 95 } | |
| 96 | |
| 97 void PrerenderingLoader::OnPrerenderStopLoading() { | 91 void PrerenderingLoader::OnPrerenderStopLoading() { |
| 98 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 99 DCHECK(!IsIdle()); | 93 DCHECK(!IsIdle()); |
| 100 DCHECK(adapter_->GetWebContents()); | 94 DCHECK(adapter_->GetWebContents()); |
| 101 // Inform SnapshotController of OnLoad event so it can determine | 95 // Inform SnapshotController of OnLoad event so it can determine |
| 102 // when to consider it really LOADED. | 96 // when to consider it really LOADED. |
| 103 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); | 97 snapshot_controller_->DocumentOnLoadCompletedInMainFrame(); |
| 104 } | 98 } |
| 105 | 99 |
| 106 void PrerenderingLoader::OnPrerenderDomContentLoaded() { | 100 void PrerenderingLoader::OnPrerenderDomContentLoaded() { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void PrerenderingLoader::CancelPrerender() { | 193 void PrerenderingLoader::CancelPrerender() { |
| 200 if (adapter_->IsActive()) { | 194 if (adapter_->IsActive()) { |
| 201 adapter_->DestroyActive(); | 195 adapter_->DestroyActive(); |
| 202 } | 196 } |
| 203 snapshot_controller_.reset(nullptr); | 197 snapshot_controller_.reset(nullptr); |
| 204 session_contents_.reset(nullptr); | 198 session_contents_.reset(nullptr); |
| 205 state_ = State::IDLE; | 199 state_ = State::IDLE; |
| 206 } | 200 } |
| 207 | 201 |
| 208 } // namespace offline_pages | 202 } // namespace offline_pages |
| OLD | NEW |