Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Unified Diff: chrome/browser/instant/instant_field_trial.cc

Issue 7337007: Introduce a field trial for Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/instant/instant_field_trial.cc
diff --git a/chrome/browser/instant/instant_field_trial.cc b/chrome/browser/instant/instant_field_trial.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1b0f59a3c23342f42d8a9eb6a4a689cda1440a3b
--- /dev/null
+++ b/chrome/browser/instant/instant_field_trial.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/instant/instant_field_trial.h"
+
+#include "base/metrics/field_trial.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+
+namespace {
+
+const char kTrialId[] = "Instant";
+
+int kControl1 = 0;
+int kControl2 = 0;
+int kExperiment1 = 0;
+int kExperiment2 = 0;
+
+// Returns true if the user is in one of the given groups in the field trial.
+bool IsGroup(Profile* profile, const int group1, const int group2) {
+ if (profile->IsOffTheRecord())
+ return false;
+
+ const PrefService* prefs = profile->GetPrefs();
+ if (prefs &&
+ (prefs->GetBoolean(prefs::kInstantEnabledOnce) ||
+ prefs->IsManagedPreference(prefs::kInstantEnabled))) {
+ return false;
+ }
+
+ const int group = base::FieldTrialList::FindValue(kTrialId);
+ return group != base::FieldTrial::kNotFinalized &&
+ group != base::FieldTrial::kDefaultGroupNumber &&
+ (group == group1 || group == group2);
+}
+
+} // namespace
+
+namespace instant_field_trial {
+
+void Init() {
+ scoped_refptr<base::FieldTrial> trial(
+ new base::FieldTrial(kTrialId, 1000, "InstantDefault", 2011, 9, 30));
+ if (!base::FieldTrialList::IsOneTimeRandomizationEnabled())
+ return;
+
+ trial->UseOneTimeRandomization();
+
+ kControl1 = trial->AppendGroup("InstantControl1", 250);
+ kControl2 = trial->AppendGroup("InstantControl2", 250);
+ kExperiment1 = trial->AppendGroup("InstantExperiment1", 250);
+ kExperiment2 = trial->AppendGroup("InstantExperiment2", 250);
+}
+
+bool IsExperiment(Profile* profile) {
+ return IsGroup(profile, kExperiment1, kExperiment2);
+}
+
+bool IsControl(Profile* profile) {
+ return IsGroup(profile, kControl1, kControl2);
+}
+
+std::string GetGroupName(Profile* profile) {
+ if (profile->IsOffTheRecord())
+ return "InstantIncognito";
+
+ const PrefService* prefs = profile->GetPrefs();
+ if (prefs &&
+ (prefs->GetBoolean(prefs::kInstantEnabledOnce) ||
+ prefs->IsManagedPreference(prefs::kInstantEnabled))) {
+ return prefs->GetBoolean(prefs::kInstantEnabled) ? "InstantEnabled"
+ : "InstantDisabled";
+ }
+
+ return base::FieldTrialList::FindFullName(kTrialId);
+}
+
+} // namespace instant_field_trial

Powered by Google App Engine
This is Rietveld 408576698