Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor.h |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor.h b/chrome/browser/predictors/resource_prefetch_predictor.h |
| index 82fdfee2fc000862a6e8400c43b4f4801926062a..51e34078b79feca6f3661a169712068471735fc1 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor.h |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.h |
| @@ -99,6 +99,15 @@ class ResourcePrefetchPredictor |
| URLRequestSummary* summary); |
| }; |
| + // Stores information about inflight navigations. |
| + struct Navigation { |
|
pasko
2016/09/22 14:27:09
The name 'Navigation' looks a bit generic, so it s
alexilin
2016/09/22 16:48:19
I don't think that 'RedirectChain' is also a good
pasko
2016/09/26 12:28:15
I would also prefer moving it into the implementat
alexilin
2016/09/27 14:52:45
Renamed to 'PageRequestSummary' and moved into pri
|
| + explicit Navigation(const GURL& initial_url); |
| + ~Navigation(); |
| + |
| + GURL initial_url; |
| + std::vector<URLRequestSummary> subresource_requests; |
| + }; |
| + |
| ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, |
| Profile* profile); |
| ~ResourcePrefetchPredictor() override; |
| @@ -153,6 +162,8 @@ class ResourcePrefetchPredictor |
| FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, NavigationUrlNotInDB); |
| FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| NavigationUrlNotInDBAndDBFull); |
| + FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, RedirectUrlNotInDB); |
| + FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, RedirectUrlInDB); |
| FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, OnMainFrameRequest); |
| FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, OnMainFrameRedirect); |
| FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| @@ -182,8 +193,10 @@ class ResourcePrefetchPredictor |
| typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; |
| typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| - typedef std::map<NavigationID, linked_ptr<std::vector<URLRequestSummary> > > |
| - NavigationMap; |
| + |
| + typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; |
| + |
| + typedef std::map<NavigationID, std::unique_ptr<Navigation>> NavigationMap; |
| typedef std::map<NavigationID, std::unique_ptr<Result>> ResultsMap; |
| // Returns true if the main page request is supported for prediction. |
| @@ -238,9 +251,11 @@ class ResourcePrefetchPredictor |
| void StartInitialization(); |
| // Callback for task to read predictor database. Takes ownership of |
| - // |url_data_map| and |host_data_map|. |
| + // all arguments. |
| void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, |
| - std::unique_ptr<PrefetchDataMap> host_data_map); |
| + std::unique_ptr<PrefetchDataMap> host_data_map, |
| + std::unique_ptr<RedirectDataMap> url_redirect_data_map, |
| + std::unique_ptr<RedirectDataMap> host_redirect_data_map); |
| // Called during initialization when history is read and the predictor |
| // database has been read. |
| @@ -261,20 +276,33 @@ class ResourcePrefetchPredictor |
| // Callback for GetUrlVisitCountTask. |
| void OnVisitCountLookup(size_t visit_count, |
| const NavigationID& navigation_id, |
| - const std::vector<URLRequestSummary>& requests); |
| + const Navigation& navigation); |
| // Removes the oldest entry in the input |data_map|, also deleting it from the |
| // predictor database. |
| void RemoveOldestEntryInPrefetchDataMap(PrefetchKeyType key_type, |
| PrefetchDataMap* data_map); |
| + void RemoveOldestEntryInRedirectDataMap(PrefetchKeyType key_type, |
| + RedirectDataMap* data_map); |
| + |
| // Merges resources in |new_resources| into the |data_map| and correspondingly |
| - // updates the predictor database. |
| + // updates the predictor database. Also calls LearnRedirect if relevant. |
| void LearnNavigation(const std::string& key, |
| PrefetchKeyType key_type, |
| const std::vector<URLRequestSummary>& new_resources, |
| size_t max_data_map_size, |
| - PrefetchDataMap* data_map); |
| + PrefetchDataMap* data_map, |
| + const std::string& redirect_origin_key, |
| + RedirectDataMap* redirect_map); |
| + |
| + // Updates information about final redirect destination for |key| in |
| + // |redirect_map| and correspondingly updates the predictor database |
| + void LearnRedirect(const std::string& key, |
| + PrefetchKeyType key_type, |
| + const std::string& final_redirect, |
| + size_t max_redirect_map_size, |
| + RedirectDataMap* redirect_map); |
| // Reports overall page load time. |
| void ReportPageLoadTimeStats(base::TimeDelta plt) const; |
| @@ -330,13 +358,13 @@ class ResourcePrefetchPredictor |
| scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; |
| base::CancelableTaskTracker history_lookup_consumer_; |
| - // Map of all the navigations in flight to their resource requests. |
| - NavigationMap inflight_navigations_; |
| - |
| // Copy of the data in the predictor tables. |
| std::unique_ptr<PrefetchDataMap> url_table_cache_; |
| std::unique_ptr<PrefetchDataMap> host_table_cache_; |
| + std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; |
| + std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; |
| + NavigationMap inflight_navigations_; |
| ResultsMap results_map_; |
| ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |