Chromium Code Reviews| 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 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 int resource_status = 0; | 241 int resource_status = 0; |
| 242 | 242 |
| 243 if (!response->first_party_for_cookies().SchemeIsHTTPOrHTTPS()) | 243 if (!response->first_party_for_cookies().SchemeIsHTTPOrHTTPS()) |
| 244 resource_status |= RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_PAGE; | 244 resource_status |= RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_PAGE; |
| 245 | 245 |
| 246 if (!response->url().SchemeIsHTTPOrHTTPS()) | 246 if (!response->url().SchemeIsHTTPOrHTTPS()) |
| 247 resource_status |= RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_RESOURCE; | 247 resource_status |= RESOURCE_STATUS_NOT_HTTP_OR_HTTPS_RESOURCE; |
| 248 | 248 |
| 249 std::string mime_type; | 249 std::string mime_type; |
| 250 response->GetMimeType(&mime_type); | 250 response->GetMimeType(&mime_type); |
| 251 if (!mime_type.empty() && !mime_util::IsSupportedImageMimeType(mime_type) && | 251 const content::ResourceType resource_type = |
| 252 !mime_util::IsSupportedJavascriptMimeType(mime_type) && | 252 GetResourceTypeFromMimeType(mime_type, content::RESOURCE_TYPE_LAST_TYPE); |
| 253 !net::MatchesMimeType("text/css", mime_type)) { | 253 if (resource_type == content::RESOURCE_TYPE_LAST_TYPE) |
| 254 resource_status |= RESOURCE_STATUS_UNSUPPORTED_MIME_TYPE; | 254 resource_status |= RESOURCE_STATUS_UNSUPPORTED_MIME_TYPE; |
| 255 } | |
| 256 | 255 |
| 257 if (response->method() != "GET") | 256 if (response->method() != "GET") |
| 258 resource_status |= RESOURCE_STATUS_NOT_GET; | 257 resource_status |= RESOURCE_STATUS_NOT_GET; |
| 259 | 258 |
| 260 if (response->original_url().spec().length() > | 259 if (response->original_url().spec().length() > |
| 261 ResourcePrefetchPredictorTables::kMaxStringLength) { | 260 ResourcePrefetchPredictorTables::kMaxStringLength) { |
| 262 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; | 261 resource_status |= RESOURCE_STATUS_URL_TOO_LONG; |
| 263 } | 262 } |
| 264 | 263 |
| 265 if (!response->response_info().headers.get()) | 264 if (!response->response_info().headers.get()) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 289 response_time += base::TimeDelta::FromSeconds(1); | 288 response_time += base::TimeDelta::FromSeconds(1); |
| 290 base::TimeDelta freshness = | 289 base::TimeDelta freshness = |
| 291 response_info.headers->GetFreshnessLifetimes(response_time).freshness; | 290 response_info.headers->GetFreshnessLifetimes(response_time).freshness; |
| 292 return freshness > base::TimeDelta(); | 291 return freshness > base::TimeDelta(); |
| 293 } | 292 } |
| 294 | 293 |
| 295 // static | 294 // static |
| 296 content::ResourceType ResourcePrefetchPredictor::GetResourceTypeFromMimeType( | 295 content::ResourceType ResourcePrefetchPredictor::GetResourceTypeFromMimeType( |
| 297 const std::string& mime_type, | 296 const std::string& mime_type, |
| 298 content::ResourceType fallback) { | 297 content::ResourceType fallback) { |
| 299 if (mime_util::IsSupportedImageMimeType(mime_type)) | 298 if (mime_type.empty()) |
| 299 return fallback; | |
| 300 else if (mime_util::IsSupportedImageMimeType(mime_type)) | |
| 300 return content::RESOURCE_TYPE_IMAGE; | 301 return content::RESOURCE_TYPE_IMAGE; |
| 301 else if (mime_util::IsSupportedJavascriptMimeType(mime_type)) | 302 else if (mime_util::IsSupportedJavascriptMimeType(mime_type)) |
| 302 return content::RESOURCE_TYPE_SCRIPT; | 303 return content::RESOURCE_TYPE_SCRIPT; |
| 303 else if (net::MatchesMimeType("text/css", mime_type)) | 304 else if (net::MatchesMimeType("text/css", mime_type)) |
| 304 return content::RESOURCE_TYPE_STYLESHEET; | 305 return content::RESOURCE_TYPE_STYLESHEET; |
| 306 else if (net::MatchesMimeType("application/font-woff", mime_type)) | |
|
pasko
2016/07/28 14:04:04
let's add more mime types for fonts. I don't know
Benoit L
2016/07/28 16:11:53
Thank you for spotting this!
Done.
| |
| 307 return content::RESOURCE_TYPE_FONT_RESOURCE; | |
| 305 else | 308 else |
| 306 return fallback; | 309 return fallback; |
| 307 } | 310 } |
| 308 | 311 |
| 309 //////////////////////////////////////////////////////////////////////////////// | 312 //////////////////////////////////////////////////////////////////////////////// |
| 310 // ResourcePrefetchPredictor structs. | 313 // ResourcePrefetchPredictor structs. |
| 311 | 314 |
| 312 ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary() | 315 ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary() |
| 313 : resource_type(content::RESOURCE_TYPE_LAST_TYPE), | 316 : resource_type(content::RESOURCE_TYPE_LAST_TYPE), |
| 314 was_cached(false) { | 317 was_cached(false) { |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 // HistoryService is already loaded. Continue with Initialization. | 1338 // HistoryService is already loaded. Continue with Initialization. |
| 1336 OnHistoryAndCacheLoaded(); | 1339 OnHistoryAndCacheLoaded(); |
| 1337 return; | 1340 return; |
| 1338 } | 1341 } |
| 1339 DCHECK(!history_service_observer_.IsObserving(history_service)); | 1342 DCHECK(!history_service_observer_.IsObserving(history_service)); |
| 1340 history_service_observer_.Add(history_service); | 1343 history_service_observer_.Add(history_service); |
| 1341 return; | 1344 return; |
| 1342 } | 1345 } |
| 1343 | 1346 |
| 1344 } // namespace predictors | 1347 } // namespace predictors |
| OLD | NEW |