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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 2227723002: predictors: Also track "no-cache" and "must-revalidate" resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/predictors/resource_prefetch_predictor.h" 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 "application/font-ttf"}; 56 "application/font-ttf"};
57 57
58 // For reporting whether a subresource is handled or not, and for what reasons. 58 // For reporting whether a subresource is handled or not, and for what reasons.
59 enum ResourceStatus { 59 enum ResourceStatus {
60 RESOURCE_STATUS_HANDLED = 0, 60 RESOURCE_STATUS_HANDLED = 0,
61 RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_PAGE = 1, 61 RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_PAGE = 1,
62 RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_RESOURCE = 2, 62 RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_RESOURCE = 2,
63 RESOURCE_STATUS_UNSUPPORTED_RESOURCE_TYPE = 4, 63 RESOURCE_STATUS_UNSUPPORTED_RESOURCE_TYPE = 4,
64 RESOURCE_STATUS_NOT_GET = 8, 64 RESOURCE_STATUS_NOT_GET = 8,
65 RESOURCE_STATUS_URL_TOO_LONG = 16, 65 RESOURCE_STATUS_URL_TOO_LONG = 16,
66 RESOURCE_STATUS_NOT_CACHEABLE = 32, 66 RESOURCE_STATUS_NO_STORE = 32,
pasko 2016/08/09 09:31:11 this enum is used in a histogram, hence it should
Benoit L 2016/08/09 12:24:38 Acknowledged.
67 RESOURCE_STATUS_HEADERS_MISSING = 64, 67 RESOURCE_STATUS_HEADERS_MISSING = 64,
68 RESOURCE_STATUS_MAX = 128, 68 RESOURCE_STATUS_MAX = 128,
69 }; 69 };
70 70
71 // For reporting various interesting events that occur during the loading of a 71 // For reporting various interesting events that occur during the loading of a
72 // single main frame. 72 // single main frame.
73 enum NavigationEvent { 73 enum NavigationEvent {
74 NAVIGATION_EVENT_REQUEST_STARTED = 0, 74 NAVIGATION_EVENT_REQUEST_STARTED = 0,
75 NAVIGATION_EVENT_REQUEST_REDIRECTED = 1, 75 NAVIGATION_EVENT_REQUEST_REDIRECTED = 1,
76 NAVIGATION_EVENT_REQUEST_REDIRECTED_EMPTY_URL = 2, 76 NAVIGATION_EVENT_REQUEST_REDIRECTED_EMPTY_URL = 2,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 resource_status |= RESOURCE_STATUS_NOT_GET; 273 resource_status |= RESOURCE_STATUS_NOT_GET;
274 274
275 if (response->original_url().spec().length() > 275 if (response->original_url().spec().length() >
276 ResourcePrefetchPredictorTables::kMaxStringLength) { 276 ResourcePrefetchPredictorTables::kMaxStringLength) {
277 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; 277 resource_status |= RESOURCE_STATUS_URL_TOO_LONG;
278 } 278 }
279 279
280 if (!response->response_info().headers.get()) 280 if (!response->response_info().headers.get())
281 resource_status |= RESOURCE_STATUS_HEADERS_MISSING; 281 resource_status |= RESOURCE_STATUS_HEADERS_MISSING;
282 282
283 if (!IsCacheable(response)) 283 if (IsNoStore(response))
284 resource_status |= RESOURCE_STATUS_NOT_CACHEABLE; 284 resource_status |= RESOURCE_STATUS_NO_STORE;
285 285
286 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ResourceStatus", 286 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ResourceStatus",
pasko 2016/08/09 09:31:11 do we actually need all of this histogram? Alterna
Benoit L 2016/08/09 12:24:38 Per offline discussion, removed the histogram (but
287 resource_status, 287 resource_status,
288 RESOURCE_STATUS_MAX); 288 RESOURCE_STATUS_MAX);
289 289
290 return resource_status == 0; 290 return resource_status == 0;
291 } 291 }
292 292
293 // static 293 // static
294 bool ResourcePrefetchPredictor::IsHandledResourceType( 294 bool ResourcePrefetchPredictor::IsHandledResourceType(
295 content::ResourceType resource_type, 295 content::ResourceType resource_type,
296 const std::string& mime_type) { 296 const std::string& mime_type) {
297 bool handled = resource_type == content::RESOURCE_TYPE_STYLESHEET || 297 bool handled = resource_type == content::RESOURCE_TYPE_STYLESHEET ||
298 resource_type == content::RESOURCE_TYPE_SCRIPT || 298 resource_type == content::RESOURCE_TYPE_SCRIPT ||
299 resource_type == content::RESOURCE_TYPE_IMAGE || 299 resource_type == content::RESOURCE_TYPE_IMAGE ||
300 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE; 300 resource_type == content::RESOURCE_TYPE_FONT_RESOURCE;
301 // Restricts content::RESOURCE_TYPE_{PREFETCH,SUB_RESOURCE} to a small set of 301 // Restricts content::RESOURCE_TYPE_{PREFETCH,SUB_RESOURCE} to a small set of
302 // mime types, because these resource types don't communicate how the 302 // mime types, because these resource types don't communicate how the
303 // resources 303 // resources
304 // will be used. 304 // will be used.
305 if ((resource_type == content::RESOURCE_TYPE_PREFETCH || 305 if ((resource_type == content::RESOURCE_TYPE_PREFETCH ||
306 resource_type == content::RESOURCE_TYPE_SUB_RESOURCE)) { 306 resource_type == content::RESOURCE_TYPE_SUB_RESOURCE)) {
307 content::ResourceType resource_type_from_mime = GetResourceTypeFromMimeType( 307 content::ResourceType resource_type_from_mime = GetResourceTypeFromMimeType(
308 mime_type, content::RESOURCE_TYPE_LAST_TYPE); 308 mime_type, content::RESOURCE_TYPE_LAST_TYPE);
309 handled = resource_type_from_mime != content::RESOURCE_TYPE_LAST_TYPE; 309 handled = resource_type_from_mime != content::RESOURCE_TYPE_LAST_TYPE;
310 } 310 }
311 return handled; 311 return handled;
312 } 312 }
313 313
314 // static 314 // static
315 bool ResourcePrefetchPredictor::IsCacheable(const net::URLRequest* response) { 315 bool ResourcePrefetchPredictor::IsNoStore(const net::URLRequest* response) {
316 if (response->was_cached()) 316 if (response->was_cached())
317 return true; 317 return false;
318 318
319 // For non cached responses, we will ensure that the freshness lifetime is
320 // some sane value.
321 const net::HttpResponseInfo& response_info = response->response_info(); 319 const net::HttpResponseInfo& response_info = response->response_info();
322 if (!response_info.headers.get()) 320 if (!response_info.headers.get())
323 return false; 321 return false;
324 base::Time response_time(response_info.response_time); 322 return response_info.headers->HasHeaderValue("cache-control", "no-store");
325 response_time += base::TimeDelta::FromSeconds(1);
326 base::TimeDelta freshness =
327 response_info.headers->GetFreshnessLifetimes(response_time).freshness;
328 return freshness > base::TimeDelta();
329 } 323 }
330 324
331 // static 325 // static
332 content::ResourceType ResourcePrefetchPredictor::GetResourceTypeFromMimeType( 326 content::ResourceType ResourcePrefetchPredictor::GetResourceTypeFromMimeType(
333 const std::string& mime_type, 327 const std::string& mime_type,
334 content::ResourceType fallback) { 328 content::ResourceType fallback) {
335 if (mime_type.empty()) { 329 if (mime_type.empty()) {
336 return fallback; 330 return fallback;
337 } else if (mime_util::IsSupportedImageMimeType(mime_type)) { 331 } else if (mime_util::IsSupportedImageMimeType(mime_type)) {
338 return content::RESOURCE_TYPE_IMAGE; 332 return content::RESOURCE_TYPE_IMAGE;
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // HistoryService is already loaded. Continue with Initialization. 1379 // HistoryService is already loaded. Continue with Initialization.
1386 OnHistoryAndCacheLoaded(); 1380 OnHistoryAndCacheLoaded();
1387 return; 1381 return;
1388 } 1382 }
1389 DCHECK(!history_service_observer_.IsObserving(history_service)); 1383 DCHECK(!history_service_observer_.IsObserving(history_service));
1390 history_service_observer_.Add(history_service); 1384 history_service_observer_.Add(history_service);
1391 return; 1385 return;
1392 } 1386 }
1393 1387
1394 } // namespace predictors 1388 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698