Index: chrome/browser/autocomplete/autocomplete_field_trial.cc |
diff --git a/chrome/browser/autocomplete/autocomplete_field_trial.cc b/chrome/browser/autocomplete/autocomplete_field_trial.cc |
index 412936e77793066d4798d957b025974020113f7c..cfed6bbd37d03650128fbc3479b31c47108c351d 100644 |
--- a/chrome/browser/autocomplete/autocomplete_field_trial.cc |
+++ b/chrome/browser/autocomplete/autocomplete_field_trial.cc |
@@ -96,12 +96,16 @@ const base::FieldTrial::Probability |
// Field trial IDs. |
// Though they are not literally "const", they are set only once, in |
-// Activate() below. |
+// ActivateStaticTrials() below. |
// Whether the static field trials have been initialized by |
-// ActivateStaticTrials method. |
+// ActivateStaticTrials() method. |
bool static_field_trials_initialized = false; |
+// Whether the dynamic field trials have been initialized by |
+// ActivateDynamicTrials() method. |
+bool dynamic_field_trials_initialized = false; |
+ |
// Field trial ID for the disallow-inline History Quick Provider |
// experiment group. |
int disallow_inline_hqp_experiment_group = 0; |
@@ -124,8 +128,12 @@ int hqp_replace_hup_scoring_experiment_group = 0; |
// word boundaries experiment group. |
int hqp_only_count_matches_at_word_boundaries_experiment_group = 0; |
+std::string DynamicFieldTrialName(int id) { |
Mark P
2013/02/11 21:13:34
please comment about expected use.
Bart N.
2013/02/11 21:42:12
Done.
|
+ return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); |
} |
+} // namespace |
+ |
void AutocompleteFieldTrial::ActivateStaticTrials() { |
DCHECK(!static_field_trials_initialized); |
@@ -237,11 +245,36 @@ void AutocompleteFieldTrial::ActivateStaticTrials() { |
} |
void AutocompleteFieldTrial::ActivateDynamicTrials() { |
- // Initialize all autocomplete dynamic field trials. |
+ // Initialize all autocomplete dynamic field trials. This method may be |
+ // called multiple times. |
+ for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) |
+ base::FieldTrialList::FindValue(DynamicFieldTrialName(i)); |
+ |
+ dynamic_field_trials_initialized = true; |
+} |
+ |
+int AutocompleteFieldTrial::GetDisabledProviderTypes() { |
+ DCHECK(dynamic_field_trials_initialized); |
+ |
+ // We assume that each group may contain a substring |
+ // "DisabledProviders_<mask>" where "mask" is a bitmap of disabled provider |
+ // types (AutocompleteProvider::Type). |
+ int provider_types = 0; |
for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { |
- base::FieldTrialList::FindValue( |
- base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, i)); |
+ std::string group_name = base::FieldTrialList::FindFullName( |
+ DynamicFieldTrialName(i)); |
+ if (!group_name.empty()) { |
+ const char kDisabledProviders[] = "DisabledProviders_"; |
+ size_t pos = group_name.find(kDisabledProviders); |
Mark P
2013/02/11 21:13:34
const
Bart N.
2013/02/11 21:42:12
Done.
|
+ if (pos == std::string::npos) |
+ continue; |
+ int types = 0; |
Mark P
2013/02/11 21:13:34
do you expect pos to ever not be 0?
perhaps dcheck
Bart N.
2013/02/11 21:42:12
I don't think it's a good idea to DCHECK against s
Mark P
2013/02/11 22:04:18
I don't see a warning message. Can you please add
Bart N.
2013/02/12 01:18:19
As discussed offline, I made now a stronger requir
|
+ base::StringToInt(base::StringPiece( |
Mark P
2013/02/11 21:13:34
consider dchecking the return type of this
Bart N.
2013/02/11 21:42:12
Not really; clarified in the comment.
Mark P
2013/02/11 22:04:18
You really do want perfect conversions. Don't try
Bart N.
2013/02/12 01:18:19
As discussed offline, it was intended. However, I
|
+ group_name.substr(pos + strlen(kDisabledProviders))), &types); |
+ provider_types |= types; |
+ } |
} |
+ return provider_types; |
} |
bool AutocompleteFieldTrial::InDisallowInlineHQPFieldTrial() { |