Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/search/search.h" | |
| 14 #include "chrome/common/metrics/metrics_util.h" | 15 #include "chrome/common/metrics/metrics_util.h" |
| 15 #include "chrome/common/metrics/variations/variation_ids.h" | 16 #include "chrome/common/metrics/variations/variation_ids.h" |
| 16 #include "chrome/common/metrics/variations/variations_util.h" | 17 #include "chrome/common/metrics/variations/variations_util.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Field trial names. | 21 // Field trial names. |
| 21 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; | 22 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; |
| 22 const char kHUPCreateShorterMatchFieldTrialName[] = | 23 const char kHUPCreateShorterMatchFieldTrialName[] = |
| 23 "OmniboxHUPCreateShorterMatch"; | 24 "OmniboxHUPCreateShorterMatch"; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 } | 264 } |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 // Background and implementation details: | 268 // Background and implementation details: |
| 268 // | 269 // |
| 269 // Each experiment group in any field trial can come with an optional set of | 270 // Each experiment group in any field trial can come with an optional set of |
| 270 // parameters (key-value pairs). In the bundled omnibox experiment | 271 // parameters (key-value pairs). In the bundled omnibox experiment |
| 271 // (kBundledExperimentFieldTrialName), each experiment group comes with a | 272 // (kBundledExperimentFieldTrialName), each experiment group comes with a |
| 272 // list of parameters in the form: | 273 // list of parameters in the form: |
| 273 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)> | 274 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)>:<whether |
|
Peter Kasting
2013/08/09 20:45:45
Nit: Consider breaking after each colon for readab
Mark P
2013/08/09 21:55:01
Nice idea: it makes the elements more readable and
| |
| 275 // InstantExtended is enabled (as a 1 or 0)> | |
| 274 // value=<arbitrary string> | 276 // value=<arbitrary string> |
| 275 // The AutocompleteInput::PageClassification can also be "*", which means | 277 // Both the AutocompleteInput::PageClassification and the InstantExtended |
| 276 // this rule applies in all page classification contexts. | 278 // entires can be "*", which means this rule applies regardless of relevant |
| 279 // context. | |
|
Peter Kasting
2013/08/09 20:45:45
Nit: regardless of relevant context -> for all val
Mark P
2013/08/09 21:55:01
Sure. I spent some time trying to choose these wo
| |
| 277 // One example parameter is | 280 // One example parameter is |
| 278 // key=SearchHistory:6 | 281 // key=SearchHistory:6:1 |
| 279 // value=PreventInlining | 282 // value=PreventInlining |
| 280 // This means in page classification context 6 (a search result page doing | 283 // This means in page classification context 6 (a search result page doing |
| 281 // search term replacement), the SearchHistory experiment should | 284 // search term replacement) with InstantExtended enabled, the SearchHistory |
| 282 // PreventInlining. | 285 // experiment should PreventInlining. |
| 286 // | |
| 287 // When an exact match to the rule in the current context is missing, we | |
| 288 // give preference to a wildcard rule that matches the instant extended | |
| 289 // context over a wildcard rule that matches the page classification | |
| 290 // context. Hopefully, though, users will write their field trial configs | |
| 291 // so as not to rely on this backoff order. | |
| 283 // | 292 // |
| 284 // In short, this function tries to find the value associated with key | 293 // In short, this function tries to find the value associated with key |
| 285 // |rule|:|page_classification|, failing that it looks up |rule|:*, | 294 // |rule|:|page_classification|:|instant_extended|, failing that it looks up |
| 295 // |rule|:*:|instant_extended|, failing that it looks up | |
| 296 // |rule|:|page_classification|:*, failing that it looks up |rule|:*:*, | |
| 286 // and failing that it returns the empty string. | 297 // and failing that it returns the empty string. |
| 287 std::string OmniboxFieldTrial::GetValueForRuleInContext( | 298 std::string OmniboxFieldTrial::GetValueForRuleInContext( |
| 288 const std::string& rule, | 299 const std::string& rule, |
| 289 AutocompleteInput::PageClassification page_classification) { | 300 AutocompleteInput::PageClassification page_classification) { |
| 290 std::map<std::string, std::string> params; | 301 std::map<std::string, std::string> params; |
| 291 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, | 302 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, |
| 292 ¶ms)) { | 303 ¶ms)) { |
| 293 return std::string(); | 304 return std::string(); |
| 294 } | 305 } |
| 306 const std::string page_classification_str = | |
| 307 base::IntToString(static_cast<int>(page_classification)); | |
| 308 const std::string instant_extended = | |
| 309 chrome::IsInstantExtendedAPIEnabled() ? "1" : "0"; | |
| 295 // Look up rule in this exact context. | 310 // Look up rule in this exact context. |
| 296 std::map<std::string, std::string>::iterator it = | 311 std::map<std::string, std::string>::iterator it = params.find( |
| 297 params.find(rule + ":" + base::IntToString( | 312 rule + ":" + page_classification_str + ":" + instant_extended); |
| 298 static_cast<int>(page_classification))); | 313 if (it != params.end()) |
| 314 return it->second; | |
| 315 // Backoff to the global page classification context. | |
|
Peter Kasting
2013/08/09 20:45:45
Nit: Backoff -> Fall back (2 places)
Mark P
2013/08/09 21:55:01
Done.
| |
| 316 it = params.find(rule + ":*:" + instant_extended); | |
| 317 if (it != params.end()) | |
| 318 return it->second; | |
| 319 // Backoff to the global instant extended context. | |
| 320 it = params.find(rule + ":" + page_classification_str + ":*"); | |
| 299 if (it != params.end()) | 321 if (it != params.end()) |
| 300 return it->second; | 322 return it->second; |
| 301 // Look up rule in the global context. | 323 // Look up rule in the global context. |
| 302 it = params.find(rule + ":*"); | 324 it = params.find(rule + ":*:*"); |
| 303 return (it != params.end()) ? it->second : std::string(); | 325 return (it != params.end()) ? it->second : std::string(); |
| 304 } | 326 } |
| OLD | NEW |