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/ui/webui/sync_promo_trial.h" | 5 #include "chrome/browser/ui/webui/sync_promo_trial.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/string_util.h" | |
9 #include "chrome/browser/google/google_util.h" | |
8 #include "chrome/browser/metrics/metrics_service.h" | 10 #include "chrome/browser/metrics/metrics_service.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
10 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
11 | 13 |
12 namespace sync_promo_trial { | 14 namespace sync_promo_trial { |
13 | 15 |
14 // Field trial IDs of the control and experiment groups. Though they are not | 16 // Field trial IDs of the control and experiment groups. Though they are not |
15 // literally "const", they are set only once, in Activate() below. See the .h | 17 // literally "const", they are set only once, in Activate() below. See the .h |
16 // file for what these groups represent. | 18 // file for what these groups represent. |
17 int g_sync_promo_experiment_a = 0; | 19 int g_sync_promo_experiment_a = 0; |
18 int g_sync_promo_experiment_b = 0; | 20 int g_sync_promo_experiment_b = 0; |
19 int g_sync_promo_experiment_c = 0; | 21 int g_sync_promo_experiment_c = 0; |
20 int g_sync_promo_experiment_d = 0; | 22 int g_sync_promo_experiment_d = 0; |
21 | 23 |
24 const char kSyncPromoEnabledTrialName[] = "SyncPromoEnabled"; | |
22 const char kSyncPromoMsgTrialName[] = "SyncPromoMsg"; | 25 const char kSyncPromoMsgTrialName[] = "SyncPromoMsg"; |
23 | 26 |
27 const char kSyncPromoEnabledWithApps[] = "EnabledWithDefaultApps"; | |
28 const char kSyncPromoEnabledWithoutApps[] = "EnabledWithoutDefaultApps"; | |
29 const char kSyncPromoDisabledWithApps[] = "DisabledWithDefaultApps"; | |
30 const char kSyncPromoDisabledWithoutApps[] = "DisabledWithoutDefaultApps"; | |
31 | |
24 void Activate() { | 32 void Activate() { |
25 // The end date (February 21, 2012) is approximately 2 weeks into M17 stable. | 33 // The end date (February 21, 2012) is approximately 2 weeks into M17 stable. |
26 scoped_refptr<base::FieldTrial> trial( | 34 scoped_refptr<base::FieldTrial> trial( |
27 new base::FieldTrial(kSyncPromoMsgTrialName, 1000, "MsgA", 2012, 2, 21)); | 35 new base::FieldTrial(kSyncPromoMsgTrialName, 1000, "MsgA", 2012, 2, 21)); |
28 g_sync_promo_experiment_a = base::FieldTrial::kDefaultGroupNumber; | 36 g_sync_promo_experiment_a = base::FieldTrial::kDefaultGroupNumber; |
29 | 37 |
30 // Try to give the user a consistent experience, if possible. | 38 // Try to give the user a consistent experience, if possible. |
31 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | 39 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
32 trial->UseOneTimeRandomization(); | 40 trial->UseOneTimeRandomization(); |
33 | 41 |
34 // Each group has probability 0.5%, leaving the control with 98.5%. | 42 // Each group has probability 0.5%, leaving the control with 98.5%. |
35 g_sync_promo_experiment_b = trial->AppendGroup("MsgB", 50); | 43 g_sync_promo_experiment_b = trial->AppendGroup("MsgB", 50); |
36 g_sync_promo_experiment_c = trial->AppendGroup("MsgC", 50); | 44 g_sync_promo_experiment_c = trial->AppendGroup("MsgC", 50); |
37 g_sync_promo_experiment_d = trial->AppendGroup("MsgD", 50); | 45 g_sync_promo_experiment_d = trial->AppendGroup("MsgD", 50); |
46 | |
47 // Determine whether we should show the sync promo via brand code. | |
48 std::string brand; | |
49 google_util::GetBrand(&brand); | |
50 | |
51 // Create a field trial based on the brand code. | |
52 if (LowerCaseEqualsASCII(brand, "ecba")) { | |
53 base::FieldTrialList::CreateFieldTrial(kSyncPromoEnabledTrialName, | |
54 kSyncPromoEnabledWithApps); | |
55 } else if (LowerCaseEqualsASCII(brand, "ecsa")) { | |
56 base::FieldTrialList::CreateFieldTrial(kSyncPromoEnabledTrialName, | |
57 kSyncPromoEnabledWithoutApps); | |
58 } else if (LowerCaseEqualsASCII(brand, "ecsb")) { | |
59 base::FieldTrialList::CreateFieldTrial(kSyncPromoEnabledTrialName, | |
60 kSyncPromoDisabledWithApps); | |
61 } else if (LowerCaseEqualsASCII(brand, "ecbb")) { | |
62 base::FieldTrialList::CreateFieldTrial(kSyncPromoEnabledTrialName, | |
63 kSyncPromoDisabledWithoutApps); | |
64 } | |
Dan Beam
2011/12/14 01:22:12
By the way, the reason I'm not interlacing these w
| |
38 } | 65 } |
39 | 66 |
40 bool IsExperimentActive() { | 67 bool IsExperimentActive() { |
41 return base::FieldTrialList::FindValue(kSyncPromoMsgTrialName) != | 68 return base::FieldTrialList::FindValue(kSyncPromoMsgTrialName) != |
42 base::FieldTrial::kNotFinalized; | 69 base::FieldTrial::kNotFinalized; |
43 } | 70 } |
44 | 71 |
72 bool IsPartOfBrandTrialToEnable() { | |
73 return base::FieldTrialList::TrialExists(kSyncPromoEnabledTrialName); | |
74 } | |
75 | |
45 Group GetGroup() { | 76 Group GetGroup() { |
46 // Promo message A is also the default value, so display it if there is no | 77 // Promo message A is also the default value, so display it if there is no |
47 // active experiment. | 78 // active experiment. |
48 if (!IsExperimentActive()) | 79 if (!IsExperimentActive()) |
49 return PROMO_MSG_A; | 80 return PROMO_MSG_A; |
50 | 81 |
51 const int group = base::FieldTrialList::FindValue(kSyncPromoMsgTrialName); | 82 const int group = base::FieldTrialList::FindValue(kSyncPromoMsgTrialName); |
52 if (group == g_sync_promo_experiment_a) | 83 if (group == g_sync_promo_experiment_a) |
53 return PROMO_MSG_A; | 84 return PROMO_MSG_A; |
54 else if (group == g_sync_promo_experiment_b) | 85 else if (group == g_sync_promo_experiment_b) |
55 return PROMO_MSG_B; | 86 return PROMO_MSG_B; |
56 else if (group == g_sync_promo_experiment_c) | 87 else if (group == g_sync_promo_experiment_c) |
57 return PROMO_MSG_C; | 88 return PROMO_MSG_C; |
58 else if (group == g_sync_promo_experiment_d) | 89 else if (group == g_sync_promo_experiment_d) |
59 return PROMO_MSG_D; | 90 return PROMO_MSG_D; |
60 | 91 |
61 NOTREACHED(); | 92 NOTREACHED(); |
62 return PROMO_MSG_A; | 93 return PROMO_MSG_A; |
63 } | 94 } |
64 | 95 |
96 int GetSyncPromoAndDefaultAppsCombination() { | |
97 // This should never happen, but it doesn't hurt to CHECK(). | |
98 DCHECK(IsPartOfBrandTrialToEnable()); | |
99 | |
100 std::string group = | |
101 base::FieldTrialList::Find(kSyncPromoEnabledTrialName)->group_name(); | |
102 | |
103 if (group == kSyncPromoEnabledWithApps) | |
104 return WITH_SYNC_PROMO_WITH_DEFAULT_APPS; | |
105 else if (group == kSyncPromoEnabledWithoutApps) | |
106 return WITH_SYNC_PROMO_WITHOUT_DEFAULT_APPS; | |
107 else if (group == kSyncPromoDisabledWithApps) | |
108 return WITHOUT_SYNC_PROMO_WITH_DEFAULT_APPS; | |
109 else if (group == kSyncPromoDisabledWithoutApps) | |
110 return WITH_SYNC_PROMO_WITH_DEFAULT_APPS; | |
111 | |
112 NOTREACHED(); | |
113 return SYNC_PROMO_AND_DEFAULT_APPS_BOUNDARY + 1; | |
114 } | |
115 | |
65 int GetMessageBodyResID() { | 116 int GetMessageBodyResID() { |
66 // Note that GetGroup and the switch will take care of the !IsExperimentActive | 117 // Note that GetGroup and the switch will take care of the !IsExperimentActive |
67 // case for us. | 118 // case for us. |
68 Group group = GetGroup(); | 119 Group group = GetGroup(); |
69 switch (group) { | 120 switch (group) { |
70 case PROMO_MSG_A: | 121 case PROMO_MSG_A: |
71 return IDS_SYNC_PROMO_MESSAGE_BODY_A; | 122 return IDS_SYNC_PROMO_MESSAGE_BODY_A; |
72 case PROMO_MSG_B: | 123 case PROMO_MSG_B: |
73 return IDS_SYNC_PROMO_MESSAGE_BODY_B; | 124 return IDS_SYNC_PROMO_MESSAGE_BODY_B; |
74 case PROMO_MSG_C: | 125 case PROMO_MSG_C: |
75 return IDS_SYNC_PROMO_MESSAGE_BODY_C; | 126 return IDS_SYNC_PROMO_MESSAGE_BODY_C; |
76 case PROMO_MSG_D: | 127 case PROMO_MSG_D: |
77 return IDS_SYNC_PROMO_MESSAGE_BODY_D; | 128 return IDS_SYNC_PROMO_MESSAGE_BODY_D; |
78 case PROMO_MSG_MAX: | 129 case PROMO_MSG_MAX: |
79 break; | 130 break; |
80 } | 131 } |
81 | 132 |
82 NOTREACHED(); | 133 NOTREACHED(); |
83 return IDS_SYNC_PROMO_MESSAGE_BODY_A; | 134 return IDS_SYNC_PROMO_MESSAGE_BODY_A; |
84 } | 135 } |
85 | 136 |
86 void RecordUserSawMessage() { | 137 void RecordUserSawMessage() { |
87 DCHECK(IsExperimentActive()); | 138 DCHECK(IsExperimentActive()); |
88 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageDisplayed", | 139 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageDisplayed", |
89 GetGroup(), | 140 GetGroup(), |
90 PROMO_MSG_MAX); | 141 PROMO_MSG_MAX); |
91 } | 142 } |
92 | 143 |
144 void RecordUserShownPromoWithTrialBrand() { | |
145 DCHECK(IsPartOfBrandTrialToEnable()); | |
146 UMA_HISTOGRAM_ENUMERATION("SyncPromo.ShownPromoWithBrand", | |
147 GetSyncPromoAndDefaultAppsCombination(), | |
148 SYNC_PROMO_AND_DEFAULT_APPS_BOUNDARY); | |
149 } | |
150 | |
93 void RecordUserSignedIn() { | 151 void RecordUserSignedIn() { |
94 DCHECK(IsExperimentActive()); | 152 DCHECK(IsExperimentActive()); |
95 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageOnSignIn", | 153 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageOnSignIn", |
96 GetGroup(), | 154 GetGroup(), |
97 PROMO_MSG_MAX); | 155 PROMO_MSG_MAX); |
98 } | 156 } |
99 | 157 |
158 void RecordUserSignedInWithTrialBrand() { | |
159 DCHECK(IsPartOfBrandTrialToEnable()); | |
160 UMA_HISTOGRAM_ENUMERATION("SyncPromo.SignedInWithBrand", | |
161 GetSyncPromoAndDefaultAppsCombination(), | |
162 SYNC_PROMO_AND_DEFAULT_APPS_BOUNDARY); | |
163 } | |
164 | |
165 bool ShouldShowAtStartupBasedOnBrand() { | |
166 DCHECK(IsPartOfBrandTrialToEnable()); | |
167 std::string name = | |
168 base::FieldTrialList::Find(kSyncPromoEnabledTrialName)->group_name(); | |
169 return name == kSyncPromoEnabledWithApps || | |
170 name == kSyncPromoEnabledWithoutApps; | |
171 } | |
172 | |
100 } // namespace sync_promo_trial | 173 } // namespace sync_promo_trial |
OLD | NEW |