| 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 const std::string types_rule = |
| 272 OmniboxFieldTrial::GetValueForRuleInContext( |
| 273 kUndemotableTopTypeRule, |
| 274 current_page_classification); |
| 275 std::vector<std::string> types; |
| 276 base::SplitString(types_rule, ':', &types); |
| 277 for (std::vector<std::string>::const_iterator it = types.begin(); |
| 278 it != types.end(); ++it) { |
| 279 // This is a best-effort conversion; we trust the hand-crafted parameters |
| 280 // downloaded from the server to be perfect. There's no need for handle |
| 281 // errors smartly. |
| 282 int t; |
| 283 base::StringToInt(*it, &t); |
| 284 undemotable_types->insert(static_cast<AutocompleteMatchType::Type>(t)); |
| 285 } |
| 286 } |
| 287 |
| 268 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( | 288 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| 269 AutocompleteInput::PageClassification current_page_classification) { | 289 AutocompleteInput::PageClassification current_page_classification) { |
| 270 return OmniboxFieldTrial::GetValueForRuleInContext( | 290 return OmniboxFieldTrial::GetValueForRuleInContext( |
| 271 kReorderForLegalDefaultMatchRule, current_page_classification) == | 291 kReorderForLegalDefaultMatchRule, current_page_classification) == |
| 272 kReorderForLegalDefaultMatchRuleEnabled; | 292 kReorderForLegalDefaultMatchRuleEnabled; |
| 273 } | 293 } |
| 274 | 294 |
| 275 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = | 295 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = |
| 276 "OmniboxBundledExperimentV1"; | 296 "OmniboxBundledExperimentV1"; |
| 277 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = | 297 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = |
| 278 "ShortcutsScoringMaxRelevance"; | 298 "ShortcutsScoringMaxRelevance"; |
| 279 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; | 299 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; |
| 280 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; | 300 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; |
| 301 const char OmniboxFieldTrial::kUndemotableTopTypeRule[] = "UndemotableTopTypes"; |
| 281 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] = | 302 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] = |
| 282 "ReorderForLegalDefaultMatch"; | 303 "ReorderForLegalDefaultMatch"; |
| 283 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] = | 304 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] = |
| 284 "ReorderForLegalDefaultMatch"; | 305 "ReorderForLegalDefaultMatch"; |
| 285 | 306 |
| 286 // Background and implementation details: | 307 // Background and implementation details: |
| 287 // | 308 // |
| 288 // Each experiment group in any field trial can come with an optional set of | 309 // Each experiment group in any field trial can come with an optional set of |
| 289 // parameters (key-value pairs). In the bundled omnibox experiment | 310 // parameters (key-value pairs). In the bundled omnibox experiment |
| 290 // (kBundledExperimentFieldTrialName), each experiment group comes with a | 311 // (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()) | 359 if (it != params.end()) |
| 339 return it->second; | 360 return it->second; |
| 340 // Fall back to the global instant extended context. | 361 // Fall back to the global instant extended context. |
| 341 it = params.find(rule + ":" + page_classification_str + ":*"); | 362 it = params.find(rule + ":" + page_classification_str + ":*"); |
| 342 if (it != params.end()) | 363 if (it != params.end()) |
| 343 return it->second; | 364 return it->second; |
| 344 // Look up rule in the global context. | 365 // Look up rule in the global context. |
| 345 it = params.find(rule + ":*:*"); | 366 it = params.find(rule + ":*:*"); |
| 346 return (it != params.end()) ? it->second : std::string(); | 367 return (it != params.end()) ? it->second : std::string(); |
| 347 } | 368 } |
| OLD | NEW |