Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7670)

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor.h

Issue 2440723002: predictors: Make ResourcePrefetchPredictor observable. (Closed)
Patch Set: Rename TestObserver to TestDelegate Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetch_predictor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6c238fb336f3e9049c5d7766aa603c4d1898384c..08796fdc212f74347092f58fd4df3d13d625eb95 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor.h
@@ -100,6 +100,40 @@ class ResourcePrefetchPredictor
URLRequestSummary* summary);
};
+ // Stores the data learned from a single navigation.
+ struct PageRequestSummary {
+ explicit PageRequestSummary(const GURL& main_frame_url);
+ PageRequestSummary(const PageRequestSummary& other);
+ ~PageRequestSummary();
+
+ GURL main_frame_url;
+ GURL initial_url;
+
+ // Stores all subresource requests within a single navigation, from initial
+ // main frame request to navigation completion.
+ std::vector<URLRequestSummary> subresource_requests;
+ };
+
+ // An interface used to notify that data in the resource prefetch predictor
+ // has changed. All methods are invoked on the UI thread.
+ class TestDelegate {
pasko 2016/10/26 12:05:40 can this be moved outside of ResourcePrefetchPredi
pasko 2016/10/26 12:05:41 I realized that this class can be forward-declared
alexilin 2016/10/26 13:09:59 I'll try to advocate existing implementation. For
pasko 2016/10/26 13:48:35 I would argue that this long name is used only in
alexilin 2016/10/26 15:22:01 Done.
+ public:
+ virtual ~TestDelegate();
pasko 2016/10/26 12:05:41 A comment would be worth adding IMO: // De-registe
alexilin 2016/10/26 13:09:59 Done.
+
+ virtual void OnNavigationLearned(size_t url_visit_count,
+ const PageRequestSummary& summary) {}
+
+ protected:
+ // |predictor| must be non-NULL and has to outlive the TestDelegate.
+ // Also the predictor must not have a TestDelegate set.
+ explicit TestDelegate(ResourcePrefetchPredictor* predictor);
+
+ private:
+ ResourcePrefetchPredictor* predictor_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDelegate);
+ };
+
ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config,
Profile* profile);
~ResourcePrefetchPredictor() override;
@@ -132,6 +166,19 @@ class ResourcePrefetchPredictor
// Called when the main frame of a page completes loading.
void RecordMainFrameLoadComplete(const NavigationID& navigation_id);
+ // Starts prefetching if it is enabled and prefetching data exists for the
+ // |main_frame_url| either at the URL or at the host level.
+ void StartPrefetching(const GURL& main_frame_url);
+
+ // Stops prefetching that may be in progress corresponding to
+ // |main_frame_url|.
+ void StopPrefetching(const GURL& main_frame_url);
+
+ // Sets the |delegate| to be notified when the resource prefetch predictor
+ // data changes. Previously registered delegate will be discarded. Call
+ // this with nullptr parameter to de-register delegate.
+ void SetDelegateForTesting(TestDelegate* delegate);
+
private:
friend class ::PredictorsHandler;
friend class ResourcePrefetchPredictorTest;
@@ -166,48 +213,6 @@ class ResourcePrefetchPredictor
INITIALIZED = 2
};
- // Stores information about inflight navigations.
- struct PageRequestSummary {
- explicit PageRequestSummary(const GURL& initial_url);
- ~PageRequestSummary();
-
- GURL initial_url;
-
- // Stores all subresources requests within a single navigation, from initial
- // main frame request to navigation completion.
- std::vector<URLRequestSummary> subresource_requests;
- };
-
- // Used to fetch the visit count for a URL from the History database.
- class GetUrlVisitCountTask : public history::HistoryDBTask {
- public:
- typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary;
- typedef ResourcePrefetchPredictor::PageRequestSummary PageRequestSummary;
- typedef base::Callback<void(size_t, // Visit count.
- const NavigationID&,
- const PageRequestSummary&)>
- VisitInfoCallback;
-
- GetUrlVisitCountTask(const NavigationID& navigation_id,
- std::unique_ptr<PageRequestSummary> summary,
- VisitInfoCallback callback);
-
- bool RunOnDBThread(history::HistoryBackend* backend,
- history::HistoryDatabase* db) override;
-
- void DoneRunOnMainThread() override;
-
- private:
- ~GetUrlVisitCountTask() override;
-
- int visit_count_;
- NavigationID navigation_id_;
- std::unique_ptr<PageRequestSummary> summary_;
- VisitInfoCallback callback_;
-
- DISALLOW_COPY_AND_ASSIGN(GetUrlVisitCountTask);
- };
-
typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap;
typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap;
@@ -261,15 +266,6 @@ class ResourcePrefetchPredictor
const PrefetchDataMap& data_map,
std::vector<GURL>* urls);
- public:
- // Starts prefetching if it is enabled and prefetching data exists for the
- // NavigationID either at the URL or at the host level.
- void StartPrefetching(const GURL& main_frame_url);
-
- // Stops prefetching that may be in progress corresponding to |navigation_id|.
- void StopPrefetching(const GURL& main_frame_url);
-
- private:
// Starts initialization by posting a task to the DB thread to read the
// predictor database.
void StartInitialization();
@@ -298,8 +294,7 @@ class ResourcePrefetchPredictor
void DeleteUrls(const history::URLRows& urls);
// Callback for GetUrlVisitCountTask.
- void OnVisitCountLookup(size_t visit_count,
- const NavigationID& navigation_id,
+ void OnVisitCountLookup(size_t url_visit_count,
const PageRequestSummary& summary);
// Removes the oldest entry in the input |data_map|, also deleting it from the
@@ -357,6 +352,7 @@ class ResourcePrefetchPredictor
}
Profile* const profile_;
+ TestDelegate* delegate_;
ResourcePrefetchPredictorConfig const config_;
InitializationState initialization_state_;
scoped_refptr<ResourcePrefetchPredictorTables> tables_;
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetch_predictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698