Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/omnibox/omnibox_field_trial.cc

Issue 55413002: Don't demote top match for certain match types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Peter's comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // The value of the DemoteByType rule is a comma-separated list of 247 // The value of the DemoteByType rule is a comma-separated list of
248 // {ResultType + ":" + Number} where ResultType is an AutocompleteMatchType:: 248 // {ResultType + ":" + Number} where ResultType is an AutocompleteMatchType::
249 // Type enum represented as an integer and Number is an integer number 249 // Type enum represented as an integer and Number is an integer number
250 // between 0 and 100 inclusive. Relevance scores of matches of that result 250 // between 0 and 100 inclusive. Relevance scores of matches of that result
251 // type are multiplied by Number / 100. 100 means no change. 251 // type are multiplied by Number / 100. 100 means no change.
252 base::StringPairs kv_pairs; 252 base::StringPairs kv_pairs;
253 if (base::SplitStringIntoKeyValuePairs(demotion_rule, ':', ',', &kv_pairs)) { 253 if (base::SplitStringIntoKeyValuePairs(demotion_rule, ':', ',', &kv_pairs)) {
254 for (base::StringPairs::const_iterator it = kv_pairs.begin(); 254 for (base::StringPairs::const_iterator it = kv_pairs.begin();
255 it != kv_pairs.end(); ++it) { 255 it != kv_pairs.end(); ++it) {
256 // This is a best-effort conversion; we trust the hand-crafted parameters 256 // This is a best-effort conversion; we trust the hand-crafted parameters
257 // downloaded from the server to be perfect. There's no need for handle 257 // downloaded from the server to be perfect. There's no need to handle
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 OmniboxFieldTrial::UndemotableTopMatchTypes
269 OmniboxFieldTrial::GetUndemotableTopTypes(
270 AutocompleteInput::PageClassification current_page_classification) {
271 UndemotableTopMatchTypes undemotable_types;
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 to handle
286 // errors smartly.
287 int t;
288 base::StringToInt(*it, &t);
289 undemotable_types.insert(static_cast<AutocompleteMatchType::Type>(t));
290 }
291 return undemotable_types;
292 }
293
268 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch( 294 bool OmniboxFieldTrial::ReorderForLegalDefaultMatch(
269 AutocompleteInput::PageClassification current_page_classification) { 295 AutocompleteInput::PageClassification current_page_classification) {
270 return OmniboxFieldTrial::GetValueForRuleInContext( 296 return OmniboxFieldTrial::GetValueForRuleInContext(
271 kReorderForLegalDefaultMatchRule, current_page_classification) == 297 kReorderForLegalDefaultMatchRule, current_page_classification) ==
272 kReorderForLegalDefaultMatchRuleEnabled; 298 kReorderForLegalDefaultMatchRuleEnabled;
273 } 299 }
274 300
275 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = 301 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] =
276 "OmniboxBundledExperimentV1"; 302 "OmniboxBundledExperimentV1";
277 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = 303 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] =
278 "ShortcutsScoringMaxRelevance"; 304 "ShortcutsScoringMaxRelevance";
279 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; 305 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory";
280 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; 306 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType";
307 const char OmniboxFieldTrial::kUndemotableTopTypeRule[] = "UndemotableTopTypes";
281 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] = 308 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRule[] =
282 "ReorderForLegalDefaultMatch"; 309 "ReorderForLegalDefaultMatch";
283 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] = 310 const char OmniboxFieldTrial::kReorderForLegalDefaultMatchRuleEnabled[] =
284 "ReorderForLegalDefaultMatch"; 311 "ReorderForLegalDefaultMatch";
285 312
286 // Background and implementation details: 313 // Background and implementation details:
287 // 314 //
288 // Each experiment group in any field trial can come with an optional set of 315 // Each experiment group in any field trial can come with an optional set of
289 // parameters (key-value pairs). In the bundled omnibox experiment 316 // parameters (key-value pairs). In the bundled omnibox experiment
290 // (kBundledExperimentFieldTrialName), each experiment group comes with a 317 // (kBundledExperimentFieldTrialName), each experiment group comes with a
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (it != params.end()) 365 if (it != params.end())
339 return it->second; 366 return it->second;
340 // Fall back to the global instant extended context. 367 // Fall back to the global instant extended context.
341 it = params.find(rule + ":" + page_classification_str + ":*"); 368 it = params.find(rule + ":" + page_classification_str + ":*");
342 if (it != params.end()) 369 if (it != params.end())
343 return it->second; 370 return it->second;
344 // Look up rule in the global context. 371 // Look up rule in the global context.
345 it = params.find(rule + ":*:*"); 372 it = params.find(rule + ":*:*");
346 return (it != params.end()) ? it->second : std::string(); 373 return (it != params.end()) ? it->second : std::string();
347 } 374 }
OLDNEW
« no previous file with comments | « chrome/browser/omnibox/omnibox_field_trial.h ('k') | chrome/browser/omnibox/omnibox_field_trial_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698