| 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" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 if (!base::StringToInt(base::StringPiece( | 215 if (!base::StringToInt(base::StringPiece( |
| 216 group_name.substr(strlen(kMaxRelevanceGroupPrefix))), | 216 group_name.substr(strlen(kMaxRelevanceGroupPrefix))), |
| 217 max_relevance)) { | 217 max_relevance)) { |
| 218 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name; | 218 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name; |
| 219 return false; | 219 return false; |
| 220 } | 220 } |
| 221 return true; | 221 return true; |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool OmniboxFieldTrial::SearchHistoryPreventInlining( | 224 bool OmniboxFieldTrial::SearchHistoryPreventInlining( |
| 225 AutocompleteInput::PageClassification current_page_classification) { | 225 AutocompleteInput::OmniboxContext omnibox_context) { |
| 226 return OmniboxFieldTrial::GetValueForRuleInContext( | 226 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 227 kSearchHistoryRule, current_page_classification) == "PreventInlining"; | 227 kSearchHistoryRule, omnibox_context) == "PreventInlining"; |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool OmniboxFieldTrial::SearchHistoryDisable( | 230 bool OmniboxFieldTrial::SearchHistoryDisable( |
| 231 AutocompleteInput::PageClassification current_page_classification) { | 231 AutocompleteInput::OmniboxContext omnibox_context) { |
| 232 return OmniboxFieldTrial::GetValueForRuleInContext( | 232 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 233 kSearchHistoryRule, current_page_classification) == "Disable"; | 233 kSearchHistoryRule, omnibox_context) == "Disable"; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Background and implementation details: | 236 // Background and implementation details: |
| 237 // | 237 // |
| 238 // Each experiment group in any field trial can come with an optional set of | 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 | 239 // parameters (key-value pairs). In the bundled omnibox experiment |
| 240 // (kBundledExperimentFieldTrialName), each experiment group comes with a | 240 // (kBundledExperimentFieldTrialName), each experiment group comes with a |
| 241 // list of parameters in the form: | 241 // list of parameters in the form: |
| 242 // key=<Rule>:<AutocompleteInput::PageClassification (as an int)> | 242 // key=<Rule>:<AutocompleteInput::OmniboxContext (as an int)> |
| 243 // value=<arbitrary string> | 243 // value=<arbitrary string> |
| 244 // The AutocompleteInput::PageClassification can also be "*", which means | 244 // The AutocompleteInput::OmniboxContext can also be "*", which means |
| 245 // this rule applies in all page classification contexts. | 245 // this rule applies in all page classification contexts. |
| 246 // One example parameter is | 246 // One example parameter is |
| 247 // key=SearchHistory:6 | 247 // key=SearchHistory:6 |
| 248 // value=PreventInlining | 248 // value=PreventInlining |
| 249 // This means in page classification context 6 (a search result page doing | 249 // This means in page classification context 6 (a search result page doing |
| 250 // search term replacement), the SearchHistory experiment should | 250 // search term replacement), the SearchHistory experiment should |
| 251 // PreventInlining. | 251 // PreventInlining. |
| 252 // | 252 // |
| 253 // In short, this function tries to find the value associated with key | 253 // In short, this function tries to find the value associated with key |
| 254 // |rule|:|page_classification|, failing that it looks up |rule|:*, | 254 // |rule|:|omnibox_context|, failing that it looks up |rule|:*, |
| 255 // and failing that it returns the empty string. | 255 // and failing that it returns the empty string. |
| 256 std::string OmniboxFieldTrial::GetValueForRuleInContext( | 256 std::string OmniboxFieldTrial::GetValueForRuleInContext( |
| 257 const std::string& rule, | 257 const std::string& rule, |
| 258 AutocompleteInput::PageClassification page_classification) { | 258 AutocompleteInput::OmniboxContext omnibox_context) { |
| 259 std::map<std::string, std::string> params; | 259 std::map<std::string, std::string> params; |
| 260 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, | 260 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, |
| 261 ¶ms)) { | 261 ¶ms)) { |
| 262 return std::string(); | 262 return std::string(); |
| 263 } | 263 } |
| 264 // Look up rule in this exact context. | 264 // Look up rule in this exact context. |
| 265 std::map<std::string, std::string>::iterator it = | 265 std::map<std::string, std::string>::iterator it = |
| 266 params.find(rule + ":" + base::IntToString( | 266 params.find(rule + ":" + base::IntToString( |
| 267 static_cast<int>(page_classification))); | 267 static_cast<int>(omnibox_context))); |
| 268 if (it != params.end()) | 268 if (it != params.end()) |
| 269 return it->second; | 269 return it->second; |
| 270 // Look up rule in the global context. | 270 // Look up rule in the global context. |
| 271 it = params.find(rule + ":*"); | 271 it = params.find(rule + ":*"); |
| 272 return (it != params.end()) ? it->second : std::string(); | 272 return (it != params.end()) ? it->second : std::string(); |
| 273 } | 273 } |
| OLD | NEW |