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

Unified Diff: chrome/browser/predictors/glowplug_config.cc

Issue 2847183002: predictors: Introduce GlowplugPredictor. (Closed)
Patch Set: Address comments. 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/glowplug_config.cc
diff --git a/chrome/browser/predictors/glowplug_config.cc b/chrome/browser/predictors/glowplug_config.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e8525349781c3546fbd4e5e68606b58b60fc1ac1
--- /dev/null
+++ b/chrome/browser/predictors/glowplug_config.cc
@@ -0,0 +1,82 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/predictors/glowplug_config.h"
+#include "chrome/browser/predictors/resource_prefetch_common.h"
+
+namespace predictors {
+
+bool IsGlowplugEnabled(Profile* profile, GlowplugPredictorConfig* config) {
+ return IsSpeculativeResourcePrefetchingEnabled(profile, config);
+}
+
+GlowplugPredictorConfig::GlowplugPredictorConfig()
+ : mode(0),
+ max_navigation_lifetime_seconds(60),
+ max_urls_to_track(500),
+ max_hosts_to_track(200),
+ min_url_visit_count(2),
+ max_resources_per_entry(50),
+ max_origins_per_entry(50),
+ max_consecutive_misses(3),
+ max_redirect_consecutive_misses(5),
+ min_resource_confidence_to_trigger_prefetch(0.7f),
+ min_resource_hits_to_trigger_prefetch(2),
+ max_prefetches_inflight_per_navigation(5),
+ max_prefetches_inflight_per_host_per_navigation(3),
+ is_url_learning_enabled(false),
+ is_manifests_enabled(false),
+ is_origin_learning_enabled(false) {}
+
+GlowplugPredictorConfig::GlowplugPredictorConfig(
+ const GlowplugPredictorConfig& other) = default;
+
+GlowplugPredictorConfig::~GlowplugPredictorConfig() = default;
+
+bool GlowplugPredictorConfig::IsLearningEnabled() const {
+ return (mode & LEARNING) > 0;
+}
+
+bool GlowplugPredictorConfig::IsPrefetchingEnabledForSomeOrigin(
+ Profile* profile) const {
+ int mask = PREFETCHING_FOR_NAVIGATION | PREFETCHING_FOR_EXTERNAL;
+ return internal::IsPrefetchingEnabledInternal(profile, mode, mask);
+}
+
+bool GlowplugPredictorConfig::IsPrefetchingEnabledForOrigin(
+ Profile* profile,
+ HintOrigin origin) const {
+ int mask = 0;
+ switch (origin) {
+ case HintOrigin::NAVIGATION:
+ mask = PREFETCHING_FOR_NAVIGATION;
+ break;
+ case HintOrigin::EXTERNAL:
+ mask = PREFETCHING_FOR_EXTERNAL;
+ break;
+ }
+ return internal::IsPrefetchingEnabledInternal(profile, mode, mask);
+}
+
+bool GlowplugPredictorConfig::IsLowConfidenceForTest() const {
+ return min_url_visit_count == 1 &&
+ std::abs(min_resource_confidence_to_trigger_prefetch - 0.5f) < 1e-6 &&
+ min_resource_hits_to_trigger_prefetch == 1;
+}
+
+bool GlowplugPredictorConfig::IsHighConfidenceForTest() const {
+ return min_url_visit_count == 3 &&
+ std::abs(min_resource_confidence_to_trigger_prefetch - 0.9f) < 1e-6 &&
+ min_resource_hits_to_trigger_prefetch == 3;
+}
+
+bool GlowplugPredictorConfig::IsMoreResourcesEnabledForTest() const {
+ return max_resources_per_entry == 100;
+}
+
+bool GlowplugPredictorConfig::IsSmallDBEnabledForTest() const {
+ return max_urls_to_track == 200 && max_hosts_to_track == 100;
+}
+
+} // namespace predictors

Powered by Google App Engine
This is Rietveld 408576698