| 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 ResourcePrefetchPredictor(const LoadingPredictorConfig& config, | 198 ResourcePrefetchPredictor(const LoadingPredictorConfig& config, |
| 199 Profile* profile); | 199 Profile* profile); |
| 200 ~ResourcePrefetchPredictor() override; | 200 ~ResourcePrefetchPredictor() override; |
| 201 | 201 |
| 202 // Starts initialization by posting a task to the DB thread to read the | 202 // Starts initialization by posting a task to the DB thread to read the |
| 203 // predictor database. | 203 // predictor database. |
| 204 void StartInitialization(); | 204 void StartInitialization(); |
| 205 void Shutdown(); | 205 void Shutdown(); |
| 206 | 206 |
| 207 // Thread safe. | |
| 208 static bool ShouldRecordRequest(net::URLRequest* request, | |
| 209 content::ResourceType resource_type); | |
| 210 static bool ShouldRecordResponse(net::URLRequest* response); | |
| 211 static bool ShouldRecordRedirect(net::URLRequest* response); | |
| 212 | |
| 213 // Determines the resource type from the declared one, falling back to MIME | 207 // Determines the resource type from the declared one, falling back to MIME |
| 214 // type detection when it is not explicit. | 208 // type detection when it is not explicit. |
| 215 static content::ResourceType GetResourceType( | 209 static content::ResourceType GetResourceType( |
| 216 content::ResourceType resource_type, | 210 content::ResourceType resource_type, |
| 217 const std::string& mime_type); | 211 const std::string& mime_type); |
| 218 | 212 |
| 219 // Determines the ResourceType from the mime type, defaulting to the | 213 // Determines the ResourceType from the mime type, defaulting to the |
| 220 // |fallback| if the ResourceType could not be determined. | 214 // |fallback| if the ResourceType could not be determined. |
| 221 static content::ResourceType GetResourceTypeFromMimeType( | 215 static content::ResourceType GetResourceTypeFromMimeType( |
| 222 const std::string& mime_type, | 216 const std::string& mime_type, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 INITIALIZED = 2 | 310 INITIALIZED = 2 |
| 317 }; | 311 }; |
| 318 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 312 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| 319 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; | 313 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; |
| 320 typedef ResourcePrefetchPredictorTables::ManifestDataMap ManifestDataMap; | 314 typedef ResourcePrefetchPredictorTables::ManifestDataMap ManifestDataMap; |
| 321 typedef ResourcePrefetchPredictorTables::OriginDataMap OriginDataMap; | 315 typedef ResourcePrefetchPredictorTables::OriginDataMap OriginDataMap; |
| 322 | 316 |
| 323 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>> | 317 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>> |
| 324 NavigationMap; | 318 NavigationMap; |
| 325 | 319 |
| 326 // Returns true if the main page request is supported for prediction. | |
| 327 static bool IsHandledMainPage(net::URLRequest* request); | |
| 328 | |
| 329 // Returns true if the subresource request is supported for prediction. | |
| 330 static bool IsHandledSubresource(net::URLRequest* request, | |
| 331 content::ResourceType resource_type); | |
| 332 | |
| 333 // Returns true if the subresource has a supported type. | |
| 334 static bool IsHandledResourceType(content::ResourceType resource_type, | |
| 335 const std::string& mime_type); | |
| 336 | |
| 337 // Returns true if the request (should have a response in it) is "no-store". | 320 // Returns true if the request (should have a response in it) is "no-store". |
| 338 static bool IsNoStore(const net::URLRequest& request); | 321 static bool IsNoStore(const net::URLRequest& request); |
| 339 | 322 |
| 340 static void SetAllowPortInUrlsForTesting(bool state); | |
| 341 | |
| 342 // Functions called on different network events pertaining to the loading of | 323 // Functions called on different network events pertaining to the loading of |
| 343 // main frame resource or sub resources. | 324 // main frame resource or sub resources. |
| 344 void OnMainFrameRequest(const URLRequestSummary& request); | 325 void OnMainFrameRequest(const URLRequestSummary& request); |
| 345 void OnMainFrameResponse(const URLRequestSummary& response); | 326 void OnMainFrameResponse(const URLRequestSummary& response); |
| 346 void OnMainFrameRedirect(const URLRequestSummary& response); | 327 void OnMainFrameRedirect(const URLRequestSummary& response); |
| 347 void OnSubresourceResponse(const URLRequestSummary& response); | 328 void OnSubresourceResponse(const URLRequestSummary& response); |
| 348 void OnSubresourceRedirect(const URLRequestSummary& response); | 329 void OnSubresourceRedirect(const URLRequestSummary& response); |
| 349 | 330 |
| 350 // Called when onload completes for a navigation. We treat this point as the | 331 // Called when onload completes for a navigation. We treat this point as the |
| 351 // "completion" of the navigation. The resources requested by the page up to | 332 // "completion" of the navigation. The resources requested by the page up to |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 | 508 |
| 528 private: | 509 private: |
| 529 ResourcePrefetchPredictor* predictor_; | 510 ResourcePrefetchPredictor* predictor_; |
| 530 | 511 |
| 531 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 512 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 532 }; | 513 }; |
| 533 | 514 |
| 534 } // namespace predictors | 515 } // namespace predictors |
| 535 | 516 |
| 536 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 517 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| OLD | NEW |