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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_common.cc

Issue 2815103002: predictors: Enable origin learning with a flag. (Closed)
Patch Set: . Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/predictors/resource_prefetch_common.h" 5 #include "chrome/browser/predictors/resource_prefetch_common.h"
6 6
7 #include <string> 7 #include <string>
8 #include <tuple> 8 #include <tuple>
9 9
10 #include "base/metrics/field_trial_params.h" 10 #include "base/metrics/field_trial_params.h"
11 #include "chrome/browser/net/prediction_options.h" 11 #include "chrome/browser/net/prediction_options.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/sessions/session_tab_helper.h" 13 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "components/prefs/pref_service.h" 14 #include "components/prefs/pref_service.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 17
18 namespace predictors { 18 namespace predictors {
19 19
20 const char kSpeculativeResourcePrefetchingFeatureName[] = 20 const char kSpeculativeResourcePrefetchingFeatureName[] =
21 "SpeculativeResourcePrefetching"; 21 "SpeculativeResourcePrefetching";
22 const char kModeParamName[] = "mode"; 22 const char kModeParamName[] = "mode";
23 const char kLearningMode[] = "learning"; 23 const char kLearningMode[] = "learning";
24 const char kExternalPrefetchingMode[] = "external-prefetching"; 24 const char kExternalPrefetchingMode[] = "external-prefetching";
25 const char kPrefetchingMode[] = "prefetching"; 25 const char kPrefetchingMode[] = "prefetching";
26 const char kEnableUrlLearningParamName[] = "enable-url-learning"; 26 const char kEnableUrlLearningParamName[] = "enable-url-learning";
27 const char kEnableManifestsParamName[] = "enable-manifests"; 27 const char kEnableManifestsParamName[] = "enable-manifests";
28 const char kEnableOriginLearningParamName[] = "enable-origin-learning";
28 29
29 const base::Feature kSpeculativeResourcePrefetchingFeature = 30 const base::Feature kSpeculativeResourcePrefetchingFeature =
30 base::Feature(kSpeculativeResourcePrefetchingFeatureName, 31 base::Feature(kSpeculativeResourcePrefetchingFeatureName,
31 base::FEATURE_DISABLED_BY_DEFAULT); 32 base::FEATURE_DISABLED_BY_DEFAULT);
32 33
33 namespace { 34 namespace {
34 35
35 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { 36 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) {
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
37 if ((mode & mask) == 0) 38 if ((mode & mask) == 0)
(...skipping 26 matching lines...) Expand all
64 base::GetFieldTrialParamValueByFeature( 65 base::GetFieldTrialParamValueByFeature(
65 kSpeculativeResourcePrefetchingFeature, kEnableUrlLearningParamName); 66 kSpeculativeResourcePrefetchingFeature, kEnableUrlLearningParamName);
66 if (enable_url_learning_value == "true") 67 if (enable_url_learning_value == "true")
67 config->is_url_learning_enabled = true; 68 config->is_url_learning_enabled = true;
68 69
69 std::string enable_manifests_value = base::GetFieldTrialParamValueByFeature( 70 std::string enable_manifests_value = base::GetFieldTrialParamValueByFeature(
70 kSpeculativeResourcePrefetchingFeature, kEnableManifestsParamName); 71 kSpeculativeResourcePrefetchingFeature, kEnableManifestsParamName);
71 if (enable_manifests_value == "true") 72 if (enable_manifests_value == "true")
72 config->is_manifests_enabled = true; 73 config->is_manifests_enabled = true;
73 74
75 bool enable_origin_learning = base::GetFieldTrialParamValueByFeature(
76 kSpeculativeResourcePrefetchingFeature,
77 kEnableOriginLearningParamName) == "true";
78 config->is_origin_learning_enabled = enable_origin_learning;
79
74 // Ensure that a resource that was only seen once is never prefetched. This 80 // Ensure that a resource that was only seen once is never prefetched. This
75 // prevents the easy mistake of trying to prefetch an ephemeral url. 81 // prevents the easy mistake of trying to prefetch an ephemeral url.
76 DCHECK_GT(config->min_resource_hits_to_trigger_prefetch, 1U); 82 DCHECK_GT(config->min_resource_hits_to_trigger_prefetch, 1U);
77 if (config->min_resource_hits_to_trigger_prefetch < 2) 83 if (config->min_resource_hits_to_trigger_prefetch < 2)
78 config->min_resource_hits_to_trigger_prefetch = 2; 84 config->min_resource_hits_to_trigger_prefetch = 2;
79 85
80 std::string mode_value = base::GetFieldTrialParamValueByFeature( 86 std::string mode_value = base::GetFieldTrialParamValueByFeature(
81 kSpeculativeResourcePrefetchingFeature, kModeParamName); 87 kSpeculativeResourcePrefetchingFeature, kModeParamName);
82 if (mode_value == kLearningMode) { 88 if (mode_value == kLearningMode) {
83 config->mode |= ResourcePrefetchPredictorConfig::LEARNING; 89 config->mode |= ResourcePrefetchPredictorConfig::LEARNING;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 min_url_visit_count(2), 144 min_url_visit_count(2),
139 max_resources_per_entry(50), 145 max_resources_per_entry(50),
140 max_origins_per_entry(50), 146 max_origins_per_entry(50),
141 max_consecutive_misses(3), 147 max_consecutive_misses(3),
142 min_resource_confidence_to_trigger_prefetch(0.7f), 148 min_resource_confidence_to_trigger_prefetch(0.7f),
143 min_resource_hits_to_trigger_prefetch(2), 149 min_resource_hits_to_trigger_prefetch(2),
144 max_prefetches_inflight_per_navigation(5), 150 max_prefetches_inflight_per_navigation(5),
145 max_prefetches_inflight_per_host_per_navigation(3), 151 max_prefetches_inflight_per_host_per_navigation(3),
146 is_url_learning_enabled(false), 152 is_url_learning_enabled(false),
147 is_manifests_enabled(false), 153 is_manifests_enabled(false),
148 is_origin_prediction_enabled(false) {} 154 is_origin_learning_enabled(false) {}
149 155
150 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( 156 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig(
151 const ResourcePrefetchPredictorConfig& other) = default; 157 const ResourcePrefetchPredictorConfig& other) = default;
152 158
153 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { 159 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() {
154 } 160 }
155 161
156 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { 162 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const {
157 return (mode & LEARNING) > 0; 163 return (mode & LEARNING) > 0;
158 } 164 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 198
193 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { 199 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const {
194 return max_resources_per_entry == 100; 200 return max_resources_per_entry == 100;
195 } 201 }
196 202
197 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { 203 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const {
198 return max_urls_to_track == 200 && max_hosts_to_track == 100; 204 return max_urls_to_track == 200 && max_hosts_to_track == 100;
199 } 205 }
200 206
201 } // namespace predictors 207 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_common.h ('k') | chrome/browser/predictors/resource_prefetch_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698