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

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

Issue 2440723002: predictors: Make ResourcePrefetchPredictor observable. (Closed)
Patch Set: . 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..7b2ce2fea5cf6c6b18610d8dbee26b189101f5a7 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor.h
@@ -16,6 +16,7 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
pasko 2016/10/21 14:41:36 not needed any more?
alexilin 2016/10/21 16:04:19 Done. I still don't know how to keep list of inclu
#include "base/scoped_observer.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
@@ -100,6 +101,19 @@ class ResourcePrefetchPredictor
URLRequestSummary* summary);
};
+ // Stores information about inflight navigation.
+ struct PageRequestSummary {
+ explicit PageRequestSummary(const GURL& main_frame_url);
+ ~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;
+ };
+
ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config,
Profile* profile);
~ResourcePrefetchPredictor() override;
@@ -132,6 +146,13 @@ 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
+ // 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:
friend class ::PredictorsHandler;
friend class ResourcePrefetchPredictorTest;
@@ -160,52 +181,26 @@ class ResourcePrefetchPredictor
FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint);
FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData);
- enum InitializationState {
- NOT_INITIALIZED = 0,
- INITIALIZING = 1,
- 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 {
+ // An interface used to notify clients (observers) of this object that data in
+ // the resource prefetch predictor has changed. Register the observer via
+ // ResourcePrefetchPredictor::SetObserverForTesting.
+ class Observer {
pasko 2016/10/21 14:41:36 s/Observer/TestObserver/
alexilin 2016/10/21 16:04:19 Done.
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);
+ virtual void OnNavigationLearned(size_t url_visit_count,
+ const PageRequestSummary& summary) {}
- bool RunOnDBThread(history::HistoryBackend* backend,
- history::HistoryDatabase* db) override;
-
- void DoneRunOnMainThread() override;
+ protected:
+ Observer() = default;
pasko 2016/10/21 14:41:36 if this is to disallow instantiating this class, t
alexilin 2016/10/21 16:04:19 No, this is for enabling default constructor expli
pasko 2016/10/21 16:47:34 Ah, oh, I did not know DISALLOW_COPY_AND_ASSIGN pr
+ virtual ~Observer() {}
pasko 2016/10/21 14:41:36 if the destructor is protected, then it becomes pr
alexilin 2016/10/21 16:04:19 Done.
private:
- ~GetUrlVisitCountTask() override;
-
- int visit_count_;
- NavigationID navigation_id_;
- std::unique_ptr<PageRequestSummary> summary_;
- VisitInfoCallback callback_;
+ DISALLOW_COPY_AND_ASSIGN(Observer);
+ };
- DISALLOW_COPY_AND_ASSIGN(GetUrlVisitCountTask);
+ enum InitializationState {
+ NOT_INITIALIZED = 0,
+ INITIALIZING = 1,
+ INITIALIZED = 2
};
typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap;
@@ -261,15 +256,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 +284,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
@@ -356,7 +341,15 @@ class ResourcePrefetchPredictor
tables_ = tables;
}
+ // Sets an |observer| to be notified when the resource prefetch predictor data
pasko 2016/10/21 14:41:36 s/an/the/ or: s/an//
alexilin 2016/10/21 16:04:19 Done.
+ // changes. Use only for testing.
pasko 2016/10/21 14:41:36 Better omit the "Use only for testing" comment bec
alexilin 2016/10/21 16:04:19 Done.
+ void SetObserverForTesting(Observer* observer);
+
+ // Removes |observer| from the observer list. Use only for testing.
+ void RemoveObserverForTesting(Observer* observer);
pasko 2016/10/21 14:41:36 providing the same observer for removal looks a li
alexilin 2016/10/21 16:04:19 Your statement is contradictory a little bit. You
pasko 2016/10/21 16:47:34 This scoped observer would be useful if we are sur
+
Profile* const profile_;
+ Observer* observer_;
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