| 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..bc9ddcaf743f0c609641b0f2eb3f3c8ae1a15396 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,29 +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
|
| - // 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 +87,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);
|
| @@ -119,6 +105,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.
|
| + virtual void FinishedPrefetchForNavigation(
|
| + const NavigationID& navigation_id,
|
| + scoped_ptr<ResourcePrefetcher::RequestVector> requests);
|
| +
|
| private:
|
| friend class ::PredictorsHandler;
|
| friend class ResourcePrefetchPredictorTest;
|
| @@ -159,6 +151,7 @@ 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,
|
| @@ -194,19 +187,25 @@ 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 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);
|
| };
|
|
|