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" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | |
16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
18 #include "components/metrics/proto/omnibox_event.pb.h" | 17 #include "components/metrics/proto/omnibox_event.pb.h" |
19 #include "components/omnibox/browser/omnibox_switches.h" | 18 #include "components/omnibox/browser/omnibox_switches.h" |
20 #include "components/search/search.h" | 19 #include "components/search/search.h" |
21 #include "components/variations/active_field_trials.h" | 20 #include "components/variations/active_field_trials.h" |
22 #include "components/variations/metrics_util.h" | 21 #include "components/variations/metrics_util.h" |
23 #include "components/variations/variations_associated_data.h" | 22 #include "components/variations/variations_associated_data.h" |
24 | 23 |
25 using metrics::OmniboxEventProto; | 24 using metrics::OmniboxEventProto; |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 typedef std::map<std::string, std::string> VariationParams; | 28 typedef std::map<std::string, std::string> VariationParams; |
30 typedef HUPScoringParams::ScoreBuckets ScoreBuckets; | 29 typedef HUPScoringParams::ScoreBuckets ScoreBuckets; |
31 | 30 |
32 // Field trial names. | 31 // Field trial names. |
33 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; | 32 const char kStopTimerFieldTrialName[] = "OmniboxStopTimer"; |
34 | 33 |
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, | 34 void InitializeBucketsFromString(const std::string& bucket_string, |
50 ScoreBuckets* score_buckets) { | 35 ScoreBuckets* score_buckets) { |
51 // Clear the buckets. | 36 // Clear the buckets. |
52 score_buckets->buckets().clear(); | 37 score_buckets->buckets().clear(); |
53 base::StringPairs kv_pairs; | 38 base::StringPairs kv_pairs; |
54 if (base::SplitStringIntoKeyValuePairs(bucket_string, ':', ',', &kv_pairs)) { | 39 if (base::SplitStringIntoKeyValuePairs(bucket_string, ':', ',', &kv_pairs)) { |
55 for (base::StringPairs::const_iterator it = kv_pairs.begin(); | 40 for (base::StringPairs::const_iterator it = kv_pairs.begin(); |
56 it != kv_pairs.end(); ++it) { | 41 it != kv_pairs.end(); ++it) { |
57 ScoreBuckets::CountMaxRelevance bucket; | 42 ScoreBuckets::CountMaxRelevance bucket; |
58 base::StringToDouble(it->first, &bucket.first); | 43 base::StringToDouble(it->first, &bucket.first); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 double time_ms; | 101 double time_ms; |
117 if ((half_life_days_ <= 0) || | 102 if ((half_life_days_ <= 0) || |
118 ((time_ms = elapsed_time.InMillisecondsF()) <= 0)) | 103 ((time_ms = elapsed_time.InMillisecondsF()) <= 0)) |
119 return 1.0; | 104 return 1.0; |
120 | 105 |
121 const double half_life_intervals = | 106 const double half_life_intervals = |
122 time_ms / base::TimeDelta::FromDays(half_life_days_).InMillisecondsF(); | 107 time_ms / base::TimeDelta::FromDays(half_life_days_).InMillisecondsF(); |
123 return pow(2.0, -half_life_intervals); | 108 return pow(2.0, -half_life_intervals); |
124 } | 109 } |
125 | 110 |
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() { | 111 int OmniboxFieldTrial::GetDisabledProviderTypes() { |
134 const std::string& types_string = variations::GetVariationParamValue( | 112 const std::string& types_string = variations::GetVariationParamValue( |
135 kBundledExperimentFieldTrialName, | 113 kBundledExperimentFieldTrialName, |
136 kDisableProvidersRule); | 114 kDisableProvidersRule); |
137 int types = 0; | 115 int types = 0; |
138 if (types_string.empty() || !base::StringToInt(types_string, &types)) { | 116 if (types_string.empty() || !base::StringToInt(types_string, &types)) { |
139 return 0; | 117 return 0; |
140 } | 118 } |
141 return types; | 119 return types; |
142 } | 120 } |
143 | 121 |
144 void OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes( | 122 void OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes( |
145 std::vector<uint32_t>* field_trial_hashes) { | 123 std::vector<uint32_t>* field_trial_hashes) { |
146 field_trial_hashes->clear(); | 124 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)) { | 125 if (base::FieldTrialList::TrialExists(kBundledExperimentFieldTrialName)) { |
153 field_trial_hashes->push_back( | 126 field_trial_hashes->push_back( |
154 metrics::HashName(kBundledExperimentFieldTrialName)); | 127 metrics::HashName(kBundledExperimentFieldTrialName)); |
155 } | 128 } |
156 } | 129 } |
157 | 130 |
158 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { | 131 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { |
159 int stop_timer_ms; | 132 int stop_timer_ms; |
160 if (base::StringToInt( | 133 if (base::StringToInt( |
161 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), | 134 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 if (it != params.end()) | 613 if (it != params.end()) |
641 return it->second; | 614 return it->second; |
642 // Fall back to the global instant extended context. | 615 // Fall back to the global instant extended context. |
643 it = params.find(rule + ":" + page_classification_str + ":*"); | 616 it = params.find(rule + ":" + page_classification_str + ":*"); |
644 if (it != params.end()) | 617 if (it != params.end()) |
645 return it->second; | 618 return it->second; |
646 // Look up rule in the global context. | 619 // Look up rule in the global context. |
647 it = params.find(rule + ":*:*"); | 620 it = params.find(rule + ":*:*"); |
648 return (it != params.end()) ? it->second : std::string(); | 621 return (it != params.end()) ? it->second : std::string(); |
649 } | 622 } |
OLD | NEW |