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 #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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 96 |
| 97 // Initializes a |URLRequestSummary| from a |URLRequest| response. | 97 // Initializes a |URLRequestSummary| from a |URLRequest| response. |
| 98 // Returns true for success. | 98 // Returns true for success. |
| 99 static bool SummarizeResponse(const net::URLRequest& request, | 99 static bool SummarizeResponse(const net::URLRequest& request, |
| 100 URLRequestSummary* summary); | 100 URLRequestSummary* summary); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, | 103 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, |
| 104 Profile* profile); | 104 Profile* profile); |
| 105 ~ResourcePrefetchPredictor() override; | 105 ~ResourcePrefetchPredictor() override; |
| 106 | |
|
pasko
2016/10/04 12:19:47
nit: this empty line was nicely separating the com
Benoit L
2016/10/05 08:36:22
Done.
| |
| 107 // Thread safe. | 106 // Thread safe. |
| 108 static bool ShouldRecordRequest(net::URLRequest* request, | 107 static bool ShouldRecordRequest(net::URLRequest* request, |
| 109 content::ResourceType resource_type); | 108 content::ResourceType resource_type); |
| 110 static bool ShouldRecordResponse(net::URLRequest* response); | 109 static bool ShouldRecordResponse(net::URLRequest* response); |
| 111 static bool ShouldRecordRedirect(net::URLRequest* response); | 110 static bool ShouldRecordRedirect(net::URLRequest* response); |
| 112 | 111 |
| 113 // Determines the resource type from the declared one, falling back to MIME | 112 // Determines the resource type from the declared one, falling back to MIME |
| 114 // type detection when it is not explicit. | 113 // type detection when it is not explicit. |
| 115 static content::ResourceType GetResourceType( | 114 static content::ResourceType GetResourceType( |
| 116 content::ResourceType resource_type, | 115 content::ResourceType resource_type, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 void OnMainFrameRequest(const URLRequestSummary& request); | 232 void OnMainFrameRequest(const URLRequestSummary& request); |
| 234 void OnMainFrameResponse(const URLRequestSummary& response); | 233 void OnMainFrameResponse(const URLRequestSummary& response); |
| 235 void OnMainFrameRedirect(const URLRequestSummary& response); | 234 void OnMainFrameRedirect(const URLRequestSummary& response); |
| 236 void OnSubresourceResponse(const URLRequestSummary& response); | 235 void OnSubresourceResponse(const URLRequestSummary& response); |
| 237 | 236 |
| 238 // Called when onload completes for a navigation. We treat this point as the | 237 // Called when onload completes for a navigation. We treat this point as the |
| 239 // "completion" of the navigation. The resources requested by the page up to | 238 // "completion" of the navigation. The resources requested by the page up to |
| 240 // this point are the only ones considered for prefetching. | 239 // this point are the only ones considered for prefetching. |
| 241 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info); | 240 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info); |
| 242 | 241 |
| 243 // Returns true if there is PrefetchData that can be used for the | 242 // Returns true if there is PrefetchData that can be used for a URL and fills |
| 244 // navigation and fills in the |prefetch_data| to resources that need to be | 243 // in the |prefetch_data| to resources that need to be prefetched. |
|
gone
2016/10/04 17:49:16
|prefetch_data| is no longer a variable here.
Benoit L
2016/10/05 08:36:22
Done.
| |
| 245 // prefetched. | 244 bool GetPrefetchData(const GURL& main_frame_url, std::vector<GURL>* urls); |
| 246 bool GetPrefetchData(const NavigationID& navigation_id, | |
| 247 std::vector<GURL>* urls, | |
| 248 PrefetchKeyType* key_type); | |
| 249 | 245 |
| 250 // Converts a PrefetchData into a list of URLs. | 246 // Converts a PrefetchData into a list of URLs. |
| 251 void PopulatePrefetcherRequest(const PrefetchData& data, | 247 void PopulatePrefetcherRequest(const PrefetchData& data, |
| 252 std::vector<GURL>* urls); | 248 std::vector<GURL>* urls); |
| 253 | 249 |
| 250 public: | |
| 254 // Starts prefetching if it is enabled and prefetching data exists for the | 251 // Starts prefetching if it is enabled and prefetching data exists for the |
| 255 // NavigationID either at the URL or at the host level. | 252 // NavigationID either at the URL or at the host level. |
| 256 void StartPrefetching(const NavigationID& navigation_id); | 253 void StartPrefetching(const GURL& main_frame_url); |
| 257 | 254 |
| 258 // Stops prefetching that may be in progress corresponding to |navigation_id|. | 255 // Stops prefetching that may be in progress corresponding to |navigation_id|. |
| 259 void StopPrefetching(const NavigationID& navigation_id); | 256 void StopPrefetching(const GURL& main_frame_url); |
| 260 | 257 |
| 258 private: | |
| 261 // Starts initialization by posting a task to the DB thread to read the | 259 // Starts initialization by posting a task to the DB thread to read the |
| 262 // predictor database. | 260 // predictor database. |
| 263 void StartInitialization(); | 261 void StartInitialization(); |
| 264 | 262 |
| 265 // Callback for task to read predictor database. Takes ownership of | 263 // Callback for task to read predictor database. Takes ownership of |
| 266 // all arguments. | 264 // all arguments. |
| 267 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, | 265 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, |
| 268 std::unique_ptr<PrefetchDataMap> host_data_map, | 266 std::unique_ptr<PrefetchDataMap> host_data_map, |
| 269 std::unique_ptr<RedirectDataMap> url_redirect_data_map, | 267 std::unique_ptr<RedirectDataMap> url_redirect_data_map, |
| 270 std::unique_ptr<RedirectDataMap> host_redirect_data_map); | 268 std::unique_ptr<RedirectDataMap> host_redirect_data_map); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 | 359 |
| 362 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 360 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 363 history_service_observer_; | 361 history_service_observer_; |
| 364 | 362 |
| 365 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); | 363 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
| 366 }; | 364 }; |
| 367 | 365 |
| 368 } // namespace predictors | 366 } // namespace predictors |
| 369 | 367 |
| 370 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 368 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| OLD | NEW |