Chromium Code Reviews| 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/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // Loading has stopped so unless the Loader has already transistioned to the | 150 // Loading has stopped so unless the Loader has already transistioned to the |
| 151 // idle state, clean up the previous request state, transition to the idle | 151 // idle state, clean up the previous request state, transition to the idle |
| 152 // state, and post callback. | 152 // state, and post callback. |
| 153 // Note: it is possible to receive some asynchronous stopped indication after | 153 // Note: it is possible to receive some asynchronous stopped indication after |
| 154 // the request has completed/stopped via another path so the Loader may be | 154 // the request has completed/stopped via another path so the Loader may be |
| 155 // idle at this point. | 155 // idle at this point. |
| 156 | 156 |
| 157 if (IsIdle()) | 157 if (IsIdle()) |
| 158 return; | 158 return; |
| 159 | 159 |
| 160 if (adapter_->IsActive()) { | |
| 161 DVLOG(1) << "Load failed: " << adapter_->GetFinalStatus(); | |
| 162 adapter_->DestroyActive(); | |
| 163 } | |
| 164 // Request status depends on whether we are still loading (failed) or | 160 // Request status depends on whether we are still loading (failed) or |
| 165 // did load and then loading was stopped (cancel - from prerender stack). | 161 // did load and then loading was stopped (cancel - from prerender stack). |
| 166 Offliner::RequestStatus request_status = | 162 Offliner::RequestStatus request_status = |
| 167 IsLoaded() ? Offliner::RequestStatus::PRERENDERING_CANCELED | 163 IsLoaded() ? Offliner::RequestStatus::PRERENDERING_CANCELED |
| 168 : Offliner::RequestStatus::PRERENDERING_FAILED; | 164 : Offliner::RequestStatus::PRERENDERING_FAILED; |
| 169 // TODO(dougarnett): For failure, determine from final status if retry-able | 165 |
| 170 // and report different failure statuses if retry-able or not. | 166 if (adapter_->IsActive()) { |
| 167 prerender::FinalStatus final_status = adapter_->GetFinalStatus(); | |
| 168 DVLOG(1) << "Load failed: " << final_status; | |
| 169 | |
| 170 // 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. | |
| 172 // We want to be able to retry these request so for now treat any | |
| 173 // unsupported scheme error as a cancel. See issue 642025. | |
|
Pete Williamson
2016/08/30 20:42:47
If we are closing bug 642025 after this change, we
dougarnett
2016/08/31 16:10:52
Acknowledged.
| |
| 174 // TODO(dougarnett): Create whitelist of final status codes that should | |
| 175 // not be considered failures (and define new RequestStatus code for them). | |
| 176 if (adapter_->GetFinalStatus() == | |
| 177 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME) { | |
| 178 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED; | |
| 179 } | |
| 180 adapter_->DestroyActive(); | |
| 181 } | |
| 182 | |
| 171 snapshot_controller_.reset(nullptr); | 183 snapshot_controller_.reset(nullptr); |
| 172 session_contents_.reset(nullptr); | 184 session_contents_.reset(nullptr); |
| 173 state_ = State::IDLE; | 185 state_ = State::IDLE; |
| 174 base::ThreadTaskRunnerHandle::Get()->PostTask( | 186 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 175 FROM_HERE, base::Bind(callback_, request_status, nullptr)); | 187 FROM_HERE, base::Bind(callback_, request_status, nullptr)); |
| 176 } | 188 } |
| 177 | 189 |
| 178 void PrerenderingLoader::CancelPrerender() { | 190 void PrerenderingLoader::CancelPrerender() { |
| 179 if (adapter_->IsActive()) { | 191 if (adapter_->IsActive()) { |
| 180 adapter_->DestroyActive(); | 192 adapter_->DestroyActive(); |
| 181 } | 193 } |
| 182 snapshot_controller_.reset(nullptr); | 194 snapshot_controller_.reset(nullptr); |
| 183 session_contents_.reset(nullptr); | 195 session_contents_.reset(nullptr); |
| 184 state_ = State::IDLE; | 196 state_ = State::IDLE; |
| 185 } | 197 } |
| 186 | 198 |
| 187 } // namespace offline_pages | 199 } // namespace offline_pages |
| OLD | NEW |