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

Side by Side Diff: components/ntp_tiles/field_trial.cc

Issue 2737573003: Remove Popular Sites experiment on iOS. (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « components/ntp_tiles/field_trial.h ('k') | ios/chrome/browser/ios_chrome_field_trials.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/metrics/field_trial.h" 5 #include "components/ntp_tiles/field_trial.h"
6 6
7 #if defined(OS_ANDROID) 7 #if defined(OS_ANDROID)
8 #include <jni.h> 8 #include <jni.h>
9 #endif 9 #endif
10 #include <string>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "components/ntp_tiles/constants.h" 15 #include "components/ntp_tiles/constants.h"
15 #include "components/ntp_tiles/field_trial.h"
16 #include "components/ntp_tiles/switches.h" 16 #include "components/ntp_tiles/switches.h"
17 #include "components/variations/variations_associated_data.h"
18 17
19 #if defined(OS_ANDROID) 18 #if defined(OS_ANDROID)
20 #include "base/android/jni_android.h" 19 #include "base/android/jni_android.h"
21 #include "jni/MostVisitedSites_jni.h" 20 #include "jni/MostVisitedSites_jni.h"
22 #endif 21 #endif
23 22
24 namespace {
25 const char kPopularSiteDefaultGroup[] = "Default";
26 const char kPopularSiteControlGroup[] = "Control";
27 const char kPopularSiteEnabledGroup[] = "Enabled";
28 const char kPopularSiteEnabledCommandLineSwitchGroup[] =
29 "EnabledWithCommandLineSwitch";
30 const char kPopularSiteDisabledCommandLineSwitchGroup[] =
31 "DisabledWithCommandLineSwitch";
32 } // namespace
33
34 namespace ntp_tiles { 23 namespace ntp_tiles {
35 24
36 // On iOS it is not technically possible to prep the field trials on first
37 // launch, the configuration file is downloaded too late. In order to run some
38 // experiments that need to be active on first launch to be meaningful these
39 // are hardcoded, but can be superceeded by a server side config on subsequent
40 // launches.
41 void SetUpFirstLaunchFieldTrial(bool is_stable_channel) {
42 // Check first if a server side config superceeded this experiment.
43 if (base::FieldTrialList::TrialExists(kPopularSitesFieldTrialName))
44 return;
45
46 // The experiment is only for stable channel, the other channels will simply
47 // get the default behavior.
48 if (!is_stable_channel)
49 return;
50
51 // Stable channels will run with 10% probability.
52 const base::FieldTrial::Probability kTotalProbability = 100;
53 const base::FieldTrial::Probability kEnabledAndControlProbability = 10;
54
55 // Experiment enabled until April 26, 2017.
56 scoped_refptr<base::FieldTrial> trial(
57 base::FieldTrialList::FactoryGetFieldTrial(
58 kPopularSitesFieldTrialName, kTotalProbability,
59 kPopularSiteDefaultGroup, 2017, 4, 26, // Apr 26, 2017
60 base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr));
61
62 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
63 if (command_line->HasSwitch(ntp_tiles::switches::kEnableNTPPopularSites)) {
64 trial->AppendGroup(kPopularSiteEnabledCommandLineSwitchGroup,
65 kTotalProbability);
66 } else if (command_line->HasSwitch(
67 ntp_tiles::switches::kDisableNTPPopularSites)) {
68 trial->AppendGroup(kPopularSiteDisabledCommandLineSwitchGroup,
69 kTotalProbability);
70 } else {
71 trial->AppendGroup(kPopularSiteControlGroup, kEnabledAndControlProbability);
72 AssociateGoogleVariationID(variations::GOOGLE_WEB_PROPERTIES,
73 kPopularSitesFieldTrialName,
74 kPopularSiteControlGroup, 3312959);
75 trial->AppendGroup(kPopularSiteEnabledGroup, kEnabledAndControlProbability);
76 AssociateGoogleVariationID(variations::GOOGLE_WEB_PROPERTIES,
77 kPopularSitesFieldTrialName,
78 kPopularSiteEnabledGroup, 3312958);
79 }
80 }
81
82 bool ShouldShowPopularSites() { 25 bool ShouldShowPopularSites() {
83 // Note: It's important to query the field trial state first, to ensure that 26 // Note: It's important to query the field trial state first, to ensure that
84 // UMA reports the correct group. 27 // UMA reports the correct group.
85 const std::string group_name = 28 const std::string group_name =
86 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName); 29 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName);
87 30
88 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 31 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
89 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) 32 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites))
90 return false; 33 return false;
91 34
92 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) 35 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites))
93 return true; 36 return true;
94 37
95 #if defined(OS_ANDROID) 38 #if defined(OS_ANDROID)
96 if (Java_MostVisitedSites_isPopularSitesForceEnabled( 39 if (Java_MostVisitedSites_isPopularSitesForceEnabled(
97 base::android::AttachCurrentThread())) { 40 base::android::AttachCurrentThread())) {
98 return true; 41 return true;
99 } 42 }
100 #endif 43 #endif
101 44
102 #if defined(OS_IOS) 45 #if defined(OS_IOS)
103 // On iOS, if not enrolled in the experiment, the default is to enable the 46 // On iOS, if not enrolled in the experiment, the default is to enable the
104 // feature. 47 // feature.
105 if (group_name.empty() || (group_name == kPopularSiteDefaultGroup)) 48 if (group_name.empty())
106 return true; 49 return true;
107 #endif 50 #endif
108 51
109 return base::StartsWith(group_name, "Enabled", 52 return base::StartsWith(group_name, "Enabled",
110 base::CompareCase::INSENSITIVE_ASCII); 53 base::CompareCase::INSENSITIVE_ASCII);
111 } 54 }
112 55
113 } // namespace ntp_tiles 56 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/field_trial.h ('k') | ios/chrome/browser/ios_chrome_field_trials.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698