OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/sync_promo_trial.h" | |
6 | |
7 #include "base/metrics/field_trial.h" | |
8 #include "chrome/browser/metrics/metrics_service.h" | |
9 #include "chrome/browser/prefs/pref_service.h" | |
10 #include "grit/generated_resources.h" | |
11 | |
12 namespace sync_promo_trial { | |
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. See the .h | |
16 // file for what these groups represent. | |
17 int g_sync_promo_experiment_a = 0; | |
18 int g_sync_promo_experiment_b = 0; | |
19 int g_sync_promo_experiment_c = 0; | |
20 int g_sync_promo_experiment_d = 0; | |
21 | |
22 const char kSyncPromoMsgTrialName[] = "SyncPromoMsg"; | |
23 | |
24 void Activate() { | |
25 // The end date (February 21, 2012) is approximately 2 weeks into M17 stable. | |
26 scoped_refptr<base::FieldTrial> trial( | |
27 new base::FieldTrial(kSyncPromoMsgTrialName, 1000, "MsgA", 2012, 2, 21)); | |
28 g_sync_promo_experiment_a = base::FieldTrial::kDefaultGroupNumber; | |
29 | |
30 // Try to give the user a consistent experience, if possible. | |
31 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | |
32 trial->UseOneTimeRandomization(); | |
33 | |
34 // Each group has probability 0.5%, leaving the control with 98.5%. | |
35 g_sync_promo_experiment_b = trial->AppendGroup("MsgB", 50); | |
36 g_sync_promo_experiment_c = trial->AppendGroup("MsgC", 50); | |
37 g_sync_promo_experiment_d = trial->AppendGroup("MsgD", 50); | |
38 } | |
39 | |
40 bool IsExperimentActive() { | |
41 return base::FieldTrialList::FindValue(kSyncPromoMsgTrialName) != | |
42 base::FieldTrial::kNotFinalized; | |
43 } | |
44 | |
45 Group GetGroup() { | |
46 // Promo message A is also the default value, so display it if there is no | |
47 // active experiment. | |
48 if (!IsExperimentActive()) | |
49 return PROMO_MSG_A; | |
50 | |
51 const int group = base::FieldTrialList::FindValue(kSyncPromoMsgTrialName); | |
52 if (group == g_sync_promo_experiment_a) | |
53 return PROMO_MSG_A; | |
54 else if (group == g_sync_promo_experiment_b) | |
55 return PROMO_MSG_B; | |
56 else if (group == g_sync_promo_experiment_c) | |
57 return PROMO_MSG_C; | |
58 else if (group == g_sync_promo_experiment_d) | |
59 return PROMO_MSG_D; | |
60 | |
61 NOTREACHED(); | |
62 return PROMO_MSG_A; | |
63 } | |
64 | |
65 int GetMessageBodyResID() { | |
66 // Note that GetGroup and the switch will take care of the !IsExperimentActive | |
67 // case for us. | |
68 Group group = GetGroup(); | |
69 switch (group) { | |
70 case PROMO_MSG_A: | |
71 return IDS_SYNC_PROMO_MESSAGE_BODY_A; | |
72 case PROMO_MSG_B: | |
73 return IDS_SYNC_PROMO_MESSAGE_BODY_B; | |
74 case PROMO_MSG_C: | |
75 return IDS_SYNC_PROMO_MESSAGE_BODY_C; | |
76 case PROMO_MSG_D: | |
77 return IDS_SYNC_PROMO_MESSAGE_BODY_D; | |
78 case PROMO_MSG_MAX: | |
79 break; | |
80 } | |
81 | |
82 NOTREACHED(); | |
83 return IDS_SYNC_PROMO_MESSAGE_BODY_A; | |
84 } | |
85 | |
86 void RecordUserSawMessage() { | |
87 DCHECK(IsExperimentActive()); | |
88 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageDisplayed", | |
89 GetGroup(), | |
90 PROMO_MSG_MAX); | |
91 } | |
92 | |
93 void RecordUserSignedIn() { | |
94 DCHECK(IsExperimentActive()); | |
95 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageOnSignIn", | |
96 GetGroup(), | |
97 PROMO_MSG_MAX); | |
98 } | |
99 | |
100 } // namespace sync_promo_trial | |
OLD | NEW |