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 e5d71ed62dcecf04b069705ec5691be74cdc2c4b..f2cf6b5162d759f98c5c121fe6223287f028ff68 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor.h |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.h |
| @@ -16,6 +16,7 @@ |
| #include "chrome/browser/history/history_types.h" |
| #include "chrome/browser/predictors/resource_prefetch_common.h" |
| #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| +#include "chrome/browser/predictors/resource_prefetcher_manager.h" |
| #include "chrome/browser/profiles/profile_keyed_service.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| @@ -52,40 +53,24 @@ 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 |
| : public ProfileKeyedService, |
| public content::NotificationObserver, |
| + public ResourcePrefetcherManager::Delegate, |
|
dominich
2012/07/23 16:04:41
do you really need the delegate pattern here? Cons
Shishir
2012/08/01 22:35:24
Done.
|
| 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 |
| - // The number of resources we should report accuracy stats on. |
| - int num_resources_assumed_prefetched; // Default 25 |
| - }; |
| - |
| // Stores the data that we need to get from the URLRequest. |
| struct URLRequestSummary { |
| URLRequestSummary(); |
| @@ -101,11 +86,11 @@ class ResourcePrefetchPredictor |
| bool was_cached; |
| }; |
| - 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); |
| @@ -159,12 +144,19 @@ class ResourcePrefetchPredictor |
| typedef std::map<NavigationID, std::vector<URLRequestSummary> > NavigationMap; |
| typedef std::map<GURL, UrlTableCacheValue> UrlTableCacheMap; |
| + typedef std::map<NavigationID, linked_ptr<ResourcePrefetcher::RequestVector> > |
|
dominich
2012/07/23 16:04:41
red flag: linked_ptr is unlikely to be what you wa
Shishir
2012/08/01 22:35:24
Changed to plain pointers.
|
| + ResultsMap; |
| // content::NotificationObserver methods OVERRIDE. |
| virtual void Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| + // ResourcePrefetcherManager::Delegate methods OVERRIDE. |
| + virtual void FinishedPrefetchForNavigation( |
| + const NavigationID& navigation_id, |
| + scoped_ptr<ResourcePrefetcher::RequestVector> requests) OVERRIDE; |
| + |
| static bool IsHandledMainPage(net::URLRequest* request); |
| static bool IsHandledSubresource(net::URLRequest* response); |
| static bool IsCacheable(const net::URLRequest* response); |
| @@ -194,19 +186,24 @@ 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 SetTablesForTesting( |
| scoped_refptr<ResourcePrefetchPredictorTables> tables); |
| Profile* const profile_; |
| - Config config_; |
| + ResourcePrefetchPredictorConfig config_; |
|
dominich
2012/07/23 16:04:41
const?
Shishir
2012/08/01 22:35:24
Done.
|
| InitializationState initialization_state_; |
| scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
| + scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; |
|
dominich
2012/07/23 16:04:41
Why is this a refptr? I'm surprised there can be m
Shishir
2012/08/01 22:35:24
Needs to be refcounted because it needs to be acce
|
| content::NotificationRegistrar notification_registrar_; |
| NavigationMap inflight_navigations_; |
| UrlTableCacheMap url_table_cache_; |
| + ResultsMap results_map_; |
| DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
| }; |