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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/scoped_observer.h" |
16 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "chrome/browser/predictors/resource_prefetch_common.h" | 19 #include "chrome/browser/predictors/resource_prefetch_common.h" |
19 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 20 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
20 #include "chrome/browser/predictors/resource_prefetcher.h" | 21 #include "chrome/browser/predictors/resource_prefetcher.h" |
| 22 #include "components/history/core/browser/history_service_observer.h" |
21 #include "components/history/core/browser/history_types.h" | 23 #include "components/history/core/browser/history_types.h" |
22 #include "components/keyed_service/core/keyed_service.h" | 24 #include "components/keyed_service/core/keyed_service.h" |
23 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
24 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
25 #include "content/public/common/resource_type.h" | 27 #include "content/public/common/resource_type.h" |
26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
27 | 29 |
28 class PredictorsHandler; | 30 class PredictorsHandler; |
29 class Profile; | 31 class Profile; |
30 | 32 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // ResourcePrefetcherManager, and issues net::URLRequest to fetch resources. | 70 // ResourcePrefetcherManager, and issues net::URLRequest to fetch resources. |
69 // | 71 // |
70 // TODO(shishir): Do speculative prefetching for https resources and/or https | 72 // TODO(shishir): Do speculative prefetching for https resources and/or https |
71 // main frame urls. | 73 // main frame urls. |
72 // TODO(zhenw): Currently only main frame requests/redirects/responses are | 74 // TODO(zhenw): Currently only main frame requests/redirects/responses are |
73 // recorded. Consider recording sub-frame responses independently or together | 75 // recorded. Consider recording sub-frame responses independently or together |
74 // with main frame. | 76 // with main frame. |
75 class ResourcePrefetchPredictor | 77 class ResourcePrefetchPredictor |
76 : public KeyedService, | 78 : public KeyedService, |
77 public content::NotificationObserver, | 79 public content::NotificationObserver, |
| 80 public history::HistoryServiceObserver, |
78 public base::SupportsWeakPtr<ResourcePrefetchPredictor> { | 81 public base::SupportsWeakPtr<ResourcePrefetchPredictor> { |
79 public: | 82 public: |
80 // Stores the data that we need to get from the URLRequest. | 83 // Stores the data that we need to get from the URLRequest. |
81 struct URLRequestSummary { | 84 struct URLRequestSummary { |
82 URLRequestSummary(); | 85 URLRequestSummary(); |
83 URLRequestSummary(const URLRequestSummary& other); | 86 URLRequestSummary(const URLRequestSummary& other); |
84 ~URLRequestSummary(); | 87 ~URLRequestSummary(); |
85 | 88 |
86 NavigationID navigation_id; | 89 NavigationID navigation_id; |
87 GURL resource_url; | 90 GURL resource_url; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 PrefetchKeyType key_type, | 289 PrefetchKeyType key_type, |
287 const std::vector<URLRequestSummary>& actual, | 290 const std::vector<URLRequestSummary>& actual, |
288 const ResourcePrefetcher::RequestVector& predicted) const; | 291 const ResourcePrefetcher::RequestVector& predicted) const; |
289 void ReportPredictedAccuracyStatsHelper( | 292 void ReportPredictedAccuracyStatsHelper( |
290 PrefetchKeyType key_type, | 293 PrefetchKeyType key_type, |
291 const ResourcePrefetcher::RequestVector& predicted, | 294 const ResourcePrefetcher::RequestVector& predicted, |
292 const std::map<GURL, bool>& actual, | 295 const std::map<GURL, bool>& actual, |
293 size_t total_resources_fetched_from_network, | 296 size_t total_resources_fetched_from_network, |
294 size_t max_assumed_prefetched) const; | 297 size_t max_assumed_prefetched) const; |
295 | 298 |
| 299 // history::HistoryServiceObserver: |
| 300 void OnHistoryServiceLoaded(HistoryService* history_service) override; |
| 301 |
| 302 // Used to connect to HistoryService or register for service loaded |
| 303 // notificatioan. |
| 304 void ConnectToHistoryService(); |
| 305 |
296 // Used for testing to inject mock tables. | 306 // Used for testing to inject mock tables. |
297 void set_mock_tables(scoped_refptr<ResourcePrefetchPredictorTables> tables) { | 307 void set_mock_tables(scoped_refptr<ResourcePrefetchPredictorTables> tables) { |
298 tables_ = tables; | 308 tables_ = tables; |
299 } | 309 } |
300 | 310 |
301 Profile* const profile_; | 311 Profile* const profile_; |
302 ResourcePrefetchPredictorConfig const config_; | 312 ResourcePrefetchPredictorConfig const config_; |
303 InitializationState initialization_state_; | 313 InitializationState initialization_state_; |
304 scoped_refptr<ResourcePrefetchPredictorTables> tables_; | 314 scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
305 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; | 315 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; |
306 content::NotificationRegistrar notification_registrar_; | 316 content::NotificationRegistrar notification_registrar_; |
307 base::CancelableTaskTracker history_lookup_consumer_; | 317 base::CancelableTaskTracker history_lookup_consumer_; |
308 | 318 |
309 // Map of all the navigations in flight to their resource requests. | 319 // Map of all the navigations in flight to their resource requests. |
310 NavigationMap inflight_navigations_; | 320 NavigationMap inflight_navigations_; |
311 | 321 |
312 // Copy of the data in the predictor tables. | 322 // Copy of the data in the predictor tables. |
313 scoped_ptr<PrefetchDataMap> url_table_cache_; | 323 scoped_ptr<PrefetchDataMap> url_table_cache_; |
314 scoped_ptr<PrefetchDataMap> host_table_cache_; | 324 scoped_ptr<PrefetchDataMap> host_table_cache_; |
315 | 325 |
316 ResultsMap results_map_; | 326 ResultsMap results_map_; |
317 STLValueDeleter<ResultsMap> results_map_deleter_; | 327 STLValueDeleter<ResultsMap> results_map_deleter_; |
318 | 328 |
| 329 ScopedObserver<HistoryService, history::HistoryServiceObserver> |
| 330 history_service_observer_; |
| 331 |
319 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); | 332 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
320 }; | 333 }; |
321 | 334 |
322 } // namespace predictors | 335 } // namespace predictors |
323 | 336 |
324 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 337 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
OLD | NEW |