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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 | 92 |
| 93 bool has_validators; | 93 bool has_validators; |
| 94 bool always_revalidate; | 94 bool always_revalidate; |
| 95 | 95 |
| 96 // Initializes a |URLRequestSummary| from a |URLRequest| response. | 96 // Initializes a |URLRequestSummary| from a |URLRequest| response. |
| 97 // Returns true for success. | 97 // Returns true for success. |
| 98 static bool SummarizeResponse(const net::URLRequest& request, | 98 static bool SummarizeResponse(const net::URLRequest& request, |
| 99 URLRequestSummary* summary); | 99 URLRequestSummary* summary); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // Stores information about inflight navigations. | |
| 103 struct Navigation { | |
|
Benoit L
2016/09/19 13:53:48
Navigation and requests are vague, overloaded word
alexilin
2016/09/19 16:49:25
This is actually an opposite thing :) This is a ve
| |
| 104 explicit Navigation(const GURL& initial_url); | |
| 105 ~Navigation(); | |
| 106 | |
| 107 GURL initial_url; | |
| 108 std::vector<URLRequestSummary> requests; | |
|
Benoit L
2016/09/19 13:53:48
Is there some invariant here, such as:
- requests
alexilin
2016/09/19 16:49:25
Related with misunderstanding in the comment above
| |
| 109 }; | |
| 110 | |
| 102 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, | 111 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, |
| 103 Profile* profile); | 112 Profile* profile); |
| 104 ~ResourcePrefetchPredictor() override; | 113 ~ResourcePrefetchPredictor() override; |
| 105 | 114 |
| 106 // Thread safe. | 115 // Thread safe. |
| 107 static bool ShouldRecordRequest(net::URLRequest* request, | 116 static bool ShouldRecordRequest(net::URLRequest* request, |
| 108 content::ResourceType resource_type); | 117 content::ResourceType resource_type); |
| 109 static bool ShouldRecordResponse(net::URLRequest* response); | 118 static bool ShouldRecordResponse(net::URLRequest* response); |
| 110 static bool ShouldRecordRedirect(net::URLRequest* response); | 119 static bool ShouldRecordRedirect(net::URLRequest* response); |
| 111 | 120 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 155 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 147 LazilyInitializeEmpty); | 156 LazilyInitializeEmpty); |
| 148 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 157 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 149 LazilyInitializeWithData); | 158 LazilyInitializeWithData); |
| 150 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 159 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 151 NavigationNotRecorded); | 160 NavigationNotRecorded); |
| 152 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, NavigationUrlInDB); | 161 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, NavigationUrlInDB); |
| 153 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, NavigationUrlNotInDB); | 162 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, NavigationUrlNotInDB); |
| 154 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 163 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 155 NavigationUrlNotInDBAndDBFull); | 164 NavigationUrlNotInDBAndDBFull); |
| 165 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, RedirectUrlNotInDB); | |
| 166 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, RedirectUrlInDB); | |
| 156 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, OnMainFrameRequest); | 167 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, OnMainFrameRequest); |
| 157 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, OnMainFrameRedirect); | 168 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, OnMainFrameRedirect); |
| 158 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 169 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 159 OnSubresourceResponse); | 170 OnSubresourceResponse); |
| 160 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetCorrectPLT); | 171 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetCorrectPLT); |
| 161 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, HandledResourceTypes); | 172 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, HandledResourceTypes); |
| 162 | 173 |
| 163 enum InitializationState { | 174 enum InitializationState { |
| 164 NOT_INITIALIZED = 0, | 175 NOT_INITIALIZED = 0, |
| 165 INITIALIZING = 1, | 176 INITIALIZING = 1, |
| 166 INITIALIZED = 2 | 177 INITIALIZED = 2 |
| 167 }; | 178 }; |
| 168 | 179 |
| 169 // Stores prefetching results. | 180 // Stores prefetching results. |
| 170 struct Result { | 181 struct Result { |
| 171 // Takes ownership of requests. | 182 // Takes ownership of requests. |
| 172 Result(PrefetchKeyType key_type, | 183 Result(PrefetchKeyType key_type, |
| 173 ResourcePrefetcher::RequestVector* requests); | 184 ResourcePrefetcher::RequestVector* requests); |
| 174 ~Result(); | 185 ~Result(); |
| 175 | 186 |
| 176 PrefetchKeyType key_type; | 187 PrefetchKeyType key_type; |
| 177 std::unique_ptr<ResourcePrefetcher::RequestVector> requests; | 188 std::unique_ptr<ResourcePrefetcher::RequestVector> requests; |
| 178 | 189 |
| 179 private: | 190 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(Result); | 191 DISALLOW_COPY_AND_ASSIGN(Result); |
| 181 }; | 192 }; |
| 182 | 193 |
| 183 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; | 194 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; |
| 184 typedef ResourcePrefetchPredictorTables::ResourceRows ResourceRows; | |
| 185 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; | 195 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; |
| 186 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 196 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| 187 typedef std::map<NavigationID, linked_ptr<std::vector<URLRequestSummary> > > | 197 |
| 188 NavigationMap; | 198 typedef ResourcePrefetchPredictorTables::RedirectRow RedirectRow; |
| 199 typedef ResourcePrefetchPredictorTables::RedirectData RedirectData; | |
| 200 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; | |
| 201 | |
| 202 typedef std::map<NavigationID, std::unique_ptr<Navigation>> NavigationMap; | |
| 189 typedef std::map<NavigationID, std::unique_ptr<Result>> ResultsMap; | 203 typedef std::map<NavigationID, std::unique_ptr<Result>> ResultsMap; |
| 190 | 204 |
| 191 // Returns true if the main page request is supported for prediction. | 205 // Returns true if the main page request is supported for prediction. |
| 192 static bool IsHandledMainPage(net::URLRequest* request); | 206 static bool IsHandledMainPage(net::URLRequest* request); |
| 193 | 207 |
| 194 // Returns true if the subresource request is supported for prediction. | 208 // Returns true if the subresource request is supported for prediction. |
| 195 static bool IsHandledSubresource(net::URLRequest* request, | 209 static bool IsHandledSubresource(net::URLRequest* request, |
| 196 content::ResourceType resource_type); | 210 content::ResourceType resource_type); |
| 197 | 211 |
| 198 // Returns true if the subresource has a supported type. | 212 // Returns true if the subresource has a supported type. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 void StartPrefetching(const NavigationID& navigation_id); | 247 void StartPrefetching(const NavigationID& navigation_id); |
| 234 | 248 |
| 235 // Stops prefetching that may be in progress corresponding to |navigation_id|. | 249 // Stops prefetching that may be in progress corresponding to |navigation_id|. |
| 236 void StopPrefetching(const NavigationID& navigation_id); | 250 void StopPrefetching(const NavigationID& navigation_id); |
| 237 | 251 |
| 238 // Starts initialization by posting a task to the DB thread to read the | 252 // Starts initialization by posting a task to the DB thread to read the |
| 239 // predictor database. | 253 // predictor database. |
| 240 void StartInitialization(); | 254 void StartInitialization(); |
| 241 | 255 |
| 242 // Callback for task to read predictor database. Takes ownership of | 256 // Callback for task to read predictor database. Takes ownership of |
| 243 // |url_data_map| and |host_data_map|. | 257 // all arguments. |
| 244 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, | 258 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, |
| 245 std::unique_ptr<PrefetchDataMap> host_data_map); | 259 std::unique_ptr<PrefetchDataMap> host_data_map, |
| 260 std::unique_ptr<RedirectDataMap> url_redirect_data_map, | |
| 261 std::unique_ptr<RedirectDataMap> host_redirect_data_map); | |
| 246 | 262 |
| 247 // Called during initialization when history is read and the predictor | 263 // Called during initialization when history is read and the predictor |
| 248 // database has been read. | 264 // database has been read. |
| 249 void OnHistoryAndCacheLoaded(); | 265 void OnHistoryAndCacheLoaded(); |
| 250 | 266 |
| 251 // Removes data for navigations where the onload never fired. Will cleanup | 267 // Removes data for navigations where the onload never fired. Will cleanup |
| 252 // inflight_navigations_ and results_map_. | 268 // inflight_navigations_ and results_map_. |
| 253 void CleanupAbandonedNavigations(const NavigationID& navigation_id); | 269 void CleanupAbandonedNavigations(const NavigationID& navigation_id); |
| 254 | 270 |
| 255 // Deletes all URLs from the predictor database, the caches and removes all | 271 // Deletes all URLs from the predictor database, the caches and removes all |
| 256 // inflight navigations. | 272 // inflight navigations. |
| 257 void DeleteAllUrls(); | 273 void DeleteAllUrls(); |
| 258 | 274 |
| 259 // Deletes data for the input |urls| and their corresponding hosts from the | 275 // Deletes data for the input |urls| and their corresponding hosts from the |
| 260 // predictor database and caches. | 276 // predictor database and caches. |
| 261 void DeleteUrls(const history::URLRows& urls); | 277 void DeleteUrls(const history::URLRows& urls); |
| 262 | 278 |
| 263 // Callback for GetUrlVisitCountTask. | 279 // Callback for GetUrlVisitCountTask. |
| 264 void OnVisitCountLookup(size_t visit_count, | 280 void OnVisitCountLookup(size_t visit_count, |
| 265 const NavigationID& navigation_id, | 281 const NavigationID& navigation_id, |
| 266 const std::vector<URLRequestSummary>& requests); | 282 const Navigation& navigation); |
| 267 | 283 |
| 268 // Removes the oldest entry in the input |data_map|, also deleting it from the | 284 // Removes the oldest entry in the input |data_map|, also deleting it from the |
| 269 // predictor database. | 285 // predictor database. |
| 270 void RemoveOldestEntryInPrefetchDataMap(PrefetchKeyType key_type, | 286 void RemoveOldestEntryInPrefetchDataMap(PrefetchKeyType key_type, |
| 271 PrefetchDataMap* data_map); | 287 PrefetchDataMap* data_map); |
| 272 | 288 |
| 289 void RemoveOldestEntryInRedirectDataMap(PrefetchKeyType key_type, | |
| 290 RedirectDataMap* data_map); | |
| 291 | |
| 273 // Merges resources in |new_resources| into the |data_map| and correspondingly | 292 // Merges resources in |new_resources| into the |data_map| and correspondingly |
| 274 // updates the predictor database. | 293 // updates the predictor database. |
| 275 void LearnNavigation(const std::string& key, | 294 void LearnNavigation(const std::string& key, |
| 276 PrefetchKeyType key_type, | 295 PrefetchKeyType key_type, |
| 277 const std::vector<URLRequestSummary>& new_resources, | 296 const std::vector<URLRequestSummary>& new_resources, |
| 278 size_t max_data_map_size, | 297 size_t max_data_map_size, |
| 279 PrefetchDataMap* data_map); | 298 PrefetchDataMap* data_map); |
| 280 | 299 |
| 300 // Updates information about final redirect destination for |key| in | |
| 301 // |redirect_map| and correspondingly updates the predictor database | |
| 302 void LearnRedirect(const std::string& key, | |
| 303 PrefetchKeyType key_type, | |
| 304 const std::string& final_redirect, | |
| 305 size_t max_redirect_map_size, | |
| 306 RedirectDataMap* redirect_map); | |
| 307 | |
| 281 // Reports overall page load time. | 308 // Reports overall page load time. |
| 282 void ReportPageLoadTimeStats(base::TimeDelta plt) const; | 309 void ReportPageLoadTimeStats(base::TimeDelta plt) const; |
| 283 | 310 |
| 284 // Reports page load time for prefetched and not prefetched pages | 311 // Reports page load time for prefetched and not prefetched pages |
| 285 void ReportPageLoadTimePrefetchStats( | 312 void ReportPageLoadTimePrefetchStats( |
| 286 base::TimeDelta plt, | 313 base::TimeDelta plt, |
| 287 bool prefetched, | 314 bool prefetched, |
| 288 base::Callback<void(int)> report_network_type_callback, | 315 base::Callback<void(int)> report_network_type_callback, |
| 289 PrefetchKeyType key_type) const; | 316 PrefetchKeyType key_type) const; |
| 290 | 317 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 tables_ = tables; | 352 tables_ = tables; |
| 326 } | 353 } |
| 327 | 354 |
| 328 Profile* const profile_; | 355 Profile* const profile_; |
| 329 ResourcePrefetchPredictorConfig const config_; | 356 ResourcePrefetchPredictorConfig const config_; |
| 330 InitializationState initialization_state_; | 357 InitializationState initialization_state_; |
| 331 scoped_refptr<ResourcePrefetchPredictorTables> tables_; | 358 scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
| 332 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; | 359 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; |
| 333 base::CancelableTaskTracker history_lookup_consumer_; | 360 base::CancelableTaskTracker history_lookup_consumer_; |
| 334 | 361 |
| 335 // Map of all the navigations in flight to their resource requests. | |
| 336 NavigationMap inflight_navigations_; | |
| 337 | |
| 338 // Copy of the data in the predictor tables. | 362 // Copy of the data in the predictor tables. |
| 339 std::unique_ptr<PrefetchDataMap> url_table_cache_; | 363 std::unique_ptr<PrefetchDataMap> url_table_cache_; |
| 340 std::unique_ptr<PrefetchDataMap> host_table_cache_; | 364 std::unique_ptr<PrefetchDataMap> host_table_cache_; |
| 365 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; | |
| 366 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; | |
| 341 | 367 |
| 368 NavigationMap inflight_navigations_; | |
| 342 ResultsMap results_map_; | 369 ResultsMap results_map_; |
| 343 | 370 |
| 344 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 371 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 345 history_service_observer_; | 372 history_service_observer_; |
| 346 | 373 |
| 347 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); | 374 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
| 348 }; | 375 }; |
| 349 | 376 |
| 350 } // namespace predictors | 377 } // namespace predictors |
| 351 | 378 |
| 352 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 379 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| OLD | NEW |