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