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