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

Unified Diff: components/ntp_tiles/field_trial.cc

Issue 2484233002: Hard coded finch config for Popular site (Closed)
Patch Set: Created 4 years, 1 month 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: components/ntp_tiles/field_trial.cc
diff --git a/components/ntp_tiles/field_trial.cc b/components/ntp_tiles/field_trial.cc
new file mode 100644
index 0000000000000000000000000000000000000000..779b5b85953135f38dcbd633fe17a5e56fb5ccef
--- /dev/null
+++ b/components/ntp_tiles/field_trial.cc
@@ -0,0 +1,82 @@
+// Copyright 2016 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 "base/metrics/field_trial.h"
+
+#if defined(OS_ANDROID)
+#include <jni.h>
+#endif
+
+#include "base/command_line.h"
+#include "base/metrics/field_trial.h"
+#include "base/strings/string_util.h"
+#include "components/ntp_tiles/constants.h"
+#include "components/ntp_tiles/field_trial.h"
+#include "components/ntp_tiles/switches.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/jni_android.h"
+#include "jni/MostVisitedSites_jni.h"
+#endif
+
+const char kPopularSiteDefaultGroup[] = "Default";
+const char kPopularSiteControlGroup[] = "Control";
+const char kPopularSiteEnabledGroup[] = "Enabled";
+const char kPopularSiteEnabledCommandLineSwitchGroup[] =
+ "EnabledWithCommandLineSwitch";
+const char kPopularSiteDisabledCommandLineSwitchGroup[] =
+ "DisabledWithCommandLineSwitch";
+
+void ntp_tiles::SetUpFirstLaunchFieldTrial(bool is_stable_channel) {
rkaplow 2016/11/10 22:56:46 can you comment this is done as a workaround since
noyau (Ping after 24h) 2016/11/14 17:08:08 Done.
+ // Stable channels will run with 10% probability.
rkaplow 2016/11/10 22:56:46 this is higher a % that we usually experiment on s
noyau (Ping after 24h) 2016/11/14 17:08:08 Not on iOS, were volume are low compared to deskto
rkaplow 2016/11/14 23:42:51 Ok.. in either case this will need to get approval
noyau (Ping after 24h) 2016/11/15 09:05:50 The highlight is already there: The first sentence
+ // Non-stable channels will run with 50% probability.
+ const base::FieldTrial::Probability kTotalProbability = 100;
+ const base::FieldTrial::Probability kEnabledAndControlProbability =
+ is_stable_channel ? 10 : 50;
+
+ // Experiment enabled until March 15, 2017. By default, disabled.
noyau (Ping after 24h) 2016/11/09 10:56:39 Before creating the new experiment should I check
rkaplow 2016/11/10 22:56:46 I think it would make sense to check in case here
noyau (Ping after 24h) 2016/11/14 17:08:08 Is Find the correct way to test for this without t
rkaplow 2016/11/14 23:42:51 I think TrialExists should work since we don't nee
noyau (Ping after 24h) 2016/11/15 09:05:50 Done.
+ scoped_refptr<base::FieldTrial> trial(
+ base::FieldTrialList::FactoryGetFieldTrial(
+ kPopularSitesFieldTrialName, kTotalProbability,
+ kPopularSiteDefaultGroup, 2017, 3, 15, // Mar 15, 2017
+ base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
+
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(ntp_tiles::switches::kEnableNTPPopularSites)) {
+ trial->AppendGroup(kPopularSiteEnabledCommandLineSwitchGroup,
+ kTotalProbability);
+ } else if (command_line->HasSwitch(
+ ntp_tiles::switches::kDisableNTPPopularSites)) {
+ trial->AppendGroup(kPopularSiteDisabledCommandLineSwitchGroup,
+ kTotalProbability);
+ } else {
+ trial->AppendGroup(kPopularSiteControlGroup, kEnabledAndControlProbability);
+ trial->AppendGroup(kPopularSiteEnabledGroup, kEnabledAndControlProbability);
+ }
+ trial->group();
+}
+
+bool ntp_tiles::ShouldShowPopularSites() {
+ // Note: It's important to query the field trial state first, to ensure that
+ // UMA reports the correct group.
+ const std::string group_name =
+ base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName);
+
+ base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
+ if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites))
+ return false;
+
+ if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites))
+ return true;
+
+#if defined(OS_ANDROID)
+ if (Java_MostVisitedSites_isPopularSitesForceEnabled(
+ base::android::AttachCurrentThread())) {
+ return true;
+ }
+#endif
+
+ return base::StartsWith(group_name, "Enabled",
+ base::CompareCase::INSENSITIVE_ASCII);
+}

Powered by Google App Engine
This is Rietveld 408576698