| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 // Stores all subresource requests within a single navigation, from initial | 113 // Stores all subresource requests within a single navigation, from initial |
| 114 // main frame request to navigation completion. | 114 // main frame request to navigation completion. |
| 115 std::vector<URLRequestSummary> subresource_requests; | 115 std::vector<URLRequestSummary> subresource_requests; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, | 118 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, |
| 119 Profile* profile); | 119 Profile* profile); |
| 120 ~ResourcePrefetchPredictor() override; | 120 ~ResourcePrefetchPredictor() override; |
| 121 | 121 |
| 122 // Starts initialization by posting a task to the DB thread to read the |
| 123 // predictor database. |
| 124 void StartInitialization(); |
| 125 |
| 122 // Thread safe. | 126 // Thread safe. |
| 123 static bool ShouldRecordRequest(net::URLRequest* request, | 127 static bool ShouldRecordRequest(net::URLRequest* request, |
| 124 content::ResourceType resource_type); | 128 content::ResourceType resource_type); |
| 125 static bool ShouldRecordResponse(net::URLRequest* response); | 129 static bool ShouldRecordResponse(net::URLRequest* response); |
| 126 static bool ShouldRecordRedirect(net::URLRequest* response); | 130 static bool ShouldRecordRedirect(net::URLRequest* response); |
| 127 | 131 |
| 128 // Determines the resource type from the declared one, falling back to MIME | 132 // Determines the resource type from the declared one, falling back to MIME |
| 129 // type detection when it is not explicit. | 133 // type detection when it is not explicit. |
| 130 static content::ResourceType GetResourceType( | 134 static content::ResourceType GetResourceType( |
| 131 content::ResourceType resource_type, | 135 content::ResourceType resource_type, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // prefetched. | 245 // prefetched. |
| 242 bool GetPrefetchData(const GURL& main_frame_url, std::vector<GURL>* urls); | 246 bool GetPrefetchData(const GURL& main_frame_url, std::vector<GURL>* urls); |
| 243 | 247 |
| 244 // Returns true iff the |data_map| contains PrefetchData that can be used | 248 // Returns true iff the |data_map| contains PrefetchData that can be used |
| 245 // for a |main_frame_key| and fills |urls| with resources that need to be | 249 // for a |main_frame_key| and fills |urls| with resources that need to be |
| 246 // prefetched. | 250 // prefetched. |
| 247 bool PopulatePrefetcherRequest(const std::string& main_frame_key, | 251 bool PopulatePrefetcherRequest(const std::string& main_frame_key, |
| 248 const PrefetchDataMap& data_map, | 252 const PrefetchDataMap& data_map, |
| 249 std::vector<GURL>* urls); | 253 std::vector<GURL>* urls); |
| 250 | 254 |
| 251 // Starts initialization by posting a task to the DB thread to read the | |
| 252 // predictor database. | |
| 253 void StartInitialization(); | |
| 254 | |
| 255 // Callback for task to read predictor database. Takes ownership of | 255 // Callback for task to read predictor database. Takes ownership of |
| 256 // all arguments. | 256 // all arguments. |
| 257 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, | 257 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, |
| 258 std::unique_ptr<PrefetchDataMap> host_data_map, | 258 std::unique_ptr<PrefetchDataMap> host_data_map, |
| 259 std::unique_ptr<RedirectDataMap> url_redirect_data_map, | 259 std::unique_ptr<RedirectDataMap> url_redirect_data_map, |
| 260 std::unique_ptr<RedirectDataMap> host_redirect_data_map); | 260 std::unique_ptr<RedirectDataMap> host_redirect_data_map); |
| 261 | 261 |
| 262 // Called during initialization when history is read and the predictor | 262 // Called during initialization when history is read and the predictor |
| 263 // database has been read. | 263 // database has been read. |
| 264 void OnHistoryAndCacheLoaded(); | 264 void OnHistoryAndCacheLoaded(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 375 |
| 376 private: | 376 private: |
| 377 ResourcePrefetchPredictor* predictor_; | 377 ResourcePrefetchPredictor* predictor_; |
| 378 | 378 |
| 379 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 379 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 380 }; | 380 }; |
| 381 | 381 |
| 382 } // namespace predictors | 382 } // namespace predictors |
| 383 | 383 |
| 384 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 384 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| OLD | NEW |