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 "grit/generated_resources.h" |
| 13 |
| 14 namespace sync_promo_trial { |
| 15 |
| 16 // Field trial IDs of the control and experiment groups. Though they are not |
| 17 // literally "const", they are set only once, in Activate() below. See the .h |
| 18 // file for what these groups represent. |
| 19 int g_sync_promo_experiment_a = 0; |
| 20 int g_sync_promo_experiment_b = 0; |
| 21 int g_sync_promo_experiment_c = 0; |
| 22 int g_sync_promo_experiment_d = 0; |
| 23 |
| 24 const char kSyncPromoEnabledTrialName[] = "SyncPromoEnabled"; |
| 25 const char kSyncPromoMsgTrialName[] = "SyncPromoMsg"; |
| 26 |
| 27 const char kSyncPromoEnabledWithApps[] = "EnabledWithDefaultApps"; |
| 28 const char kSyncPromoEnabledWithoutApps[] = "EnabledWithoutDefaultApps"; |
| 29 const char kSyncPromoDisabledWithoutAppsA[] = "DisabledWithoutDefaultAppsA"; |
| 30 const char kSyncPromoDisabledWithoutAppsB[] = "DisabledWithoutDefaultAppsB"; |
| 31 |
| 32 void Activate() { |
| 33 // The end date (February 21, 2012) is approximately 2 weeks into M17 stable. |
| 34 scoped_refptr<base::FieldTrial> trial( |
| 35 new base::FieldTrial(kSyncPromoMsgTrialName, 1000, "MsgA", 2012, 2, 21)); |
| 36 g_sync_promo_experiment_a = base::FieldTrial::kDefaultGroupNumber; |
| 37 |
| 38 // Try to give the user a consistent experience, if possible. |
| 39 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
| 40 trial->UseOneTimeRandomization(); |
| 41 |
| 42 // Each group has probability 0.5%, leaving the control with 98.5%. |
| 43 g_sync_promo_experiment_b = trial->AppendGroup("MsgB", 50); |
| 44 g_sync_promo_experiment_c = trial->AppendGroup("MsgC", 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 kSyncPromoDisabledWithoutAppsA); |
| 61 } else if (LowerCaseEqualsASCII(brand, "ecbb")) { |
| 62 base::FieldTrialList::CreateFieldTrial(kSyncPromoEnabledTrialName, |
| 63 kSyncPromoDisabledWithoutAppsB); |
| 64 } |
| 65 } |
| 66 |
| 67 bool IsExperimentActive() { |
| 68 return base::FieldTrialList::FindValue(kSyncPromoMsgTrialName) != |
| 69 base::FieldTrial::kNotFinalized; |
| 70 } |
| 71 |
| 72 bool IsPartOfBrandTrialToEnable() { |
| 73 return base::FieldTrialList::TrialExists(kSyncPromoEnabledTrialName); |
| 74 } |
| 75 |
| 76 Group GetGroup() { |
| 77 // Promo message A is also the default value, so display it if there is no |
| 78 // active experiment. |
| 79 if (!IsExperimentActive()) |
| 80 return PROMO_MSG_A; |
| 81 |
| 82 const int group = base::FieldTrialList::FindValue(kSyncPromoMsgTrialName); |
| 83 if (group == g_sync_promo_experiment_a) |
| 84 return PROMO_MSG_A; |
| 85 else if (group == g_sync_promo_experiment_b) |
| 86 return PROMO_MSG_B; |
| 87 else if (group == g_sync_promo_experiment_c) |
| 88 return PROMO_MSG_C; |
| 89 else if (group == g_sync_promo_experiment_d) |
| 90 return PROMO_MSG_D; |
| 91 |
| 92 NOTREACHED(); |
| 93 return PROMO_MSG_A; |
| 94 } |
| 95 |
| 96 int GetSyncPromoBrandUMABucketFromGroup() { |
| 97 DCHECK(IsPartOfBrandTrialToEnable()); |
| 98 |
| 99 std::string group = |
| 100 base::FieldTrialList::Find(kSyncPromoEnabledTrialName)->group_name(); |
| 101 |
| 102 if (group == kSyncPromoEnabledWithApps) |
| 103 return WITH_SYNC_PROMO_WITH_DEFAULT_APPS; |
| 104 else if (group == kSyncPromoEnabledWithoutApps) |
| 105 return WITH_SYNC_PROMO_WITHOUT_DEFAULT_APPS; |
| 106 else if (group == kSyncPromoDisabledWithoutAppsA) |
| 107 return WITHOUT_SYNC_PROMO_WITHOUT_DEFAULT_APPS_A; |
| 108 else if (group == kSyncPromoDisabledWithoutAppsB) |
| 109 return WITHOUT_SYNC_PROMO_WITHOUT_DEFAULT_APPS_B; |
| 110 |
| 111 NOTREACHED(); |
| 112 return SYNC_PROMO_AND_DEFAULT_APPS_BOUNDARY + 1; |
| 113 } |
| 114 |
| 115 int GetMessageBodyResID() { |
| 116 // Note that GetGroup and the switch will take care of the !IsExperimentActive |
| 117 // case for us. |
| 118 Group group = GetGroup(); |
| 119 switch (group) { |
| 120 case PROMO_MSG_A: |
| 121 return IDS_SYNC_PROMO_MESSAGE_BODY_A; |
| 122 case PROMO_MSG_B: |
| 123 return IDS_SYNC_PROMO_MESSAGE_BODY_B; |
| 124 case PROMO_MSG_C: |
| 125 return IDS_SYNC_PROMO_MESSAGE_BODY_C; |
| 126 case PROMO_MSG_D: |
| 127 return IDS_SYNC_PROMO_MESSAGE_BODY_D; |
| 128 case PROMO_MSG_MAX: |
| 129 break; |
| 130 } |
| 131 |
| 132 NOTREACHED(); |
| 133 return IDS_SYNC_PROMO_MESSAGE_BODY_A; |
| 134 } |
| 135 |
| 136 void RecordUserSawMessage() { |
| 137 DCHECK(IsExperimentActive()); |
| 138 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageDisplayed", |
| 139 GetGroup(), |
| 140 PROMO_MSG_MAX); |
| 141 } |
| 142 |
| 143 void RecordUserShownPromoWithTrialBrand() { |
| 144 DCHECK(IsPartOfBrandTrialToEnable()); |
| 145 UMA_HISTOGRAM_ENUMERATION("SyncPromo.ShownPromoWithBrand", |
| 146 GetSyncPromoBrandUMABucketFromGroup(), |
| 147 SYNC_PROMO_AND_DEFAULT_APPS_BOUNDARY); |
| 148 } |
| 149 |
| 150 void RecordUserSignedIn() { |
| 151 DCHECK(IsExperimentActive()); |
| 152 UMA_HISTOGRAM_ENUMERATION("SyncPromo.MessageOnSignIn", |
| 153 GetGroup(), |
| 154 PROMO_MSG_MAX); |
| 155 } |
| 156 |
| 157 void RecordUserSignedInWithTrialBrand() { |
| 158 DCHECK(IsPartOfBrandTrialToEnable()); |
| 159 UMA_HISTOGRAM_ENUMERATION("SyncPromo.SignedInWithBrand", |
| 160 GetSyncPromoBrandUMABucketFromGroup(), |
| 161 SYNC_PROMO_AND_DEFAULT_APPS_BOUNDARY); |
| 162 } |
| 163 |
| 164 bool ShouldShowAtStartupBasedOnBrand() { |
| 165 DCHECK(IsPartOfBrandTrialToEnable()); |
| 166 std::string name = |
| 167 base::FieldTrialList::Find(kSyncPromoEnabledTrialName)->group_name(); |
| 168 return name == kSyncPromoEnabledWithApps || |
| 169 name == kSyncPromoEnabledWithoutApps; |
| 170 } |
| 171 |
| 172 } // namespace sync_promo_trial |
OLD | NEW |