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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 std::unique_ptr<ResourcePrefetcher::RequestVector> requests; | 177 std::unique_ptr<ResourcePrefetcher::RequestVector> requests; |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(Result); | 180 DISALLOW_COPY_AND_ASSIGN(Result); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; | 183 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; |
| 184 typedef ResourcePrefetchPredictorTables::ResourceRows ResourceRows; | 184 typedef ResourcePrefetchPredictorTables::ResourceRows ResourceRows; |
| 185 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; | 185 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; |
| 186 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 186 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| 187 | |
| 188 typedef ResourcePrefetchPredictorTables::RedirectStatRow RedirectStatRow; | |
| 189 typedef ResourcePrefetchPredictorTables::RedirectStatRows RedirectStatRows; | |
| 190 typedef ResourcePrefetchPredictorTables::RedirectData RedirectData; | |
| 191 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; | |
| 192 | |
| 187 typedef std::map<NavigationID, linked_ptr<std::vector<URLRequestSummary> > > | 193 typedef std::map<NavigationID, linked_ptr<std::vector<URLRequestSummary> > > |
|
mattcary
2016/09/09 13:19:21
To be consistent with other code, should remove sp
| |
| 188 NavigationMap; | 194 NavigationMap; |
| 189 typedef std::map<NavigationID, std::unique_ptr<Result>> ResultsMap; | 195 typedef std::map<NavigationID, std::unique_ptr<Result>> ResultsMap; |
| 196 typedef std::map<NavigationID, linked_ptr<std::vector<GURL> > > RedirectsMap; | |
|
mattcary
2016/09/09 09:16:11
Should use unique_ptr instead, see
https://www.ch
alexilin
2016/09/09 13:59:19
Yep, I used linked_ptr like in a rest of code but
| |
| 190 | 197 |
| 191 // Returns true if the main page request is supported for prediction. | 198 // Returns true if the main page request is supported for prediction. |
| 192 static bool IsHandledMainPage(net::URLRequest* request); | 199 static bool IsHandledMainPage(net::URLRequest* request); |
| 193 | 200 |
| 194 // Returns true if the subresource request is supported for prediction. | 201 // Returns true if the subresource request is supported for prediction. |
| 195 static bool IsHandledSubresource(net::URLRequest* request, | 202 static bool IsHandledSubresource(net::URLRequest* request, |
| 196 content::ResourceType resource_type); | 203 content::ResourceType resource_type); |
| 197 | 204 |
| 198 // Returns true if the subresource has a supported type. | 205 // Returns true if the subresource has a supported type. |
| 199 static bool IsHandledResourceType(content::ResourceType resource_type, | 206 static bool IsHandledResourceType(content::ResourceType resource_type, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 void StartPrefetching(const NavigationID& navigation_id); | 240 void StartPrefetching(const NavigationID& navigation_id); |
| 234 | 241 |
| 235 // Stops prefetching that may be in progress corresponding to |navigation_id|. | 242 // Stops prefetching that may be in progress corresponding to |navigation_id|. |
| 236 void StopPrefetching(const NavigationID& navigation_id); | 243 void StopPrefetching(const NavigationID& navigation_id); |
| 237 | 244 |
| 238 // Starts initialization by posting a task to the DB thread to read the | 245 // Starts initialization by posting a task to the DB thread to read the |
| 239 // predictor database. | 246 // predictor database. |
| 240 void StartInitialization(); | 247 void StartInitialization(); |
| 241 | 248 |
| 242 // Callback for task to read predictor database. Takes ownership of | 249 // Callback for task to read predictor database. Takes ownership of |
| 243 // |url_data_map| and |host_data_map|. | 250 // all arguments. |
| 244 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, | 251 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, |
| 245 std::unique_ptr<PrefetchDataMap> host_data_map); | 252 std::unique_ptr<PrefetchDataMap> host_data_map, |
| 253 std::unique_ptr<RedirectDataMap> url_redirect_data_map, | |
| 254 std::unique_ptr<RedirectDataMap> host_redirect_data_map); | |
| 246 | 255 |
| 247 // Called during initialization when history is read and the predictor | 256 // Called during initialization when history is read and the predictor |
| 248 // database has been read. | 257 // database has been read. |
| 249 void OnHistoryAndCacheLoaded(); | 258 void OnHistoryAndCacheLoaded(); |
| 250 | 259 |
| 251 // Removes data for navigations where the onload never fired. Will cleanup | 260 // Removes data for navigations where the onload never fired. Will cleanup |
| 252 // inflight_navigations_ and results_map_. | 261 // inflight_navigations_ and results_map_. |
| 253 void CleanupAbandonedNavigations(const NavigationID& navigation_id); | 262 void CleanupAbandonedNavigations(const NavigationID& navigation_id); |
| 254 | 263 |
| 255 // Deletes all URLs from the predictor database, the caches and removes all | 264 // Deletes all URLs from the predictor database, the caches and removes all |
| 256 // inflight navigations. | 265 // inflight navigations. |
| 257 void DeleteAllUrls(); | 266 void DeleteAllUrls(); |
| 258 | 267 |
| 259 // Deletes data for the input |urls| and their corresponding hosts from the | 268 // Deletes data for the input |urls| and their corresponding hosts from the |
| 260 // predictor database and caches. | 269 // predictor database and caches. |
| 261 void DeleteUrls(const history::URLRows& urls); | 270 void DeleteUrls(const history::URLRows& urls); |
| 262 | 271 |
| 263 // Callback for GetUrlVisitCountTask. | 272 // Callback for GetUrlVisitCountTask. |
| 264 void OnVisitCountLookup(size_t visit_count, | 273 void OnVisitCountLookup(size_t visit_count, |
| 265 const NavigationID& navigation_id, | 274 const NavigationID& navigation_id, |
| 266 const std::vector<URLRequestSummary>& requests); | 275 const std::vector<URLRequestSummary>& requests, |
| 276 std::vector<GURL>* redirects); | |
| 267 | 277 |
| 268 // Removes the oldest entry in the input |data_map|, also deleting it from the | 278 // Removes the oldest entry in the input |data_map|, also deleting it from the |
| 269 // predictor database. | 279 // predictor database. |
| 270 void RemoveOldestEntryInPrefetchDataMap(PrefetchKeyType key_type, | 280 void RemoveOldestEntryInPrefetchDataMap(PrefetchKeyType key_type, |
| 271 PrefetchDataMap* data_map); | 281 PrefetchDataMap* data_map); |
| 272 | 282 |
| 273 // Merges resources in |new_resources| into the |data_map| and correspondingly | 283 // Merges resources in |new_resources| into the |data_map| and correspondingly |
| 274 // updates the predictor database. | 284 // updates the predictor database. |
| 275 void LearnNavigation(const std::string& key, | 285 void LearnNavigation(const std::string& key, |
| 276 PrefetchKeyType key_type, | 286 PrefetchKeyType key_type, |
| 277 const std::vector<URLRequestSummary>& new_resources, | 287 const std::vector<URLRequestSummary>& new_resources, |
| 278 size_t max_data_map_size, | 288 size_t max_data_map_size, |
| 279 PrefetchDataMap* data_map); | 289 PrefetchDataMap* data_map); |
| 280 | 290 |
| 291 // Updates information about final redirect destination for all |keys| in | |
| 292 // |redirect_map| and correspondingly updates the predictor database | |
| 293 void LearnRedirects(const std::vector<std::string>& keys, | |
| 294 PrefetchKeyType key_type, | |
| 295 const std::string& final_redirect, | |
| 296 size_t max_redirect_map_size, | |
| 297 RedirectDataMap* redirect_map); | |
| 298 | |
| 281 // Reports overall page load time. | 299 // Reports overall page load time. |
| 282 void ReportPageLoadTimeStats(base::TimeDelta plt) const; | 300 void ReportPageLoadTimeStats(base::TimeDelta plt) const; |
| 283 | 301 |
| 284 // Reports page load time for prefetched and not prefetched pages | 302 // Reports page load time for prefetched and not prefetched pages |
| 285 void ReportPageLoadTimePrefetchStats( | 303 void ReportPageLoadTimePrefetchStats( |
| 286 base::TimeDelta plt, | 304 base::TimeDelta plt, |
| 287 bool prefetched, | 305 bool prefetched, |
| 288 base::Callback<void(int)> report_network_type_callback, | 306 base::Callback<void(int)> report_network_type_callback, |
| 289 PrefetchKeyType key_type) const; | 307 PrefetchKeyType key_type) const; |
| 290 | 308 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 scoped_refptr<ResourcePrefetchPredictorTables> tables_; | 349 scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
| 332 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; | 350 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; |
| 333 base::CancelableTaskTracker history_lookup_consumer_; | 351 base::CancelableTaskTracker history_lookup_consumer_; |
| 334 | 352 |
| 335 // Map of all the navigations in flight to their resource requests. | 353 // Map of all the navigations in flight to their resource requests. |
| 336 NavigationMap inflight_navigations_; | 354 NavigationMap inflight_navigations_; |
| 337 | 355 |
| 338 // Copy of the data in the predictor tables. | 356 // Copy of the data in the predictor tables. |
| 339 std::unique_ptr<PrefetchDataMap> url_table_cache_; | 357 std::unique_ptr<PrefetchDataMap> url_table_cache_; |
| 340 std::unique_ptr<PrefetchDataMap> host_table_cache_; | 358 std::unique_ptr<PrefetchDataMap> host_table_cache_; |
| 359 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; | |
| 360 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; | |
| 341 | 361 |
| 342 ResultsMap results_map_; | 362 ResultsMap results_map_; |
| 363 RedirectsMap redirects_map_; | |
| 343 | 364 |
| 344 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 365 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 345 history_service_observer_; | 366 history_service_observer_; |
| 346 | 367 |
| 347 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); | 368 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
| 348 }; | 369 }; |
| 349 | 370 |
| 350 } // namespace predictors | 371 } // namespace predictors |
| 351 | 372 |
| 352 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 373 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| OLD | NEW |