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/instant/instant_field_trial.h" |
| 6 |
| 7 #include "base/metrics/field_trial.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const char kTrialId[] = "Instant"; |
| 15 |
| 16 int kControl1 = 0; |
| 17 int kControl2 = 0; |
| 18 int kExperiment1 = 0; |
| 19 int kExperiment2 = 0; |
| 20 |
| 21 // Returns true if the user is in one of the given groups in the field trial. |
| 22 bool IsGroup(Profile* profile, const int group1, const int group2) { |
| 23 if (profile->IsOffTheRecord()) |
| 24 return false; |
| 25 |
| 26 const PrefService* prefs = profile->GetPrefs(); |
| 27 if (prefs && |
| 28 (prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
| 29 prefs->IsManagedPreference(prefs::kInstantEnabled))) { |
| 30 return false; |
| 31 } |
| 32 |
| 33 const int group = base::FieldTrialList::FindValue(kTrialId); |
| 34 return group != base::FieldTrial::kNotFinalized && |
| 35 group != base::FieldTrial::kDefaultGroupNumber && |
| 36 (group == group1 || group == group2); |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 namespace instant_field_trial { |
| 42 |
| 43 void Init() { |
| 44 scoped_refptr<base::FieldTrial> trial( |
| 45 new base::FieldTrial(kTrialId, 1000, "InstantDefault", 2011, 9, 30)); |
| 46 if (!base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
| 47 return; |
| 48 |
| 49 trial->UseOneTimeRandomization(); |
| 50 |
| 51 kControl1 = trial->AppendGroup("InstantControl1", 250); |
| 52 kControl2 = trial->AppendGroup("InstantControl2", 250); |
| 53 kExperiment1 = trial->AppendGroup("InstantExperiment1", 250); |
| 54 kExperiment2 = trial->AppendGroup("InstantExperiment2", 250); |
| 55 } |
| 56 |
| 57 bool IsExperiment(Profile* profile) { |
| 58 return IsGroup(profile, kExperiment1, kExperiment2); |
| 59 } |
| 60 |
| 61 bool IsControl(Profile* profile) { |
| 62 return IsGroup(profile, kControl1, kControl2); |
| 63 } |
| 64 |
| 65 std::string GetGroupName(Profile* profile) { |
| 66 if (profile->IsOffTheRecord()) |
| 67 return "InstantIncognito"; |
| 68 |
| 69 const PrefService* prefs = profile->GetPrefs(); |
| 70 if (prefs && |
| 71 (prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
| 72 prefs->IsManagedPreference(prefs::kInstantEnabled))) { |
| 73 return prefs->GetBoolean(prefs::kInstantEnabled) ? "InstantEnabled" |
| 74 : "InstantDisabled"; |
| 75 } |
| 76 |
| 77 return base::FieldTrialList::FindFullName(kTrialId); |
| 78 } |
| 79 |
| 80 } // namespace instant_field_trial |
OLD | NEW |