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" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 // errors smartly. | 258 // errors smartly. |
| 259 int k, v; | 259 int k, v; |
| 260 base::StringToInt(it->first, &k); | 260 base::StringToInt(it->first, &k); |
| 261 base::StringToInt(it->second, &v); | 261 base::StringToInt(it->second, &v); |
| 262 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = | 262 (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = |
| 263 static_cast<float>(v) / 100.0f; | 263 static_cast<float>(v) / 100.0f; |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void OmniboxFieldTrial::GetUndemotableTopTypes( | |
| 269 AutocompleteInput::PageClassification current_page_classification, | |
| 270 UndemotableTopMatchTypes* undemotable_types) { | |
| 271 undemotable_types->clear(); | |
| 272 const std::string types_rule = | |
| 273 OmniboxFieldTrial::GetValueForRuleInContext( | |
| 274 kUndemotableTopTypeRule, | |
| 275 current_page_classification); | |
| 276 // The value of the UndemotableTopTypes rule is a comma-separated list of | |
| 277 // AutocompleteMatchType::Type enums represented as an integer. | |
|
Mark P
2013/11/04 20:30:12
Perhaps add something about demotion scores (refer
H Fung
2013/11/04 21:39:57
Done.
| |
| 278 std::vector<std::string> types; | |
| 279 base::SplitString(types_rule, ',', &types); | |
| 280 for (std::vector<std::string>::const_iterator it = types.begin(); | |
| 281 it != types.end(); ++it) { | |
| 282 // This is a best-effort conversion; we trust the hand-crafted parameters | |
| 283 // downloaded from the server to be perfect. There's no need for handle | |
| 284 // errors smartly. | |
| 285 int t; | |
| 286 base::StringToInt(*it, &t); | |
| 287 undemotable_types->insert(static_cast<AutocompleteMatchType::Type>(t)); | |
| 288 } | |
| 289 } | |
| 290 | |
| 268 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( | 291 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 269 AutocompleteInput::PageClassification current_page_classification) { | 292 AutocompleteInput::PageClassification current_page_classification) { |
| 270 return OmniboxFieldTrial::GetValueForRuleInContext( | 293 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 271 kReorderForLegalDefaultMatchRule, current_page_classification) == | 294 kReorderForLegalDefaultMatchRule, current_page_classification) == |
| 272 kReorderForLegalDefaultMatchRuleEnabled; | 295 kReorderForLegalDefaultMatchRuleEnabled; |
| 273 } | 296 } |
| 274 | 297 |
| 275 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = | 298 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = |
| 276 "OmniboxBundledExperimentV1"; | 299 "OmniboxBundledExperimentV1"; |
| 277 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = | 300 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = |
| 278 "ShortcutsScoringMaxRelevance"; | 301 "ShortcutsScoringMaxRelevance"; |
| 279 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; | 302 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; |
| 280 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; | 303 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; |
| 304 const char OmniboxFieldTrial::kUndemotableTopTypeRule[] = "UndemotableTopTypes"; | |
| 281 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] = | 305 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] = |
| 282 "ReorderForLegalDefaultMatch"; | 306 "ReorderForLegalDefaultMatch"; |
| 283 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] = | 307 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] = |
| 284 "ReorderForLegalDefaultMatch"; | 308 "ReorderForLegalDefaultMatch"; |
| 285 | 309 |
| 286 // Background and implementation details: | 310 // Background and implementation details: |
| 287 // | 311 // |
| 288 // Each experiment group in any field trial can come with an optional set of | 312 // Each experiment group in any field trial can come with an optional set of |
| 289 // parameters (key-value pairs). In the bundled omnibox experiment | 313 // parameters (key-value pairs). In the bundled omnibox experiment |
| 290 // (kBundledExperimentFieldTrialName), each experiment group comes with a | 314 // (kBundledExperimentFieldTrialName), each experiment group comes with a |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 if (it != params.end()) | 362 if (it != params.end()) |
| 339 return it->second; | 363 return it->second; |
| 340 // Fall back to the global instant extended context. | 364 // Fall back to the global instant extended context. |
| 341 it = params.find(rule + ":" + page_classification_str + ":*"); | 365 it = params.find(rule + ":" + page_classification_str + ":*"); |
| 342 if (it != params.end()) | 366 if (it != params.end()) |
| 343 return it->second; | 367 return it->second; |
| 344 // Look up rule in the global context. | 368 // Look up rule in the global context. |
| 345 it = params.find(rule + ":*:*"); | 369 it = params.find(rule + ":*:*"); |
| 346 return (it != params.end()) ? it->second : std::string(); | 370 return (it != params.end()) ? it->second : std::string(); |
| 347 } | 371 } |
| OLD | NEW |