OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/omnibox_field_trial.h" | 5 #include "components/omnibox/browser/omnibox_field_trial.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "components/variations/metrics_util.h" | 22 #include "components/variations/metrics_util.h" |
23 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
24 | 24 |
25 using metrics::OmniboxEventProto; | 25 using metrics::OmniboxEventProto; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 typedef std::map<std::string, std::string> VariationParams; | 29 typedef std::map<std::string, std::string> VariationParams; |
30 typedef HUPScoringParams::ScoreBuckets ScoreBuckets; | 30 typedef HUPScoringParams::ScoreBuckets ScoreBuckets; |
31 | 31 |
32 // Field trial names. | |
33 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; | |
34 | |
35 // The autocomplete dynamic field trial name prefix. Each field trial is | |
36 // configured dynamically and is retrieved automatically by Chrome during | |
37 // the startup. | |
38 const char kAutocompleteDynamicFieldTrialPrefix[] = "AutocompleteDynamicTrial_"; | |
39 // The maximum number of the autocomplete dynamic field trials (aka layers). | |
40 const int kMaxAutocompleteDynamicFieldTrials = 5; | |
41 | |
42 | |
43 // Concatenates the autocomplete dynamic field trial prefix with a field trial | |
44 // ID to form a complete autocomplete field trial name. | |
45 std::string DynamicFieldTrialName(int id) { | |
46 return base::StringPrintf("%s%d", kAutocompleteDynamicFieldTrialPrefix, id); | |
47 } | |
48 | |
49 void InitializeBucketsFromString(const std::string& bucket_string, | 32 void InitializeBucketsFromString(const std::string& bucket_string, |
50 ScoreBuckets* score_buckets) { | 33 ScoreBuckets* score_buckets) { |
51 // Clear the buckets. | 34 // Clear the buckets. |
52 score_buckets->buckets().clear(); | 35 score_buckets->buckets().clear(); |
53 base::StringPairs kv_pairs; | 36 base::StringPairs kv_pairs; |
54 if (base::SplitStringIntoKeyValuePairs(bucket_string, ':', ',', &kv_pairs)) { | 37 if (base::SplitStringIntoKeyValuePairs(bucket_string, ':', ',', &kv_pairs)) { |
55 for (base::StringPairs::const_iterator it = kv_pairs.begin(); | 38 for (base::StringPairs::const_iterator it = kv_pairs.begin(); |
56 it != kv_pairs.end(); ++it) { | 39 it != kv_pairs.end(); ++it) { |
57 ScoreBuckets::CountMaxRelevance bucket; | 40 ScoreBuckets::CountMaxRelevance bucket; |
58 base::StringToDouble(it->first, &bucket.first); | 41 base::StringToDouble(it->first, &bucket.first); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 double time_ms; | 99 double time_ms; |
117 if ((half_life_days_ <= 0) || | 100 if ((half_life_days_ <= 0) || |
118 ((time_ms = elapsed_time.InMillisecondsF()) <= 0)) | 101 ((time_ms = elapsed_time.InMillisecondsF()) <= 0)) |
119 return 1.0; | 102 return 1.0; |
120 | 103 |
121 const double half_life_intervals = | 104 const double half_life_intervals = |
122 time_ms / base::TimeDelta::FromDays(half_life_days_).InMillisecondsF(); | 105 time_ms / base::TimeDelta::FromDays(half_life_days_).InMillisecondsF(); |
123 return pow(2.0, -half_life_intervals); | 106 return pow(2.0, -half_life_intervals); |
124 } | 107 } |
125 | 108 |
126 void OmniboxFieldTrial::ActivateDynamicTrials() { | |
127 // Initialize all autocomplete dynamic field trials. This method may be | |
128 // called multiple times. | |
129 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) | |
130 base::FieldTrialList::FindValue(DynamicFieldTrialName(i)); | |
131 } | |
132 | |
133 int OmniboxFieldTrial::GetDisabledProviderTypes() { | 109 int OmniboxFieldTrial::GetDisabledProviderTypes() { |
134 const std::string& types_string = variations::GetVariationParamValue( | 110 const std::string& types_string = variations::GetVariationParamValue( |
135 kBundledExperimentFieldTrialName, | 111 kBundledExperimentFieldTrialName, |
136 kDisableProvidersRule); | 112 kDisableProvidersRule); |
137 int types = 0; | 113 int types = 0; |
138 if (types_string.empty() || !base::StringToInt(types_string, &types)) { | 114 if (types_string.empty() || !base::StringToInt(types_string, &types)) { |
139 return 0; | 115 return 0; |
140 } | 116 } |
141 return types; | 117 return types; |
142 } | 118 } |
143 | 119 |
144 void OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes( | |
Mark P
2016/01/14 05:31:02
The last part of this function still needs to rema
Ilya Sherman
2016/01/14 05:40:41
Whoops! Thanks for catching that.
| |
145 std::vector<uint32_t>* field_trial_hashes) { | |
146 field_trial_hashes->clear(); | |
147 for (int i = 0; i < kMaxAutocompleteDynamicFieldTrials; ++i) { | |
148 const std::string& trial_name = DynamicFieldTrialName(i); | |
149 if (base::FieldTrialList::TrialExists(trial_name)) | |
150 field_trial_hashes->push_back(metrics::HashName(trial_name)); | |
151 } | |
152 if (base::FieldTrialList::TrialExists(kBundledExperimentFieldTrialName)) { | |
153 field_trial_hashes->push_back( | |
154 metrics::HashName(kBundledExperimentFieldTrialName)); | |
155 } | |
156 } | |
157 | |
158 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { | |
Mark P
2016/01/14 05:31:02
I'd prefer is this trial remains.
Ilya Sherman
2016/01/14 05:40:41
Done.
| |
159 int stop_timer_ms; | |
160 if (base::StringToInt( | |
161 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), | |
162 &stop_timer_ms)) | |
163 return base::TimeDelta::FromMilliseconds(stop_timer_ms); | |
164 return base::TimeDelta::FromMilliseconds(1500); | |
165 } | |
166 | |
167 bool OmniboxFieldTrial::InZeroSuggestFieldTrial() { | 120 bool OmniboxFieldTrial::InZeroSuggestFieldTrial() { |
168 if (variations::GetVariationParamValue( | 121 if (variations::GetVariationParamValue( |
169 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "true") | 122 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "true") |
170 return true; | 123 return true; |
171 if (variations::GetVariationParamValue( | 124 if (variations::GetVariationParamValue( |
172 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "false") | 125 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "false") |
173 return false; | 126 return false; |
174 #if defined(OS_IOS) | 127 #if defined(OS_IOS) |
175 return false; | 128 return false; |
176 #else | 129 #else |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 if (it != params.end()) | 593 if (it != params.end()) |
641 return it->second; | 594 return it->second; |
642 // Fall back to the global instant extended context. | 595 // Fall back to the global instant extended context. |
643 it = params.find(rule + ":" + page_classification_str + ":*"); | 596 it = params.find(rule + ":" + page_classification_str + ":*"); |
644 if (it != params.end()) | 597 if (it != params.end()) |
645 return it->second; | 598 return it->second; |
646 // Look up rule in the global context. | 599 // Look up rule in the global context. |
647 it = params.find(rule + ":*:*"); | 600 it = params.find(rule + ":*:*"); |
648 return (it != params.end()) ? it->second : std::string(); | 601 return (it != params.end()) ? it->second : std::string(); |
649 } | 602 } |
OLD | NEW |