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

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

Issue 22031002: Omnibox: Create DemoteByType Experiment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: come cleanup, getting proper function names, etc. 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_split.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "chrome/common/metrics/metrics_util.h" 14 #include "chrome/common/metrics/metrics_util.h"
14 #include "chrome/common/metrics/variations/variation_ids.h" 15 #include "chrome/common/metrics/variations/variation_ids.h"
15 #include "chrome/common/metrics/variations/variations_util.h" 16 #include "chrome/common/metrics/variations/variations_util.h"
16 17
17 namespace { 18 namespace {
18 19
19 // Field trial names. 20 // Field trial names.
20 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; 21 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects";
21 const char kHUPCreateShorterMatchFieldTrialName[] = 22 const char kHUPCreateShorterMatchFieldTrialName[] =
22 "OmniboxHUPCreateShorterMatch"; 23 "OmniboxHUPCreateShorterMatch";
23 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; 24 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer";
24 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; 25 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring";
25 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; 26 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1";
26 27
27 // Rule names used by the bundled experiment. 28 // Rule names used by the bundled experiment.
28 const char kSearchHistoryRule[] = "SearchHistory"; 29 const char kSearchHistoryRule[] = "SearchHistory";
30 const char kDemoteByTypeRule[] = "DemoteByType";
29 31
30 // The autocomplete dynamic field trial name prefix. Each field trial is 32 // The autocomplete dynamic field trial name prefix. Each field trial is
31 // configured dynamically and is retrieved automatically by Chrome during 33 // configured dynamically and is retrieved automatically by Chrome during
32 // the startup. 34 // the startup.
33 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; 35 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_";
34 // The maximum number of the autocomplete dynamic field trials (aka layers). 36 // The maximum number of the autocomplete dynamic field trials (aka layers).
35 const int kMaxAutocompleteDynamicFieldTrials = 5; 37 const int kMaxAutocompleteDynamicFieldTrials = 5;
36 38
37 // Field trial experiment probabilities. 39 // Field trial experiment probabilities.
38 40
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return OmniboxFieldTrial::GetValueForRuleInContext( 228 return OmniboxFieldTrial::GetValueForRuleInContext(
227 kSearchHistoryRule, current_page_classification) == "PreventInlining"; 229 kSearchHistoryRule, current_page_classification) == "PreventInlining";
228 } 230 }
229 231
230 bool OmniboxFieldTrial::SearchHistoryDisable( 232 bool OmniboxFieldTrial::SearchHistoryDisable(
231 AutocompleteInput::PageClassification current_page_classification) { 233 AutocompleteInput::PageClassification current_page_classification) {
232 return OmniboxFieldTrial::GetValueForRuleInContext( 234 return OmniboxFieldTrial::GetValueForRuleInContext(
233 kSearchHistoryRule, current_page_classification) == "Disable"; 235 kSearchHistoryRule, current_page_classification) == "Disable";
234 } 236 }
235 237
238 void OmniboxFieldTrial::GetDemotionsByType(
239 AutocompleteInput::PageClassification current_page_classification,
240 DemotionMultiplierByType* demotions_by_type) {
241 demotions_by_type->clear();
242 const std::string demotion_rule =
243 OmniboxFieldTrial::GetValueForRuleInContext(
244 kDemoteByTypeRule,
245 current_page_classification);
246 // The value of the DemoteByType rule is a comma-separated list of
247 // {ResultType + ":" + Number} where ResultType is an AutocompleteMatchType::
248 // Type enum represented as an integer and Number is an integer number
249 // between 0 and 100 inclusive. Relevance scores of matches of that result
250 // type are multiplied by Number / 100. 100 means no change.
251 std::vector<std::pair<std::string, std::string> > kv_pairs;
Peter Kasting 2013/08/06 19:33:50 Nit: This suggests that string_split.h should have
Mark P 2013/08/06 22:00:15 Done.
252 if (base::SplitStringIntoKeyValuePairs(demotion_rule, ':', ',', &kv_pairs)) {
253 for (size_t i = 0; i < kv_pairs.size(); ++i) {
254 // This is a best-effort conversion; we trust the hand-crafted parameters
255 // downloaded from the server to be perfect. There's no need for handle
256 // errors smartly.
257 int k, v;
258 base::StringToInt(kv_pairs[i].first, &k);
259 base::StringToInt(kv_pairs[i].second, &v);
260 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] =
261 static_cast<float>(v) / 100.0f;
262 }
263 }
264 }
265
236 // Background and implementation details: 266 // Background and implementation details:
237 // 267 //
238 // Each experiment group in any field trial can come with an optional set of 268 // Each experiment group in any field trial can come with an optional set of
239 // parameters (key-value pairs). In the bundled omnibox experiment 269 // parameters (key-value pairs). In the bundled omnibox experiment
240 // (kBundledExperimentFieldTrialName), each experiment group comes with a 270 // (kBundledExperimentFieldTrialName), each experiment group comes with a
241 // list of parameters in the form: 271 // list of parameters in the form:
242 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)> 272 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)>
243 // value=<arbitrary string> 273 // value=<arbitrary string>
244 // The AutocompleteInput::PageClassification can also be "*", which means 274 // The AutocompleteInput::PageClassification can also be "*", which means
245 // this rule applies in all page classification contexts. 275 // this rule applies in all page classification contexts.
(...skipping 18 matching lines...) Expand all
264 // Look up rule in this exact context. 294 // Look up rule in this exact context.
265 std::map<std::string, std::string>::iterator it = 295 std::map<std::string, std::string>::iterator it =
266 params.find(rule + ":" + base::IntToString( 296 params.find(rule + ":" + base::IntToString(
267 static_cast<int>(page_classification))); 297 static_cast<int>(page_classification)));
268 if (it != params.end()) 298 if (it != params.end())
269 return it->second; 299 return it->second;
270 // Look up rule in the global context. 300 // Look up rule in the global context.
271 it = params.find(rule + ":*"); 301 it = params.find(rule + ":*");
272 return (it != params.end()) ? it->second : std::string(); 302 return (it != params.end()) ? it->second : std::string();
273 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698