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 09e0402ffea38d4aa1d6fa9f402df9dc9b72b2ca..aec0333a15ac6daa18e1ed98938f9f7307225f29 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor.h |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.h |
| @@ -14,6 +14,7 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/time.h" |
| #include "chrome/browser/history/history_types.h" |
| +#include "chrome/browser/predictors/resource_prefetcher.h" |
| #include "chrome/browser/predictors/resource_prefetch_common.h" |
| #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| #include "chrome/browser/profiles/profile_keyed_service.h" |
| @@ -35,6 +36,8 @@ class URLRequest; |
| namespace predictors { |
| +class ResourcePrefetcherManager; |
| + |
| // Contains logic for learning what can be prefetched and for kicking off |
| // speculative prefetching. |
| // - The class is a profile keyed service owned by the profile. |
| @@ -52,10 +55,16 @@ namespace predictors { |
| // PredictorDatabase. |
| // * ResourcePrefetchPredictor - Learns about resource requirements per URL in |
| // the UI thread through the ResourcePrefetchPredictorObserver and perisists |
| -// it to disk in the DB thread through the ResourcePrefetchPredictorTables. |
| -// Owned by profile. |
| +// it to disk in the DB thread through the ResourcePrefetchPredictorTables. It |
| +// initiates resource prefetching using the ResourcePrefetcherManager. Owned |
| +// by profile. |
| +// * ResourcePrefetcherManager - Manages the ResourcePrefetchers that do the |
| +// prefetching on the IO thread. The manager is owned by the |
| +// ResourcePrefetchPredictor and interfaces between the predictor on the UI |
| +// thread and the prefetchers on the IO thread. |
| +// * ResourcePrefetcher - Lives entirely on the IO thread, owned by the |
| +// ResourcePrefetcherManager, and issues net::URLRequest to fetch resources. |
| // |
| -// TODO(shishir): Implement the prefetching of resources. |
| // TODO(shishir): Do speculative prefetching for https resources and/or https |
| // main_frame urls. |
| class ResourcePrefetchPredictor |
| @@ -63,27 +72,6 @@ class ResourcePrefetchPredictor |
| public content::NotificationObserver, |
| public base::SupportsWeakPtr<ResourcePrefetchPredictor> { |
| public: |
| - // The following config allows us to change the predictor constants and run |
| - // field trials with different constants. |
| - struct Config { |
| - // Initializes the config with default values. |
| - Config(); |
| - |
| - // If a navigation hasn't seen a load complete event in this much time, it |
| - // is considered abandoned. |
| - int max_navigation_lifetime_seconds; // Default 60 |
| - // Size of LRU caches for the Url data. |
| - size_t max_urls_to_track; // Default 500 |
| - // The number of times, we should have seen a visit to this Url in history |
| - // to start tracking it. This is to ensure we dont bother with oneoff |
| - // entries. |
| - int min_url_visit_count; // Default 3 |
| - // The maximum number of resources to store per entry. |
| - int max_resources_per_entry; // Default 50 |
| - // The number of consecutive misses after we stop tracking a resource Url. |
| - int max_consecutive_misses; // Default 3 |
| - }; |
| - |
| // Stores the data that we need to get from the URLRequest. |
| struct URLRequestSummary { |
| URLRequestSummary(); |
| @@ -100,11 +88,11 @@ class ResourcePrefetchPredictor |
| GURL redirect_url; // Empty unless request was redirected to a valid url. |
| }; |
| - ResourcePrefetchPredictor(const Config& config, Profile* profile); |
| + ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, |
| + Profile* profile); |
| virtual ~ResourcePrefetchPredictor(); |
| // Thread safe. |
| - static bool IsEnabled(Profile* profile); |
| static bool ShouldRecordRequest(net::URLRequest* request, |
| ResourceType::Type resource_type); |
| static bool ShouldRecordResponse(net::URLRequest* response); |
| @@ -118,6 +106,12 @@ class ResourcePrefetchPredictor |
| void RecordUrlResponse(const URLRequestSummary& response); |
| void RecordUrlRedirect(const URLRequestSummary& response); |
| + // Called by ResourcePrefetcherManager to notify that prefetching has finished |
| + // for a navigation. Takes ownership of |requests|. |
|
dominich
2012/09/11 18:40:43
I don't think the scoped_ptr necessarily suggests
Shishir
2012/09/11 19:36:31
Raw pointer it is. In this case the method is not
|
| + virtual void FinishedPrefetchForNavigation( |
| + const NavigationID& navigation_id, |
| + scoped_ptr<ResourcePrefetcher::RequestVector> requests); |
| + |
| private: |
| friend class ::PredictorsHandler; |
| friend class ResourcePrefetchPredictorTest; |
| @@ -158,12 +152,16 @@ class ResourcePrefetchPredictor |
| typedef std::map<NavigationID, std::vector<URLRequestSummary> > NavigationMap; |
| typedef std::map<GURL, UrlTableCacheValue> UrlTableCacheMap; |
| + typedef std::map<NavigationID, ResourcePrefetcher::RequestVector*> ResultsMap; |
| // content::NotificationObserver methods OVERRIDE. |
| virtual void Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| + // ProfileKeyedService methods OVERRIDE. |
| + virtual void Shutdown() OVERRIDE; |
| + |
| static bool IsHandledMainPage(net::URLRequest* request); |
| static bool IsHandledSubresource(net::URLRequest* response); |
| static bool IsCacheable(const net::URLRequest* response); |
| @@ -193,7 +191,9 @@ class ResourcePrefetchPredictor |
| void OnNavigationComplete(const NavigationID& navigation_id); |
| void LearnUrlNavigation(const GURL& main_frame_url, |
| const std::vector<URLRequestSummary>& new_value); |
| - void MaybeReportAccuracyStats(const NavigationID& navigation_id) const; |
| + void MaybeReportAccuracyStats(const NavigationID& navigation_id); |
| + void MaybeReportSimulatedAccuracyStats( |
| + const NavigationID& navigation_id) const; |
| void ReportAccuracyHistograms(const UrlTableRowVector& predicted, |
| const std::map<GURL, bool>& actual_resources, |
| int total_resources_fetched_from_network, |
| @@ -203,13 +203,16 @@ class ResourcePrefetchPredictor |
| scoped_refptr<ResourcePrefetchPredictorTables> tables); |
| Profile* const profile_; |
| - Config config_; |
| + ResourcePrefetchPredictorConfig const config_; |
| InitializationState initialization_state_; |
| scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
| + scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; |
| content::NotificationRegistrar notification_registrar_; |
| NavigationMap inflight_navigations_; |
| UrlTableCacheMap url_table_cache_; |
| + ResultsMap results_map_; |
| + STLValueDeleter<ResultsMap> results_map_deleter_; |
| DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
| }; |