| 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 21 matching lines...) Expand all Loading... |
| 32 // Classifies the appropriate RequestStatus for for the given prerender | 32 // Classifies the appropriate RequestStatus for for the given prerender |
| 33 // FinalStatus. | 33 // FinalStatus. |
| 34 Offliner::RequestStatus ClassifyFinalStatus( | 34 Offliner::RequestStatus ClassifyFinalStatus( |
| 35 prerender::FinalStatus final_status) { | 35 prerender::FinalStatus final_status) { |
| 36 switch (final_status) { | 36 switch (final_status) { |
| 37 // Identify aborted/canceled operations. | 37 // Identify aborted/canceled operations. |
| 38 | 38 |
| 39 case prerender::FINAL_STATUS_CANCELLED: | 39 case prerender::FINAL_STATUS_CANCELLED: |
| 40 // TODO(dougarnett): Reconsider if/when get better granularity (642768) | 40 // TODO(dougarnett): Reconsider if/when get better granularity (642768) |
| 41 case prerender::FINAL_STATUS_UNSUPPORTED_SCHEME: | 41 case prerender::FINAL_STATUS_UNSUPPORTED_SCHEME: |
| 42 return Offliner::PRERENDERING_CANCELED; | 42 return Offliner::LOADING_CANCELED; |
| 43 | 43 |
| 44 // Identify non-retryable failures. These are a hard type failures | 44 // Identify non-retryable failures. These are a hard type failures |
| 45 // associated with the page and so are expected to occur again if retried. | 45 // associated with the page and so are expected to occur again if retried. |
| 46 | 46 |
| 47 case prerender::FINAL_STATUS_SAFE_BROWSING: | 47 case prerender::FINAL_STATUS_SAFE_BROWSING: |
| 48 case prerender::FINAL_STATUS_CREATING_AUDIO_STREAM: | 48 case prerender::FINAL_STATUS_CREATING_AUDIO_STREAM: |
| 49 case prerender::FINAL_STATUS_JAVASCRIPT_ALERT: | 49 case prerender::FINAL_STATUS_JAVASCRIPT_ALERT: |
| 50 case prerender::FINAL_STATUS_CREATE_NEW_WINDOW: | 50 case prerender::FINAL_STATUS_CREATE_NEW_WINDOW: |
| 51 case prerender::FINAL_STATUS_INVALID_HTTP_METHOD: | 51 case prerender::FINAL_STATUS_INVALID_HTTP_METHOD: |
| 52 case prerender::FINAL_STATUS_OPEN_URL: | 52 case prerender::FINAL_STATUS_OPEN_URL: |
| 53 return Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY; | 53 return Offliner::RequestStatus::LOADING_FAILED_NO_RETRY; |
| 54 | 54 |
| 55 // Identify failures that indicate we should stop further processing | 55 // Identify failures that indicate we should stop further processing |
| 56 // for now. These may be current resource issues or app closing. | 56 // for now. These may be current resource issues or app closing. |
| 57 | 57 |
| 58 case prerender::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED: | 58 case prerender::FINAL_STATUS_MEMORY_LIMIT_EXCEEDED: |
| 59 case prerender::FINAL_STATUS_RATE_LIMIT_EXCEEDED: | 59 case prerender::FINAL_STATUS_RATE_LIMIT_EXCEEDED: |
| 60 case prerender::FINAL_STATUS_RENDERER_CRASHED: | 60 case prerender::FINAL_STATUS_RENDERER_CRASHED: |
| 61 case prerender::FINAL_STATUS_TOO_MANY_PROCESSES: | 61 case prerender::FINAL_STATUS_TOO_MANY_PROCESSES: |
| 62 case prerender::FINAL_STATUS_TIMED_OUT: | 62 case prerender::FINAL_STATUS_TIMED_OUT: |
| 63 case prerender::FINAL_STATUS_APP_TERMINATING: | 63 case prerender::FINAL_STATUS_APP_TERMINATING: |
| 64 case prerender::FINAL_STATUS_PROFILE_DESTROYED: | 64 case prerender::FINAL_STATUS_PROFILE_DESTROYED: |
| 65 return Offliner::RequestStatus::PRERENDERING_FAILED_NO_NEXT; | 65 return Offliner::RequestStatus::LOADING_FAILED_NO_NEXT; |
| 66 | 66 |
| 67 // Otherwise, assume retryable failure. | 67 // Otherwise, assume retryable failure. |
| 68 | 68 |
| 69 case prerender::FINAL_STATUS_NEW_NAVIGATION_ENTRY: | 69 case prerender::FINAL_STATUS_NEW_NAVIGATION_ENTRY: |
| 70 case prerender::FINAL_STATUS_CACHE_OR_HISTORY_CLEARED: | 70 case prerender::FINAL_STATUS_CACHE_OR_HISTORY_CLEARED: |
| 71 case prerender::FINAL_STATUS_SSL_ERROR: | 71 case prerender::FINAL_STATUS_SSL_ERROR: |
| 72 case prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED: | 72 case prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED: |
| 73 case prerender::FINAL_STATUS_WINDOW_PRINT: | 73 case prerender::FINAL_STATUS_WINDOW_PRINT: |
| 74 default: | 74 default: |
| 75 return Offliner::RequestStatus::PRERENDERING_FAILED; | 75 return Offliner::RequestStatus::LOADING_FAILED; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context) | 79 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context) |
| 80 : state_(State::IDLE), | 80 : state_(State::IDLE), |
| 81 snapshot_controller_(nullptr), | 81 snapshot_controller_(nullptr), |
| 82 browser_context_(browser_context) { | 82 browser_context_(browser_context) { |
| 83 adapter_.reset(new PrerenderAdapter(this)); | 83 adapter_.reset(new PrerenderAdapter(this)); |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 if (IsIdle()) | 216 if (IsIdle()) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 Offliner::RequestStatus request_status; | 219 Offliner::RequestStatus request_status; |
| 220 | 220 |
| 221 if (adapter_->IsActive()) { | 221 if (adapter_->IsActive()) { |
| 222 if (IsLoaded()) { | 222 if (IsLoaded()) { |
| 223 // If page already loaded, then prerender is telling us that it is | 223 // If page already loaded, then prerender is telling us that it is |
| 224 // canceling (and we should stop using the loaded WebContents). | 224 // canceling (and we should stop using the loaded WebContents). |
| 225 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED; | 225 request_status = Offliner::RequestStatus::LOADING_CANCELED; |
| 226 } else { | 226 } else { |
| 227 // Otherwise, get the available FinalStatus to classify the outcome. | 227 // Otherwise, get the available FinalStatus to classify the outcome. |
| 228 prerender::FinalStatus final_status = adapter_->GetFinalStatus(); | 228 prerender::FinalStatus final_status = adapter_->GetFinalStatus(); |
| 229 DVLOG(1) << "Load failed: " << final_status; | 229 DVLOG(1) << "Load failed: " << final_status; |
| 230 request_status = ClassifyFinalStatus(final_status); | 230 request_status = ClassifyFinalStatus(final_status); |
| 231 | 231 |
| 232 // Loss of network connection can show up as unsupported scheme per | 232 // Loss of network connection can show up as unsupported scheme per |
| 233 // a redirect to a special data URL is used to navigate to error page. | 233 // a redirect to a special data URL is used to navigate to error page. |
| 234 // Capture the current connectivity here in case we can leverage that | 234 // Capture the current connectivity here in case we can leverage that |
| 235 // to differentiate how to treat it. | 235 // to differentiate how to treat it. |
| 236 if (final_status == prerender::FINAL_STATUS_UNSUPPORTED_SCHEME) { | 236 if (final_status == prerender::FINAL_STATUS_UNSUPPORTED_SCHEME) { |
| 237 UMA_HISTOGRAM_ENUMERATION( | 237 UMA_HISTOGRAM_ENUMERATION( |
| 238 "OfflinePages.Background.UnsupportedScheme.ConnectionType", | 238 "OfflinePages.Background.UnsupportedScheme.ConnectionType", |
| 239 net::NetworkChangeNotifier::GetConnectionType(), | 239 net::NetworkChangeNotifier::GetConnectionType(), |
| 240 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1); | 240 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 // Now clean up the active prerendering operation detail. | 244 // Now clean up the active prerendering operation detail. |
| 245 adapter_->DestroyActive(); | 245 adapter_->DestroyActive(); |
| 246 } else { | 246 } else { |
| 247 // No access to FinalStatus so classify as retryable failure. | 247 // No access to FinalStatus so classify as retryable failure. |
| 248 request_status = Offliner::RequestStatus::PRERENDERING_FAILED; | 248 request_status = Offliner::RequestStatus::LOADING_FAILED; |
| 249 } | 249 } |
| 250 | 250 |
| 251 snapshot_controller_.reset(nullptr); | 251 snapshot_controller_.reset(nullptr); |
| 252 session_contents_.reset(nullptr); | 252 session_contents_.reset(nullptr); |
| 253 state_ = State::IDLE; | 253 state_ = State::IDLE; |
| 254 base::ThreadTaskRunnerHandle::Get()->PostTask( | 254 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 255 FROM_HERE, base::Bind(callback_, request_status, nullptr)); | 255 FROM_HERE, base::Bind(callback_, request_status, nullptr)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void PrerenderingLoader::CancelPrerender() { | 258 void PrerenderingLoader::CancelPrerender() { |
| 259 if (adapter_->IsActive()) { | 259 if (adapter_->IsActive()) { |
| 260 adapter_->DestroyActive(); | 260 adapter_->DestroyActive(); |
| 261 } | 261 } |
| 262 snapshot_controller_.reset(nullptr); | 262 snapshot_controller_.reset(nullptr); |
| 263 session_contents_.reset(nullptr); | 263 session_contents_.reset(nullptr); |
| 264 state_ = State::IDLE; | 264 state_ = State::IDLE; |
| 265 } | 265 } |
| 266 | 266 |
| 267 } // namespace offline_pages | 267 } // namespace offline_pages |
| OLD | NEW |