| 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 { |
| 19 long kOfflinePageDclDelayMs = 25000; |
| 20 long kOfflinePageOnloadDelayMs = 2000; |
| 21 } // namespace |
| 22 |
| 23 |
| 18 namespace offline_pages { | 24 namespace offline_pages { |
| 19 | 25 |
| 20 | 26 |
| 21 // Classifies the appropriate RequestStatus for for the given prerender | 27 // Classifies the appropriate RequestStatus for for the given prerender |
| 22 // FinalStatus. | 28 // FinalStatus. |
| 23 Offliner::RequestStatus ClassifyFinalStatus( | 29 Offliner::RequestStatus ClassifyFinalStatus( |
| 24 prerender::FinalStatus final_status) { | 30 prerender::FinalStatus final_status) { |
| 25 switch (final_status) { | 31 switch (final_status) { |
| 26 | 32 |
| 27 // Identify aborted/canceled operations | 33 // Identify aborted/canceled operations |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 content::SessionStorageNamespace* sessionStorageNamespace = | 81 content::SessionStorageNamespace* sessionStorageNamespace = |
| 76 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); | 82 new_web_contents->GetController().GetDefaultSessionStorageNamespace(); |
| 77 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); | 83 gfx::Size renderWindowSize = new_web_contents->GetContainerBounds().size(); |
| 78 bool accepted = adapter_->StartPrerender( | 84 bool accepted = adapter_->StartPrerender( |
| 79 browser_context_, url, sessionStorageNamespace, renderWindowSize); | 85 browser_context_, url, sessionStorageNamespace, renderWindowSize); |
| 80 if (!accepted) | 86 if (!accepted) |
| 81 return false; | 87 return false; |
| 82 | 88 |
| 83 DCHECK(adapter_->IsActive()); | 89 DCHECK(adapter_->IsActive()); |
| 84 snapshot_controller_.reset( | 90 snapshot_controller_.reset( |
| 85 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this)); | 91 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), this, |
| 92 kOfflinePageDclDelayMs, |
| 93 kOfflinePageOnloadDelayMs)); |
| 86 callback_ = callback; | 94 callback_ = callback; |
| 87 session_contents_.swap(new_web_contents); | 95 session_contents_.swap(new_web_contents); |
| 88 state_ = State::LOADING; | 96 state_ = State::LOADING; |
| 89 return true; | 97 return true; |
| 90 } | 98 } |
| 91 | 99 |
| 92 void PrerenderingLoader::StopLoading() { | 100 void PrerenderingLoader::StopLoading() { |
| 93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 94 CancelPrerender(); | 102 CancelPrerender(); |
| 95 } | 103 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void PrerenderingLoader::CancelPrerender() { | 232 void PrerenderingLoader::CancelPrerender() { |
| 225 if (adapter_->IsActive()) { | 233 if (adapter_->IsActive()) { |
| 226 adapter_->DestroyActive(); | 234 adapter_->DestroyActive(); |
| 227 } | 235 } |
| 228 snapshot_controller_.reset(nullptr); | 236 snapshot_controller_.reset(nullptr); |
| 229 session_contents_.reset(nullptr); | 237 session_contents_.reset(nullptr); |
| 230 state_ = State::IDLE; | 238 state_ = State::IDLE; |
| 231 } | 239 } |
| 232 | 240 |
| 233 } // namespace offline_pages | 241 } // namespace offline_pages |
| OLD | NEW |