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