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

Side by Side Diff: chrome/browser/omnibox/omnibox_field_trial.cc

Issue 20777006: Omnibox: Create Bundled Field Trial; Convert SearchHistory trial to it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Alexei's spacing suggestion Created 7 years, 4 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 | Annotate | Revision Log
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/omnibox/omnibox_field_trial.h" 5 #include "chrome/browser/omnibox/omnibox_field_trial.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/common/metrics/metrics_util.h" 13 #include "chrome/common/metrics/metrics_util.h"
14 #include "chrome/common/metrics/variations/variation_ids.h" 14 #include "chrome/common/metrics/variations/variation_ids.h"
15 #include "chrome/common/metrics/variations/variations_util.h" 15 #include "chrome/common/metrics/variations/variations_util.h"
16 16
17 namespace { 17 namespace {
18 18
19 // Field trial names. 19 // Field trial names.
20 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; 20 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects";
21 const char kHUPCreateShorterMatchFieldTrialName[] = 21 const char kHUPCreateShorterMatchFieldTrialName[] =
22 "OmniboxHUPCreateShorterMatch"; 22 "OmniboxHUPCreateShorterMatch";
23 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; 23 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer";
24 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; 24 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring";
25 const char kSearchHistoryFieldTrialName[] = "OmniboxSearchHistory"; 25 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1";
26
27 // Rule names used by the bundled experiment.
28 const char kSearchHistoryRule[] = "SearchHistory";
26 29
27 // The autocomplete dynamic field trial name prefix. Each field trial is 30 // The autocomplete dynamic field trial name prefix. Each field trial is
28 // configured dynamically and is retrieved automatically by Chrome during 31 // configured dynamically and is retrieved automatically by Chrome during
29 // the startup. 32 // the startup.
30 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; 33 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_";
31 // The maximum number of the autocomplete dynamic field trials (aka layers). 34 // The maximum number of the autocomplete dynamic field trials (aka layers).
32 const int kMaxAutocompleteDynamicFieldTrials = 5; 35 const int kMaxAutocompleteDynamicFieldTrials = 5;
33 36
34 // Field trial experiment probabilities. 37 // Field trial experiment probabilities.
35 38
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return false; 214 return false;
212 if (!base::StringToInt(base::StringPiece( 215 if (!base::StringToInt(base::StringPiece(
213 group_name.substr(strlen(kMaxRelevanceGroupPrefix))), 216 group_name.substr(strlen(kMaxRelevanceGroupPrefix))),
214 max_relevance)) { 217 max_relevance)) {
215 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name; 218 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name;
216 return false; 219 return false;
217 } 220 }
218 return true; 221 return true;
219 } 222 }
220 223
221 bool OmniboxFieldTrial::SearchHistoryPreventInlining() { 224 bool OmniboxFieldTrial::SearchHistoryPreventInlining(
222 return (base::FieldTrialList::FindFullName(kSearchHistoryFieldTrialName) == 225 AutocompleteInput::PageClassification current_page_classification) {
223 "PreventInlining"); 226 return OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext(
227 kSearchHistoryRule, current_page_classification) == "PreventInlining";
224 } 228 }
225 229
226 bool OmniboxFieldTrial::SearchHistoryDisable() { 230 bool OmniboxFieldTrial::SearchHistoryDisable(
227 return (base::FieldTrialList::FindFullName(kSearchHistoryFieldTrialName) == 231 AutocompleteInput::PageClassification current_page_classification) {
228 "Disable"); 232 return OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext(
233 kSearchHistoryRule, current_page_classification) == "Disable";
229 } 234 }
235
236 // Background and implementation details:
Peter Kasting 2013/08/01 22:44:48 Honestly, I still think this comment, as-is, is cl
Mark P 2013/08/02 00:44:36 Added a new opening paragraph to the .h that impor
237 //
238 // Each experiment group in any field trial can come with an optional set of
239 // parameters (key-value pairs). In the bundled omnibox experiment
240 // (kBundledExperimentFieldTrialName), each experiment group comes with a
241 // list of parameters in the form:
242 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)>
243 // value=<arbitrary string>
244 // The AutocompleteInput::PageClassification can also be "*", which means
245 // this rule applies in all contexts.
Peter Kasting 2013/08/01 22:44:48 Nit: "in all contexts" -> "for all classifications
Mark P 2013/08/02 00:44:36 see other comment about context.
246 // One example parameter is
247 // key=SearchHistory:6
248 // value=PreventInlining
249 // This means in context 6 (a search result page doing search term replacement),
250 // the SearchHistory experiment should PreventInlining.
251 //
252 // In short, this function tries to find the value associated with key
253 // |rule|:|current_page_classification|, failing that it looks up |rule|:*,
254 // and failing that it returns the empty string.
255 std::string OmniboxFieldTrial::GetValueOfRuleInPageClassificationContext(
256 const std::string& rule,
257 AutocompleteInput::PageClassification current_page_classification) {
258 std::map<std::string, std::string> params;
259 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName,
260 &params)) {
261 return std::string();
262 }
263 // Look up rule in this exact context.
Peter Kasting 2013/08/01 22:44:48 Nit: "in this exact context" -> "for the provided
Mark P 2013/08/02 00:44:36 see other comment about context.
264 std::map<std::string, std::string>::iterator it =
265 params.find(rule + ":" + base::IntToString(
266 static_cast<int>(current_page_classification)));
267 if (it != params.end())
268 return it->second;
269 // Look up rule in the global context.
Peter Kasting 2013/08/01 22:44:48 Nit: Maybe "See if we have a fallback rule for all
Mark P 2013/08/02 00:44:36 see other comment about context.
270 it = params.find(rule + ":*");
271 return (it != params.end()) ? it->second : std::string();
272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698