Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_loader.cc

Issue 2294933003: [Offline Pages] Handle prerender FinalStatus UnsupportedScheme as a cancel rather than failure. (Closed)
Patch Set: Revert started try count change from this cl and added TODO with followup bug id. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerendering_loader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
174 // TODO(dougarnett): Use new FinalStatus code if/when supported (642768).
175 // TODO(dougarnett): Create whitelist of final status codes that should
176 // not be considered failures (and define new RequestStatus code for them).
177 if (adapter_->GetFinalStatus() ==
178 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME) {
179 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED;
180 }
181 adapter_->DestroyActive();
182 }
183
171 snapshot_controller_.reset(nullptr); 184 snapshot_controller_.reset(nullptr);
172 session_contents_.reset(nullptr); 185 session_contents_.reset(nullptr);
173 state_ = State::IDLE; 186 state_ = State::IDLE;
174 base::ThreadTaskRunnerHandle::Get()->PostTask( 187 base::ThreadTaskRunnerHandle::Get()->PostTask(
175 FROM_HERE, base::Bind(callback_, request_status, nullptr)); 188 FROM_HERE, base::Bind(callback_, request_status, nullptr));
176 } 189 }
177 190
178 void PrerenderingLoader::CancelPrerender() { 191 void PrerenderingLoader::CancelPrerender() {
179 if (adapter_->IsActive()) { 192 if (adapter_->IsActive()) {
180 adapter_->DestroyActive(); 193 adapter_->DestroyActive();
181 } 194 }
182 snapshot_controller_.reset(nullptr); 195 snapshot_controller_.reset(nullptr);
183 session_contents_.reset(nullptr); 196 session_contents_.reset(nullptr);
184 state_ = State::IDLE; 197 state_ = State::IDLE;
185 } 198 }
186 199
187 } // namespace offline_pages 200 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/prerendering_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698