| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // state, and post callback. | 177 // state, and post callback. |
| 178 // Note: it is possible to receive some asynchronous stopped indication after | 178 // Note: it is possible to receive some asynchronous stopped indication after |
| 179 // the request has completed/stopped via another path so the Loader may be | 179 // the request has completed/stopped via another path so the Loader may be |
| 180 // idle at this point. | 180 // idle at this point. |
| 181 | 181 |
| 182 if (IsIdle()) | 182 if (IsIdle()) |
| 183 return; | 183 return; |
| 184 | 184 |
| 185 Offliner::RequestStatus request_status; | 185 Offliner::RequestStatus request_status; |
| 186 | 186 |
| 187 if (IsLoaded()) { | 187 if (adapter_->IsActive()) { |
| 188 // If page already loaded, then prerender is telling us that it is | 188 if (IsLoaded()) { |
| 189 // canceling (and we should stop using the loaded WebContents). | 189 // If page already loaded, then prerender is telling us that it is |
| 190 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED; | 190 // canceling (and we should stop using the loaded WebContents). |
| 191 } else if (adapter_->IsActive()) { | 191 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED; |
| 192 // Get the available FinalStatus to better identify the outcome. | 192 } else { |
| 193 prerender::FinalStatus final_status = adapter_->GetFinalStatus(); | 193 // Otherwise, get the available FinalStatus to classify the outcome. |
| 194 DVLOG(1) << "Load failed: " << final_status; | 194 prerender::FinalStatus final_status = adapter_->GetFinalStatus(); |
| 195 request_status = ClassifyFinalStatus(final_status); | 195 DVLOG(1) << "Load failed: " << final_status; |
| 196 request_status = ClassifyFinalStatus(final_status); |
| 196 | 197 |
| 197 // Loss of network connection can show up as unsupported scheme per | 198 // Loss of network connection can show up as unsupported scheme per |
| 198 // a redirect to a special data URL is used to navigate to error page. | 199 // a redirect to a special data URL is used to navigate to error page. |
| 199 // Capture the current connectivity here in case we can leverage that | 200 // Capture the current connectivity here in case we can leverage that |
| 200 // to differentiate how to treat it. | 201 // to differentiate how to treat it. |
| 201 if (final_status == prerender::FINAL_STATUS_UNSUPPORTED_SCHEME) { | 202 if (final_status == prerender::FINAL_STATUS_UNSUPPORTED_SCHEME) { |
| 202 UMA_HISTOGRAM_ENUMERATION( | 203 UMA_HISTOGRAM_ENUMERATION( |
| 203 "OfflinePages.Background.UnsupportedScheme.ConnectionType", | 204 "OfflinePages.Background.UnsupportedScheme.ConnectionType", |
| 204 net::NetworkChangeNotifier::GetConnectionType(), | 205 net::NetworkChangeNotifier::GetConnectionType(), |
| 205 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1); | 206 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1); |
| 207 } |
| 206 } | 208 } |
| 209 |
| 210 // Now clean up the active prerendering operation detail. |
| 207 adapter_->DestroyActive(); | 211 adapter_->DestroyActive(); |
| 208 } else { | 212 } else { |
| 209 // No access to FinalStatus so classify as retryable failure. | 213 // No access to FinalStatus so classify as retryable failure. |
| 210 request_status = Offliner::RequestStatus::PRERENDERING_FAILED; | 214 request_status = Offliner::RequestStatus::PRERENDERING_FAILED; |
| 211 } | 215 } |
| 212 | 216 |
| 213 snapshot_controller_.reset(nullptr); | 217 snapshot_controller_.reset(nullptr); |
| 214 session_contents_.reset(nullptr); | 218 session_contents_.reset(nullptr); |
| 215 state_ = State::IDLE; | 219 state_ = State::IDLE; |
| 216 base::ThreadTaskRunnerHandle::Get()->PostTask( | 220 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 217 FROM_HERE, base::Bind(callback_, request_status, nullptr)); | 221 FROM_HERE, base::Bind(callback_, request_status, nullptr)); |
| 218 } | 222 } |
| 219 | 223 |
| 220 void PrerenderingLoader::CancelPrerender() { | 224 void PrerenderingLoader::CancelPrerender() { |
| 221 if (adapter_->IsActive()) { | 225 if (adapter_->IsActive()) { |
| 222 adapter_->DestroyActive(); | 226 adapter_->DestroyActive(); |
| 223 } | 227 } |
| 224 snapshot_controller_.reset(nullptr); | 228 snapshot_controller_.reset(nullptr); |
| 225 session_contents_.reset(nullptr); | 229 session_contents_.reset(nullptr); |
| 226 state_ = State::IDLE; | 230 state_ = State::IDLE; |
| 227 } | 231 } |
| 228 | 232 |
| 229 } // namespace offline_pages | 233 } // namespace offline_pages |
| OLD | NEW |