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

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

Issue 2361883002: [Offline Pages] Adds classification of some prerender FinalStatus codes as canceled operations or a… (Closed)
Patch Set: Merge Created 4 years, 2 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/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"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "net/base/network_change_notifier.h" 15 #include "net/base/network_change_notifier.h"
16 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
17 17
18 namespace offline_pages { 18 namespace offline_pages {
19 19
20
21 // Classifies the appropriate RequestStatus for for the given prerender
22 // FinalStatus.
23 Offliner::RequestStatus ClassifyFinalStatus(
24 prerender::FinalStatus final_status) {
25 switch (final_status) {
26
27 // Identify aborted/canceled operations
28
29 case prerender::FINAL_STATUS_CANCELLED:
30 // TODO(dougarnett): Reconsider if/when get better granularity (642768)
31 case prerender::FINAL_STATUS_UNSUPPORTED_SCHEME:
32 return Offliner::PRERENDERING_CANCELED;
33
34 // Identify non-retryable failues.
35
36 case prerender::FINAL_STATUS_SAFE_BROWSING:
37 case prerender::FINAL_STATUS_CREATING_AUDIO_STREAM:
38 case prerender::FINAL_STATUS_JAVASCRIPT_ALERT:
39 return Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY;
40
41 // Otherwise, assume retryable failure.
42 default:
43 return Offliner::RequestStatus::PRERENDERING_FAILED;
44 }
45 }
46
20 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context) 47 PrerenderingLoader::PrerenderingLoader(content::BrowserContext* browser_context)
21 : state_(State::IDLE), 48 : state_(State::IDLE),
22 snapshot_controller_(nullptr), 49 snapshot_controller_(nullptr),
23 browser_context_(browser_context) { 50 browser_context_(browser_context) {
24 adapter_.reset(new PrerenderAdapter(this)); 51 adapter_.reset(new PrerenderAdapter(this));
25 } 52 }
26 53
27 PrerenderingLoader::~PrerenderingLoader() { 54 PrerenderingLoader::~PrerenderingLoader() {
28 CancelPrerender(); 55 CancelPrerender();
29 } 56 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 base::ThreadTaskRunnerHandle::Get()->PostTask( 165 base::ThreadTaskRunnerHandle::Get()->PostTask(
139 FROM_HERE, 166 FROM_HERE,
140 base::Bind(callback_, Offliner::RequestStatus::LOADED, web_contents)); 167 base::Bind(callback_, Offliner::RequestStatus::LOADED, web_contents));
141 } else { 168 } else {
142 // No WebContents means that the load failed (and it stopped). 169 // No WebContents means that the load failed (and it stopped).
143 HandleLoadingStopped(); 170 HandleLoadingStopped();
144 } 171 }
145 } 172 }
146 173
147 void PrerenderingLoader::HandleLoadingStopped() { 174 void PrerenderingLoader::HandleLoadingStopped() {
148 // Loading has stopped so unless the Loader has already transistioned to the 175 // Loading has stopped so unless the Loader has already transitioned to the
149 // idle state, clean up the previous request state, transition to the idle 176 // idle state, clean up the previous request state, transition to the idle
150 // state, and post callback. 177 // state, and post callback.
151 // Note: it is possible to receive some asynchronous stopped indication after 178 // Note: it is possible to receive some asynchronous stopped indication after
152 // 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
153 // idle at this point. 180 // idle at this point.
154 181
155 if (IsIdle()) 182 if (IsIdle())
156 return; 183 return;
157 184
158 // Request status depends on whether we are still loading (failed) or 185 Offliner::RequestStatus request_status;
159 // did load and then loading was stopped (cancel - from prerender stack).
160 Offliner::RequestStatus request_status =
161 IsLoaded() ? Offliner::RequestStatus::PRERENDERING_CANCELED
162 : Offliner::RequestStatus::PRERENDERING_FAILED;
163 186
164 if (adapter_->IsActive()) { 187 if (IsLoaded()) {
188 // If page already loaded, then prerender is telling us that it is
189 // canceling (and we should stop using the loaded WebContents).
190 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED;
191 } else if (adapter_->IsActive()) {
192 // Get the available FinalStatus to better identify the outcome.
165 prerender::FinalStatus final_status = adapter_->GetFinalStatus(); 193 prerender::FinalStatus final_status = adapter_->GetFinalStatus();
166 DVLOG(1) << "Load failed: " << final_status; 194 DVLOG(1) << "Load failed: " << final_status;
195 request_status = ClassifyFinalStatus(final_status);
167 196
168 // Loss of network connection can show up as unsupported scheme per 197 // Loss of network connection can show up as unsupported scheme per
169 // a redirect to a special data URL is used to navigate to error page. 198 // a redirect to a special data URL is used to navigate to error page.
170 // We want to be able to retry these request so for now treat any 199 // Capture the current connectivity here in case we can leverage that
171 // unsupported scheme error as a cancel. 200 // to differentiate how to treat it.
172 // TODO(dougarnett): Use new FinalStatus code if/when supported (642768). 201 if (final_status == prerender::FINAL_STATUS_UNSUPPORTED_SCHEME) {
173 // TODO(dougarnett): Create whitelist of final status codes that should
174 // not be considered failures (and define new RequestStatus code for them).
175 if (adapter_->GetFinalStatus() ==
176 prerender::FinalStatus::FINAL_STATUS_UNSUPPORTED_SCHEME) {
177 request_status = Offliner::RequestStatus::PRERENDERING_CANCELED;
178 UMA_HISTOGRAM_ENUMERATION( 202 UMA_HISTOGRAM_ENUMERATION(
179 "OfflinePages.Background.UnsupportedScheme.ConnectionType", 203 "OfflinePages.Background.UnsupportedScheme.ConnectionType",
180 net::NetworkChangeNotifier::GetConnectionType(), 204 net::NetworkChangeNotifier::GetConnectionType(),
181 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1); 205 net::NetworkChangeNotifier::ConnectionType::CONNECTION_LAST + 1);
182 } 206 }
183 adapter_->DestroyActive(); 207 adapter_->DestroyActive();
208 } else {
209 // No access to FinalStatus so classify as retryable failure.
210 request_status = Offliner::RequestStatus::PRERENDERING_FAILED;
184 } 211 }
185 212
186 snapshot_controller_.reset(nullptr); 213 snapshot_controller_.reset(nullptr);
187 session_contents_.reset(nullptr); 214 session_contents_.reset(nullptr);
188 state_ = State::IDLE; 215 state_ = State::IDLE;
189 base::ThreadTaskRunnerHandle::Get()->PostTask( 216 base::ThreadTaskRunnerHandle::Get()->PostTask(
190 FROM_HERE, base::Bind(callback_, request_status, nullptr)); 217 FROM_HERE, base::Bind(callback_, request_status, nullptr));
191 } 218 }
192 219
193 void PrerenderingLoader::CancelPrerender() { 220 void PrerenderingLoader::CancelPrerender() {
194 if (adapter_->IsActive()) { 221 if (adapter_->IsActive()) {
195 adapter_->DestroyActive(); 222 adapter_->DestroyActive();
196 } 223 }
197 snapshot_controller_.reset(nullptr); 224 snapshot_controller_.reset(nullptr);
198 session_contents_.reset(nullptr); 225 session_contents_.reset(nullptr);
199 state_ = State::IDLE; 226 state_ = State::IDLE;
200 } 227 }
201 228
202 } // namespace offline_pages 229 } // 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