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