OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/instant/instant_field_trial.h" | 5 #include "chrome/browser/instant/instant_field_trial.h" |
6 | 6 |
| 7 #include "base/metrics/field_trial.h" |
7 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 bool field_trial_active_ = false; | 13 |
| 14 // Field trial IDs of the control and experiment groups. Though they are not |
| 15 // literally "const", they are set only once, in Activate() below. |
| 16 int g_control_group_id_1 = 0; |
| 17 int g_control_group_id_2 = 0; |
| 18 int g_experiment_group_id_1 = 0; |
| 19 int g_experiment_group_id_2 = 0; |
| 20 |
13 } | 21 } |
14 | 22 |
15 // static | 23 // static |
16 void InstantFieldTrial::Activate() { | 24 void InstantFieldTrial::Activate() { |
17 field_trial_active_ = true; | 25 scoped_refptr<base::FieldTrial> trial( |
| 26 new base::FieldTrial("Instant", 1000, "InstantInactive", 2012, 1, 1)); |
| 27 |
| 28 // One-time randomization is disabled if the user hasn't opted-in to UMA. |
| 29 if (!base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
| 30 return; |
| 31 trial->UseOneTimeRandomization(); |
| 32 |
| 33 g_control_group_id_1 = trial->AppendGroup("InstantControl1", 450); // 45% |
| 34 g_control_group_id_2 = trial->AppendGroup("InstantControl2", 450); // 45% |
| 35 g_experiment_group_id_1 = trial->AppendGroup("InstantExperiment1", 50); // 5% |
| 36 g_experiment_group_id_2 = trial->AppendGroup("InstantExperiment2", 50); // 5% |
18 } | 37 } |
19 | 38 |
20 // static | 39 // static |
21 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { | 40 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { |
22 if (!field_trial_active_) | |
23 return INACTIVE; | |
24 | |
25 if (profile->IsOffTheRecord()) | 41 if (profile->IsOffTheRecord()) |
26 return INACTIVE; | 42 return INACTIVE; |
27 | 43 |
28 const PrefService* prefs = profile->GetPrefs(); | 44 const PrefService* prefs = profile->GetPrefs(); |
29 if (!prefs || | 45 if (!prefs || |
30 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || | 46 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || |
31 prefs->GetBoolean(prefs::kInstantEnabledOnce) || | 47 prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
32 prefs->IsManagedPreference(prefs::kInstantEnabled)) { | 48 prefs->IsManagedPreference(prefs::kInstantEnabled)) { |
33 return INACTIVE; | 49 return INACTIVE; |
34 } | 50 } |
35 | 51 |
36 const int random = prefs->GetInteger(prefs::kInstantFieldTrialRandomDraw); | 52 const int group = base::FieldTrialList::FindValue("Instant"); |
37 return random < 4500 ? CONTROL1 : // 45% | 53 |
38 random < 9000 ? CONTROL2 : // 45% | 54 if (group == base::FieldTrial::kNotFinalized || |
39 random < 9500 ? EXPERIMENT1 // 5% | 55 group == base::FieldTrial::kDefaultGroupNumber) { |
40 : EXPERIMENT2; // 5% | 56 return INACTIVE; |
| 57 } |
| 58 |
| 59 return group == g_control_group_id_1 ? CONTROL1 : |
| 60 group == g_control_group_id_2 ? CONTROL2 : |
| 61 group == g_experiment_group_id_1 ? EXPERIMENT1 : |
| 62 group == g_experiment_group_id_2 ? EXPERIMENT2 |
| 63 : INACTIVE; |
41 } | 64 } |
42 | 65 |
43 // static | 66 // static |
44 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { | 67 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { |
45 Group group = GetGroup(profile); | 68 Group group = GetGroup(profile); |
46 return group == EXPERIMENT1 || group == EXPERIMENT2; | 69 return group == EXPERIMENT1 || group == EXPERIMENT2; |
47 } | 70 } |
48 | 71 |
49 // static | 72 // static |
50 std::string InstantFieldTrial::GetGroupName(Profile* profile) { | 73 std::string InstantFieldTrial::GetGroupName(Profile* profile) { |
51 switch (GetGroup(profile)) { | 74 switch (GetGroup(profile)) { |
52 case INACTIVE: return "InstantInactive"; | 75 case INACTIVE: return "InstantInactive"; |
53 case CONTROL1: return "InstantControl1"; | 76 case CONTROL1: return "InstantControl1"; |
54 case CONTROL2: return "InstantControl2"; | 77 case CONTROL2: return "InstantControl2"; |
55 case EXPERIMENT1: return "InstantExperiment1"; | 78 case EXPERIMENT1: return "InstantExperiment1"; |
56 case EXPERIMENT2: return "InstantExperiment2"; | 79 case EXPERIMENT2: return "InstantExperiment2"; |
57 } | 80 } |
58 NOTREACHED(); | 81 NOTREACHED(); |
59 return "InstantUnknown"; | 82 return "InstantUnknown"; |
60 } | 83 } |
OLD | NEW |