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

Side by Side Diff: chrome/browser/prerender/prerender_field_trial.cc

Issue 10752006: Adding a field trial to enable speculative resource prefetching learning. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prerender/prerender_field_trial.h" 5 #include "chrome/browser/prerender/prerender_field_trial.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "chrome/browser/metrics/metrics_service.h" 11 #include "chrome/browser/metrics/metrics_service.h"
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prerender/prerender_manager.h" 14 #include "chrome/browser/prerender/prerender_manager.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/chrome_version_info.h" 17 #include "chrome/common/chrome_version_info.h"
18 18
19 namespace prerender { 19 namespace prerender {
20 20
21 namespace { 21 namespace {
22 22
23 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; 23 const char kOmniboxTrialName[] = "PrerenderFromOmnibox";
24 int g_omnibox_trial_default_group_number = -1; 24 int g_omnibox_trial_default_group_number = -1;
25 25
26 const char kSpeculativePrefetchingLearningTrialName[] =
27 "SpeculativePrefetchingLearning";
28 int g_speculative_prfetching_learning_default_group_number = -1;
dominich 2012/07/09 20:57:23 typo: prefetching
Shishir 2012/07/09 21:02:01 Done.
29
26 void SetupPrefetchFieldTrial() { 30 void SetupPrefetchFieldTrial() {
27 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 31 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
28 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 32 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
29 channel == chrome::VersionInfo::CHANNEL_BETA) { 33 channel == chrome::VersionInfo::CHANNEL_BETA) {
30 return; 34 return;
31 } 35 }
32 36
33 const base::FieldTrial::Probability divisor = 1000; 37 const base::FieldTrial::Probability divisor = 1000;
34 const base::FieldTrial::Probability prefetch_probability = 500; 38 const base::FieldTrial::Probability prefetch_probability = 500;
35 scoped_refptr<base::FieldTrial> trial( 39 scoped_refptr<base::FieldTrial> trial(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 PrerenderManager::SetMode( 119 PrerenderManager::SetMode(
116 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); 120 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP);
117 } else { 121 } else {
118 NOTREACHED(); 122 NOTREACHED();
119 } 123 }
120 } 124 }
121 125
122 } // end namespace 126 } // end namespace
123 127
124 void ConfigureOmniboxPrerender(); 128 void ConfigureOmniboxPrerender();
125 129
dominich 2012/07/09 20:57:23 nit: remove blank line
Shishir 2012/07/09 21:02:01 Done.
130 void ConfigureSpeculativePrefetching();
131
126 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { 132 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) {
127 enum PrerenderOption { 133 enum PrerenderOption {
128 PRERENDER_OPTION_AUTO, 134 PRERENDER_OPTION_AUTO,
129 PRERENDER_OPTION_DISABLED, 135 PRERENDER_OPTION_DISABLED,
130 PRERENDER_OPTION_ENABLED, 136 PRERENDER_OPTION_ENABLED,
131 PRERENDER_OPTION_PREFETCH_ONLY, 137 PRERENDER_OPTION_PREFETCH_ONLY,
132 }; 138 };
133 139
134 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; 140 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO;
135 if (command_line.HasSwitch(switches::kPrerenderMode)) { 141 if (command_line.HasSwitch(switches::kPrerenderMode)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 break; 181 break;
176 default: 182 default:
177 NOTREACHED(); 183 NOTREACHED();
178 } 184 }
179 185
180 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", 186 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions",
181 PrerenderManager::GetMode(), 187 PrerenderManager::GetMode(),
182 PrerenderManager::PRERENDER_MODE_MAX); 188 PrerenderManager::PRERENDER_MODE_MAX);
183 189
184 ConfigureOmniboxPrerender(); 190 ConfigureOmniboxPrerender();
191 ConfigureSpeculativePrefetching();
185 } 192 }
186 193
187 void ConfigureOmniboxPrerender() { 194 void ConfigureOmniboxPrerender() {
188 // Field trial to see if we're enabled. 195 // Field trial to see if we're enabled.
189 const base::FieldTrial::Probability kDivisor = 100; 196 const base::FieldTrial::Probability kDivisor = 100;
190 197
191 base::FieldTrial::Probability kDisabledProbability = 10; 198 base::FieldTrial::Probability kDisabledProbability = 10;
192 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 199 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
193 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 200 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
194 channel == chrome::VersionInfo::CHANNEL_BETA) { 201 channel == chrome::VersionInfo::CHANNEL_BETA) {
(...skipping 28 matching lines...) Expand all
223 return false; 230 return false;
224 231
225 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); 232 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto);
226 } 233 }
227 234
228 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName); 235 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName);
229 return group == base::FieldTrial::kNotFinalized || 236 return group == base::FieldTrial::kNotFinalized ||
230 group == g_omnibox_trial_default_group_number; 237 group == g_omnibox_trial_default_group_number;
231 } 238 }
232 239
240 void ConfigureSpeculativePrefetching() {
241 // Field trial to see if we're enabled.
242 const base::FieldTrial::Probability kDivisor = 100;
243
244 base::FieldTrial::Probability kDisabledProbability = 99;
245 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
246 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
247 channel == chrome::VersionInfo::CHANNEL_BETA) {
248 kDisabledProbability = 100;
249 }
250 scoped_refptr<base::FieldTrial> speculative_prefetching_learning_trial(
251 base::FieldTrialList::FactoryGetFieldTrial(
252 kSpeculativePrefetchingLearningTrialName,
253 kDivisor,
254 "SpeculativePrefetchingLearningEnabled",
255 2012, 12, 30,
256 &g_speculative_prfetching_learning_default_group_number));
257 speculative_prefetching_learning_trial->AppendGroup(
258 "SpeculativePrefetchingDisabled",
259 kDisabledProbability);
260 }
261
262 bool IsSpeculativeResourcePrefetchingLearningEnabled(Profile* profile) {
263 if (!profile)
264 return false;
265
266 // Override any field trial groups if the user has set a command line flag.
267 if (CommandLine::ForCurrentProcess()->HasSwitch(
268 switches::kSpeculativeResourcePrefetching)) {
269 const std::string switch_value =
270 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
271 switches::kSpeculativeResourcePrefetching);
272
273 if (switch_value == switches::kSpeculativeResourcePrefetchingLearning)
274 return true;
275 }
276
277 const int group = base::FieldTrialList::FindValue(
278 kSpeculativePrefetchingLearningTrialName);
279 return group == g_speculative_prfetching_learning_default_group_number;
280 }
281
233 } // namespace prerender 282 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698