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>: |
| 275 // <AutocompleteInput::PageClassification (as an int)>: |
| 276 // <whether Instant Extended is enabled (as a 1 or 0)> |
| 277 // (note that there are no linebreaks in keys; this format is for |
| 278 // presentation only> |
274 // value=<arbitrary string> | 279 // value=<arbitrary string> |
275 // The AutocompleteInput::PageClassification can also be "*", which means | 280 // Both the AutocompleteInput::PageClassification and the Instant Extended |
276 // this rule applies in all page classification contexts. | 281 // entries can be "*", which means this rule applies for all values of the |
| 282 // matching portion of the context. |
277 // One example parameter is | 283 // One example parameter is |
278 // key=SearchHistory:6 | 284 // key=SearchHistory:6:1 |
279 // value=PreventInlining | 285 // value=PreventInlining |
280 // This means in page classification context 6 (a search result page doing | 286 // This means in page classification context 6 (a search result page doing |
281 // search term replacement), the SearchHistory experiment should | 287 // search term replacement) with Instant Extended enabled, the SearchHistory |
282 // PreventInlining. | 288 // experiment should PreventInlining. |
| 289 // |
| 290 // When an exact match to the rule in the current context is missing, we |
| 291 // give preference to a wildcard rule that matches the instant extended |
| 292 // context over a wildcard rule that matches the page classification |
| 293 // context. Hopefully, though, users will write their field trial configs |
| 294 // so as not to rely on this fall back order. |
283 // | 295 // |
284 // In short, this function tries to find the value associated with key | 296 // In short, this function tries to find the value associated with key |
285 // |rule|:|page_classification|, failing that it looks up |rule|:*, | 297 // |rule|:|page_classification|:|instant_extended|, failing that it looks up |
| 298 // |rule|:*:|instant_extended|, failing that it looks up |
| 299 // |rule|:|page_classification|:*, failing that it looks up |rule|:*:*, |
286 // and failing that it returns the empty string. | 300 // and failing that it returns the empty string. |
287 std::string OmniboxFieldTrial::GetValueForRuleInContext( | 301 std::string OmniboxFieldTrial::GetValueForRuleInContext( |
288 const std::string& rule, | 302 const std::string& rule, |
289 AutocompleteInput::PageClassification page_classification) { | 303 AutocompleteInput::PageClassification page_classification) { |
290 std::map<std::string, std::string> params; | 304 std::map<std::string, std::string> params; |
291 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, | 305 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, |
292 ¶ms)) { | 306 ¶ms)) { |
293 return std::string(); | 307 return std::string(); |
294 } | 308 } |
| 309 const std::string page_classification_str = |
| 310 base::IntToString(static_cast<int>(page_classification)); |
| 311 const std::string instant_extended = |
| 312 chrome::IsInstantExtendedAPIEnabled() ? "1" : "0"; |
295 // Look up rule in this exact context. | 313 // Look up rule in this exact context. |
296 std::map<std::string, std::string>::iterator it = | 314 std::map<std::string, std::string>::iterator it = params.find( |
297 params.find(rule + ":" + base::IntToString( | 315 rule + ":" + page_classification_str + ":" + instant_extended); |
298 static_cast<int>(page_classification))); | 316 if (it != params.end()) |
| 317 return it->second; |
| 318 // Fall back to the global page classification context. |
| 319 it = params.find(rule + ":*:" + instant_extended); |
| 320 if (it != params.end()) |
| 321 return it->second; |
| 322 // Fall back to the global instant extended context. |
| 323 it = params.find(rule + ":" + page_classification_str + ":*"); |
299 if (it != params.end()) | 324 if (it != params.end()) |
300 return it->second; | 325 return it->second; |
301 // Look up rule in the global context. | 326 // Look up rule in the global context. |
302 it = params.find(rule + ":*"); | 327 it = params.find(rule + ":*:*"); |
303 return (it != params.end()) ? it->second : std::string(); | 328 return (it != params.end()) ? it->second : std::string(); |
304 } | 329 } |
OLD | NEW |