Chromium Code Reviews| 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/instant/instant_field_trial.h" | 5 #include "chrome/browser/instant/instant_field_trial.h" |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | |
| 7 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 bool field_trial_active_ = false; | 13 |
| 14 int kControlGroupId1 = 0; | |
|
sky
2011/08/08 16:10:54
Add descriptions. Using kFoo implies these are con
sreeram
2011/08/08 16:30:10
Done.
| |
| 15 int kControlGroupId2 = 0; | |
| 16 int kExperimentGroupId1 = 0; | |
| 17 int kExperimentGroupId2 = 0; | |
| 18 | |
| 13 } | 19 } |
| 14 | 20 |
| 15 // static | 21 // static |
| 16 void InstantFieldTrial::Activate() { | 22 void InstantFieldTrial::Activate() { |
| 17 field_trial_active_ = true; | 23 scoped_refptr<base::FieldTrial> trial( |
| 24 new base::FieldTrial("Instant", 10000, "InstantInactive", 2012, 1, 1)); | |
| 25 | |
| 26 if (!base::FieldTrialList::IsOneTimeRandomizationEnabled()) | |
| 27 return; | |
| 28 trial->UseOneTimeRandomization(); | |
| 29 | |
| 30 kControlGroupId1 = trial->AppendGroup("InstantControl1", 4500); // 45% | |
| 31 kControlGroupId2 = trial->AppendGroup("InstantControl2", 4500); // 45% | |
| 32 kExperimentGroupId1 = trial->AppendGroup("InstantExperiment1", 500); // 5% | |
| 33 kExperimentGroupId2 = trial->AppendGroup("InstantExperiment2", 500); // 5% | |
| 18 } | 34 } |
| 19 | 35 |
| 20 // static | 36 // static |
| 21 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { | 37 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { |
| 22 if (!field_trial_active_) | |
| 23 return INACTIVE; | |
| 24 | |
| 25 if (profile->IsOffTheRecord()) | 38 if (profile->IsOffTheRecord()) |
| 26 return INACTIVE; | 39 return INACTIVE; |
| 27 | 40 |
| 28 const PrefService* prefs = profile->GetPrefs(); | 41 const PrefService* prefs = profile->GetPrefs(); |
| 29 if (!prefs || | 42 if (!prefs || |
| 30 prefs->GetBoolean(prefs::kInstantEnabledOnce) || | 43 prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
| 31 prefs->IsManagedPreference(prefs::kInstantEnabled)) { | 44 prefs->IsManagedPreference(prefs::kInstantEnabled)) { |
| 32 return INACTIVE; | 45 return INACTIVE; |
| 33 } | 46 } |
| 34 | 47 |
| 35 const int random = prefs->GetInteger(prefs::kInstantFieldTrialRandomDraw); | 48 const int group = base::FieldTrialList::FindValue("Instant"); |
| 36 return random < 4500 ? CONTROL1 : // 45% | 49 |
| 37 random < 9000 ? CONTROL2 : // 45% | 50 if (group == base::FieldTrial::kNotFinalized || |
| 38 random < 9500 ? EXPERIMENT1 // 5% | 51 group == base::FieldTrial::kDefaultGroupNumber) { |
| 39 : EXPERIMENT2; // 5% | 52 return INACTIVE; |
| 53 } | |
| 54 | |
| 55 if (group == kControlGroupId1) { | |
|
sky
2011/08/08 16:10:54
no {}
sreeram
2011/08/08 16:30:10
Done.
| |
| 56 return CONTROL1; | |
| 57 } else if (group == kControlGroupId2) { | |
| 58 return CONTROL2; | |
| 59 } else if (group == kExperimentGroupId1) { | |
| 60 return EXPERIMENT1; | |
| 61 } else if (group == kExperimentGroupId2) { | |
| 62 return EXPERIMENT2; | |
| 63 } else { | |
| 64 return INACTIVE; | |
| 65 } | |
| 40 } | 66 } |
| 41 | 67 |
| 42 // static | 68 // static |
| 43 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { | 69 bool InstantFieldTrial::IsExperimentGroup(Profile* profile) { |
| 44 Group group = GetGroup(profile); | 70 Group group = GetGroup(profile); |
| 45 return group == EXPERIMENT1 || group == EXPERIMENT2; | 71 return group == EXPERIMENT1 || group == EXPERIMENT2; |
| 46 } | 72 } |
| 47 | 73 |
| 48 // static | 74 // static |
| 49 std::string InstantFieldTrial::GetGroupName(Profile* profile) { | 75 std::string InstantFieldTrial::GetGroupName(Profile* profile) { |
| 50 switch (GetGroup(profile)) { | 76 switch (GetGroup(profile)) { |
| 51 case INACTIVE: return "InstantInactive"; | 77 case INACTIVE: return "InstantInactive"; |
| 52 case CONTROL1: return "InstantControl1"; | 78 case CONTROL1: return "InstantControl1"; |
| 53 case CONTROL2: return "InstantControl2"; | 79 case CONTROL2: return "InstantControl2"; |
| 54 case EXPERIMENT1: return "InstantExperiment1"; | 80 case EXPERIMENT1: return "InstantExperiment1"; |
| 55 case EXPERIMENT2: return "InstantExperiment2"; | 81 case EXPERIMENT2: return "InstantExperiment2"; |
| 56 } | 82 } |
| 57 NOTREACHED(); | 83 NOTREACHED(); |
| 58 return "InstantUnknown"; | 84 return "InstantUnknown"; |
| 59 } | 85 } |
| OLD | NEW |