| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 if (response->method() != "GET") | 203 if (response->method() != "GET") |
| 204 resource_status |= RESOURCE_STATUS_NOT_GET; | 204 resource_status |= RESOURCE_STATUS_NOT_GET; |
| 205 | 205 |
| 206 if (response->original_url().spec().length() > | 206 if (response->original_url().spec().length() > |
| 207 ResourcePrefetchPredictorTables::kMaxStringLength) { | 207 ResourcePrefetchPredictorTables::kMaxStringLength) { |
| 208 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; | 208 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; |
| 209 } | 209 } |
| 210 | 210 |
| 211 if (!response->response_info().headers) | 211 if (!response->response_info().headers.get()) |
| 212 resource_status |= RESOURCE_STATUS_HEADERS_MISSING; | 212 resource_status |= RESOURCE_STATUS_HEADERS_MISSING; |
| 213 | 213 |
| 214 if (!IsCacheable(response)) | 214 if (!IsCacheable(response)) |
| 215 resource_status |= RESOURCE_STATUS_NOT_CACHEABLE; | 215 resource_status |= RESOURCE_STATUS_NOT_CACHEABLE; |
| 216 | 216 |
| 217 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ResourceStatus", | 217 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.ResourceStatus", |
| 218 resource_status, | 218 resource_status, |
| 219 RESOURCE_STATUS_MAX); | 219 RESOURCE_STATUS_MAX); |
| 220 | 220 |
| 221 return resource_status == 0; | 221 return resource_status == 0; |
| 222 } | 222 } |
| 223 | 223 |
| 224 // static | 224 // static |
| 225 bool ResourcePrefetchPredictor::IsCacheable(const net::URLRequest* response) { | 225 bool ResourcePrefetchPredictor::IsCacheable(const net::URLRequest* response) { |
| 226 if (response->was_cached()) | 226 if (response->was_cached()) |
| 227 return true; | 227 return true; |
| 228 | 228 |
| 229 // For non cached responses, we will ensure that the freshness lifetime is | 229 // For non cached responses, we will ensure that the freshness lifetime is |
| 230 // some sane value. | 230 // some sane value. |
| 231 const net::HttpResponseInfo& response_info = response->response_info(); | 231 const net::HttpResponseInfo& response_info = response->response_info(); |
| 232 if (!response_info.headers) | 232 if (!response_info.headers.get()) |
| 233 return false; | 233 return false; |
| 234 base::Time response_time(response_info.response_time); | 234 base::Time response_time(response_info.response_time); |
| 235 response_time += base::TimeDelta::FromSeconds(1); | 235 response_time += base::TimeDelta::FromSeconds(1); |
| 236 base::TimeDelta freshness = response_info.headers->GetFreshnessLifetime( | 236 base::TimeDelta freshness = response_info.headers->GetFreshnessLifetime( |
| 237 response_time); | 237 response_time); |
| 238 return freshness > base::TimeDelta(); | 238 return freshness > base::TimeDelta(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // static | 241 // static |
| 242 ResourceType::Type ResourcePrefetchPredictor::GetResourceTypeFromMimeType( | 242 ResourceType::Type ResourcePrefetchPredictor::GetResourceTypeFromMimeType( |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 break; | 435 break; |
| 436 } | 436 } |
| 437 | 437 |
| 438 default: | 438 default: |
| 439 NOTREACHED() << "Unexpected notification observed."; | 439 NOTREACHED() << "Unexpected notification observed."; |
| 440 break; | 440 break; |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 void ResourcePrefetchPredictor::Shutdown() { | 444 void ResourcePrefetchPredictor::Shutdown() { |
| 445 if (prefetch_manager_) { | 445 if (prefetch_manager_.get()) { |
| 446 prefetch_manager_->ShutdownOnUIThread(); | 446 prefetch_manager_->ShutdownOnUIThread(); |
| 447 prefetch_manager_ = NULL; | 447 prefetch_manager_ = NULL; |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 void ResourcePrefetchPredictor::OnMainFrameRequest( | 451 void ResourcePrefetchPredictor::OnMainFrameRequest( |
| 452 const URLRequestSummary& request) { | 452 const URLRequestSummary& request) { |
| 453 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 453 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 454 DCHECK_EQ(INITIALIZED, initialization_state_); | 454 DCHECK_EQ(INITIALIZED, initialization_state_); |
| 455 | 455 |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( | 1239 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( |
| 1240 "PrefetchFromNetworkPercentOfTotalFromNetwork", | 1240 "PrefetchFromNetworkPercentOfTotalFromNetwork", |
| 1241 prefetch_network * 100.0 / total_resources_fetched_from_network); | 1241 prefetch_network * 100.0 / total_resources_fetched_from_network); |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE | 1244 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE |
| 1245 #undef RPP_PREDICTED_HISTOGRAM_COUNTS | 1245 #undef RPP_PREDICTED_HISTOGRAM_COUNTS |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 } // namespace predictors | 1248 } // namespace predictors |
| OLD | NEW |