| 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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "net/base/network_change_notifier.h" |
| 14 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 15 | 17 |
| 16 namespace offline_pages { | 18 namespace offline_pages { |
| 17 | 19 |
| 18 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context) | 20 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context) |
| 19 : state_(State::IDLE), | 21 : state_(State::IDLE), |
| 20 snapshot_controller_(nullptr), | 22 snapshot_controller_(nullptr), |
| 21 browser_context_(browser_context) { | 23 browser_context_(browser_context) { |
| 22 adapter_.reset(new PrerenderAdapter(this)); | 24 adapter_.reset(new PrerenderAdapter(this)); |
| 23 } | 25 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // Loss of network connection can show up as unsupported scheme per | 172 // Loss of network connection can show up as unsupported scheme per |
| 171 // a redirect to a special data URL is used to navigate to error page. | 173 // a redirect to a special data URL is used to navigate to error page. |
| 172 // We want to be able to retry these request so for now treat any | 174 // We want to be able to retry these request so for now treat any |
| 173 // unsupported scheme error as a cancel. | 175 // unsupported scheme error as a cancel. |
| 174 // TODO(dougarnett): Use new FinalStatus code if/when supported (642768). | 176 // TODO(dougarnett): Use new FinalStatus code if/when supported (642768). |
| 175 // TODO(dougarnett): Create whitelist of final status codes that should | 177 // TODO(dougarnett): Create whitelist of final status codes that should |
| 176 // not be considered failures (and define new RequestStatus code for them). | 178 // not be considered failures (and define new RequestStatus code for them). |
| 177 if (adapter_->GetFinalStatus() == | 179 if (adapter_->GetFinalStatus() == |
| 178 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME) { | 180 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME) { |
| 179 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED; | 181 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED; |
| 182 UMA_HISTOGRAM_ENUMERATION( |
| 183 "OfflinePages.Background.UnsupportedScheme.ConnectionType", |
| 184 net::NetworkChangeNotifier::GetConnectionType(), |
| 185 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1); |
| 180 } | 186 } |
| 181 adapter_->DestroyActive(); | 187 adapter_->DestroyActive(); |
| 182 } | 188 } |
| 183 | 189 |
| 184 snapshot_controller_.reset(nullptr); | 190 snapshot_controller_.reset(nullptr); |
| 185 session_contents_.reset(nullptr); | 191 session_contents_.reset(nullptr); |
| 186 state_ = State::IDLE; | 192 state_ = State::IDLE; |
| 187 base::ThreadTaskRunnerHandle::Get()->PostTask( | 193 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 188 FROM_HERE, base::Bind(callback_, request_status, nullptr)); | 194 FROM_HERE, base::Bind(callback_, request_status, nullptr)); |
| 189 } | 195 } |
| 190 | 196 |
| 191 void PrerenderingLoader::CancelPrerender() { | 197 void PrerenderingLoader::CancelPrerender() { |
| 192 if (adapter_->IsActive()) { | 198 if (adapter_->IsActive()) { |
| 193 adapter_->DestroyActive(); | 199 adapter_->DestroyActive(); |
| 194 } | 200 } |
| 195 snapshot_controller_.reset(nullptr); | 201 snapshot_controller_.reset(nullptr); |
| 196 session_contents_.reset(nullptr); | 202 session_contents_.reset(nullptr); |
| 197 state_ = State::IDLE; | 203 state_ = State::IDLE; |
| 198 } | 204 } |
| 199 | 205 |
| 200 } // namespace offline_pages | 206 } // namespace offline_pages |
| OLD | NEW |