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" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_input.h" |
14 #include "chrome/browser/search/search.h" | 15 #include "chrome/browser/search/search.h" |
15 #include "chrome/common/metrics/metrics_util.h" | 16 #include "chrome/common/metrics/metrics_util.h" |
16 #include "chrome/common/metrics/variations/variation_ids.h" | 17 #include "chrome/common/metrics/variations/variation_ids.h" |
17 #include "chrome/common/metrics/variations/variations_util.h" | 18 #include "chrome/common/metrics/variations/variations_util.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Field trial names. | 22 // Field trial names. |
22 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; | 23 const char kHUPCullRedirectsFieldTrialName[] = "OmniboxHUPCullRedirects"; |
23 const char kHUPCreateShorterMatchFieldTrialName[] = | 24 const char kHUPCreateShorterMatchFieldTrialName[] = |
24 "OmniboxHUPCreateShorterMatch"; | 25 "OmniboxHUPCreateShorterMatch"; |
25 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; | 26 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; |
26 const char kShortcutsScoringFieldTrialName[] = "OmniboxShortcutsScoring"; | |
27 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; | 27 const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; |
28 | 28 |
29 // Rule names used by the bundled experiment. | 29 // Rule names used by the bundled experiment. |
| 30 const char kShortcutsScoringMaxRelevanceRule[] = "ShortcutsScoringMaxRelevance"; |
30 const char kSearchHistoryRule[] = "SearchHistory"; | 31 const char kSearchHistoryRule[] = "SearchHistory"; |
31 const char kDemoteByTypeRule[] = "DemoteByType"; | 32 const char kDemoteByTypeRule[] = "DemoteByType"; |
32 | 33 |
33 // The autocomplete dynamic field trial name prefix. Each field trial is | 34 // The autocomplete dynamic field trial name prefix. Each field trial is |
34 // configured dynamically and is retrieved automatically by Chrome during | 35 // configured dynamically and is retrieved automatically by Chrome during |
35 // the startup. | 36 // the startup. |
36 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; | 37 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; |
37 // The maximum number of the autocomplete dynamic field trials (aka layers). | 38 // The maximum number of the autocomplete dynamic field trials (aka layers). |
38 const int kMaxAutocompleteDynamicFieldTrials = 5; | 39 const int kMaxAutocompleteDynamicFieldTrials = 5; |
39 | 40 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // is a bitmap of disabled provider types (AutocompleteProvider::Type). | 129 // is a bitmap of disabled provider types (AutocompleteProvider::Type). |
129 int provider_types = 0; | 130 int provider_types = 0; |
130 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { | 131 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { |
131 std::string group_name = base::FieldTrialList::FindFullName( | 132 std::string group_name = base::FieldTrialList::FindFullName( |
132 DynamicFieldTrialName(i)); | 133 DynamicFieldTrialName(i)); |
133 const char kDisabledProviders[] = "DisabledProviders_"; | 134 const char kDisabledProviders[] = "DisabledProviders_"; |
134 if (!StartsWithASCII(group_name, kDisabledProviders, true)) | 135 if (!StartsWithASCII(group_name, kDisabledProviders, true)) |
135 continue; | 136 continue; |
136 int types = 0; | 137 int types = 0; |
137 if (!base::StringToInt(base::StringPiece( | 138 if (!base::StringToInt(base::StringPiece( |
138 group_name.substr(strlen(kDisabledProviders))), &types)) { | 139 group_name.substr(strlen(kDisabledProviders))), &types)) |
139 LOG(WARNING) << "Malformed DisabledProviders string: " << group_name; | |
140 continue; | 140 continue; |
141 } | 141 provider_types |= types; |
142 if (types == 0) | |
143 LOG(WARNING) << "Expecting a non-zero bitmap; group = " << group_name; | |
144 else | |
145 provider_types |= types; | |
146 } | 142 } |
147 return provider_types; | 143 return provider_types; |
148 } | 144 } |
149 | 145 |
150 void OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes( | 146 void OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes( |
151 std::vector<uint32>* field_trial_hashes) { | 147 std::vector<uint32>* field_trial_hashes) { |
152 field_trial_hashes->clear(); | 148 field_trial_hashes->clear(); |
153 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { | 149 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { |
154 const std::string& trial_name = DynamicFieldTrialName(i); | 150 const std::string& trial_name = DynamicFieldTrialName(i); |
155 if (base::FieldTrialList::TrialExists(trial_name)) | 151 if (base::FieldTrialList::TrialExists(trial_name)) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { | 196 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { |
201 const std::string& group_name = base::FieldTrialList::FindFullName( | 197 const std::string& group_name = base::FieldTrialList::FindFullName( |
202 DynamicFieldTrialName(i)); | 198 DynamicFieldTrialName(i)); |
203 const char kEnableZeroSuggest[] = "EnableZeroSuggest"; | 199 const char kEnableZeroSuggest[] = "EnableZeroSuggest"; |
204 if (StartsWithASCII(group_name, kEnableZeroSuggest, true)) | 200 if (StartsWithASCII(group_name, kEnableZeroSuggest, true)) |
205 return true; | 201 return true; |
206 } | 202 } |
207 return false; | 203 return false; |
208 } | 204 } |
209 | 205 |
210 // If the active group name starts with "MaxRelevance_", extract the | 206 bool OmniboxFieldTrial::ShortcutsScoringMaxRelevance( |
211 // int that immediately following that, returning true on success. | 207 AutocompleteInput::PageClassification current_page_classification, |
212 bool OmniboxFieldTrial::ShortcutsScoringMaxRelevance(int* max_relevance) { | 208 int* max_relevance) { |
213 std::string group_name = | 209 // The value of the rule is a string that encodes an integer containing |
214 base::FieldTrialList::FindFullName(kShortcutsScoringFieldTrialName); | 210 // the max relevance. |
215 const char kMaxRelevanceGroupPrefix[] = "MaxRelevance_"; | 211 const std::string& max_relevance_str = |
216 if (!StartsWithASCII(group_name, kMaxRelevanceGroupPrefix, true)) | 212 OmniboxFieldTrial::GetValueForRuleInContext( |
| 213 kShortcutsScoringMaxRelevanceRule, current_page_classification); |
| 214 if (max_relevance_str.empty()) |
217 return false; | 215 return false; |
218 if (!base::StringToInt(base::StringPiece( | 216 if (!base::StringToInt(max_relevance_str, max_relevance)) |
219 group_name.substr(strlen(kMaxRelevanceGroupPrefix))), | |
220 max_relevance)) { | |
221 LOG(WARNING) << "Malformed MaxRelevance string: " << group_name; | |
222 return false; | 217 return false; |
223 } | |
224 return true; | 218 return true; |
225 } | 219 } |
226 | 220 |
227 bool OmniboxFieldTrial::SearchHistoryPreventInlining( | 221 bool OmniboxFieldTrial::SearchHistoryPreventInlining( |
228 AutocompleteInput::PageClassification current_page_classification) { | 222 AutocompleteInput::PageClassification current_page_classification) { |
229 return OmniboxFieldTrial::GetValueForRuleInContext( | 223 return OmniboxFieldTrial::GetValueForRuleInContext( |
230 kSearchHistoryRule, current_page_classification) == "PreventInlining"; | 224 kSearchHistoryRule, current_page_classification) == "PreventInlining"; |
231 } | 225 } |
232 | 226 |
233 bool OmniboxFieldTrial::SearchHistoryDisable( | 227 bool OmniboxFieldTrial::SearchHistoryDisable( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (it != params.end()) | 314 if (it != params.end()) |
321 return it->second; | 315 return it->second; |
322 // Fall back to the global instant extended context. | 316 // Fall back to the global instant extended context. |
323 it = params.find(rule + ":" + page_classification_str + ":*"); | 317 it = params.find(rule + ":" + page_classification_str + ":*"); |
324 if (it != params.end()) | 318 if (it != params.end()) |
325 return it->second; | 319 return it->second; |
326 // Look up rule in the global context. | 320 // Look up rule in the global context. |
327 it = params.find(rule + ":*:*"); | 321 it = params.find(rule + ":*:*"); |
328 return (it != params.end()) ? it->second : std::string(); | 322 return (it != params.end()) ? it->second : std::string(); |
329 } | 323 } |
OLD | NEW |