| OLD | NEW |
| 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/history/history_service_factory.h" | 18 #include "chrome/browser/history/history_service_factory.h" |
| 19 #include "chrome/browser/predictors/predictor_database.h" | 19 #include "chrome/browser/predictors/predictor_database.h" |
| 20 #include "chrome/browser/predictors/predictor_database_factory.h" | 20 #include "chrome/browser/predictors/predictor_database_factory.h" |
| 21 #include "chrome/browser/predictors/resource_prefetcher_manager.h" | 21 #include "chrome/browser/predictors/resource_prefetcher_manager.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "components/history/core/browser/history_database.h" | 25 #include "components/history/core/browser/history_database.h" |
| 26 #include "components/history/core/browser/history_db_task.h" | 26 #include "components/history/core/browser/history_db_task.h" |
| 27 #include "components/history/core/browser/history_service.h" | 27 #include "components/history/core/browser/history_service.h" |
| 28 #include "components/mime_util/mime_util.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/resource_request_info.h" | 31 #include "content/public/browser/resource_request_info.h" |
| 31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 32 #include "net/base/mime_util.h" | 33 #include "net/base/mime_util.h" |
| 33 #include "net/base/network_change_notifier.h" | 34 #include "net/base/network_change_notifier.h" |
| 34 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
| 35 #include "net/url_request/url_request.h" | 36 #include "net/url_request/url_request.h" |
| 36 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
| 37 | 38 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 net::URLRequest* response) { | 240 net::URLRequest* response) { |
| 240 int resource_status = 0; | 241 int resource_status = 0; |
| 241 if (response->first_party_for_cookies().scheme() != url::kHttpScheme) | 242 if (response->first_party_for_cookies().scheme() != url::kHttpScheme) |
| 242 resource_status |= RESOURCE_STATUS_NOT_HTTP_PAGE; | 243 resource_status |= RESOURCE_STATUS_NOT_HTTP_PAGE; |
| 243 | 244 |
| 244 if (response->original_url().scheme() != url::kHttpScheme) | 245 if (response->original_url().scheme() != url::kHttpScheme) |
| 245 resource_status |= RESOURCE_STATUS_NOT_HTTP_RESOURCE; | 246 resource_status |= RESOURCE_STATUS_NOT_HTTP_RESOURCE; |
| 246 | 247 |
| 247 std::string mime_type; | 248 std::string mime_type; |
| 248 response->GetMimeType(&mime_type); | 249 response->GetMimeType(&mime_type); |
| 249 if (!mime_type.empty() && | 250 if (!mime_type.empty() && !mime_util::IsSupportedImageMimeType(mime_type) && |
| 250 !net::IsSupportedImageMimeType(mime_type.c_str()) && | 251 !mime_util::IsSupportedJavascriptMimeType(mime_type) && |
| 251 !net::IsSupportedJavascriptMimeType(mime_type.c_str()) && | |
| 252 !net::MatchesMimeType("text/css", mime_type)) { | 252 !net::MatchesMimeType("text/css", mime_type)) { |
| 253 resource_status |= RESOURCE_STATUS_UNSUPPORTED_MIME_TYPE; | 253 resource_status |= RESOURCE_STATUS_UNSUPPORTED_MIME_TYPE; |
| 254 } | 254 } |
| 255 | 255 |
| 256 if (response->method() != "GET") | 256 if (response->method() != "GET") |
| 257 resource_status |= RESOURCE_STATUS_NOT_GET; | 257 resource_status |= RESOURCE_STATUS_NOT_GET; |
| 258 | 258 |
| 259 if (response->original_url().spec().length() > | 259 if (response->original_url().spec().length() > |
| 260 ResourcePrefetchPredictorTables::kMaxStringLength) { | 260 ResourcePrefetchPredictorTables::kMaxStringLength) { |
| 261 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; | 261 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 288 response_time += base::TimeDelta::FromSeconds(1); | 288 response_time += base::TimeDelta::FromSeconds(1); |
| 289 base::TimeDelta freshness = | 289 base::TimeDelta freshness = |
| 290 response_info.headers->GetFreshnessLifetimes(response_time).freshness; | 290 response_info.headers->GetFreshnessLifetimes(response_time).freshness; |
| 291 return freshness > base::TimeDelta(); | 291 return freshness > base::TimeDelta(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // static | 294 // static |
| 295 content::ResourceType ResourcePrefetchPredictor::GetResourceTypeFromMimeType( | 295 content::ResourceType ResourcePrefetchPredictor::GetResourceTypeFromMimeType( |
| 296 const std::string& mime_type, | 296 const std::string& mime_type, |
| 297 content::ResourceType fallback) { | 297 content::ResourceType fallback) { |
| 298 if (net::IsSupportedImageMimeType(mime_type.c_str())) | 298 if (mime_util::IsSupportedImageMimeType(mime_type)) |
| 299 return content::RESOURCE_TYPE_IMAGE; | 299 return content::RESOURCE_TYPE_IMAGE; |
| 300 else if (net::IsSupportedJavascriptMimeType(mime_type.c_str())) | 300 else if (mime_util::IsSupportedJavascriptMimeType(mime_type)) |
| 301 return content::RESOURCE_TYPE_SCRIPT; | 301 return content::RESOURCE_TYPE_SCRIPT; |
| 302 else if (net::MatchesMimeType("text/css", mime_type)) | 302 else if (net::MatchesMimeType("text/css", mime_type)) |
| 303 return content::RESOURCE_TYPE_STYLESHEET; | 303 return content::RESOURCE_TYPE_STYLESHEET; |
| 304 else | 304 else |
| 305 return fallback; | 305 return fallback; |
| 306 } | 306 } |
| 307 | 307 |
| 308 //////////////////////////////////////////////////////////////////////////////// | 308 //////////////////////////////////////////////////////////////////////////////// |
| 309 // ResourcePrefetchPredictor structs. | 309 // ResourcePrefetchPredictor structs. |
| 310 | 310 |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 // HistoryService is already loaded. Continue with Initialization. | 1337 // HistoryService is already loaded. Continue with Initialization. |
| 1338 OnHistoryAndCacheLoaded(); | 1338 OnHistoryAndCacheLoaded(); |
| 1339 return; | 1339 return; |
| 1340 } | 1340 } |
| 1341 DCHECK(!history_service_observer_.IsObserving(history_service)); | 1341 DCHECK(!history_service_observer_.IsObserving(history_service)); |
| 1342 history_service_observer_.Add(history_service); | 1342 history_service_observer_.Add(history_service); |
| 1343 return; | 1343 return; |
| 1344 } | 1344 } |
| 1345 | 1345 |
| 1346 } // namespace predictors | 1346 } // namespace predictors |
| OLD | NEW |