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

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

Issue 2887133003: predictors: Refactor resource_prefetch_predictor triggering. (Closed)
Patch Set: . Created 3 years, 7 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
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 2cd3c950895ace6aabeb4aa0cf8d2067fa9263e0..38d2d0765b7c99d4216ccb7b1597bb13c119cb3d 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.h
+++ b/chrome/browser/predictors/resource_prefetch_predictor.h
@@ -23,6 +23,7 @@
#include "chrome/browser/predictors/resource_prefetch_common.h"
#include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
#include "chrome/browser/predictors/resource_prefetcher.h"
+#include "chrome/browser/predictors/resource_prefetcher_manager.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h"
@@ -244,7 +245,7 @@ class ResourcePrefetchPredictor
std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats);
// Returns true if prefetching data exists for the |main_frame_url|.
- virtual bool IsUrlPrefetchable(const GURL& main_frame_url);
+ virtual bool IsUrlPrefetchable(const GURL& main_frame_url) const;
// Returns true iff |resource| has sufficient confidence level and required
// number of hits.
@@ -260,6 +261,10 @@ class ResourcePrefetchPredictor
void SetObserverForTesting(TestObserver* observer);
private:
+ // Return whether the predictor has data about a URL and can prefetch it
+ // for a given origin with the current configuration.
+ bool CanPrefetchUrlForOrigin(const GURL& url, HintOrigin origin) const;
+
// Starts prefetching if it is enabled for |origin| 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, HintOrigin origin);
@@ -309,6 +314,8 @@ class ResourcePrefetchPredictor
TestPrefetchingDurationHistogram);
FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest,
TestRecordFirstContentfulPaint);
+ FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest,
+ TestCanPrefetchUrlForOrigin);
enum InitializationState {
NOT_INITIALIZED = 0,
@@ -473,6 +480,12 @@ class ResourcePrefetchPredictor
tables_ = tables;
}
+ // For testing.
+ void set_mock_resource_prefetcher_manager(
+ scoped_refptr<ResourcePrefetcherManager> prefetch_manager) {
+ prefetch_manager_ = prefetch_manager;
+ }
+
Profile* const profile_;
TestObserver* observer_;
const LoadingPredictorConfig config_;

Powered by Google App Engine
This is Rietveld 408576698