OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/metrics/field_trial.h" |
| 6 |
| 7 #if defined(OS_ANDROID) |
| 8 #include <jni.h> |
| 9 #endif |
| 10 |
| 11 #include "base/command_line.h" |
| 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/strings/string_util.h" |
| 14 #include "components/ntp_tiles/constants.h" |
| 15 #include "components/ntp_tiles/field_trial.h" |
| 16 #include "components/ntp_tiles/switches.h" |
| 17 |
| 18 #if defined(OS_ANDROID) |
| 19 #include "base/android/jni_android.h" |
| 20 #include "jni/MostVisitedSites_jni.h" |
| 21 #endif |
| 22 |
| 23 namespace { |
| 24 const char kPopularSiteDefaultGroup[] = "Default"; |
| 25 const char kPopularSiteControlGroup[] = "Control"; |
| 26 const char kPopularSiteEnabledGroup[] = "Enabled"; |
| 27 const char kPopularSiteEnabledCommandLineSwitchGroup[] = |
| 28 "EnabledWithCommandLineSwitch"; |
| 29 const char kPopularSiteDisabledCommandLineSwitchGroup[] = |
| 30 "DisabledWithCommandLineSwitch"; |
| 31 } // namespace |
| 32 |
| 33 namespace ntp_tiles { |
| 34 |
| 35 // On iOS it is not technically possible to prep the field trials on first |
| 36 // launch, the configuration file is downloaded too late. In order to run some |
| 37 // experiments that need to be active on first launch to be meaningful these |
| 38 // are hardcoded, but can be superceeded by a server side config on subsequent |
| 39 // launches. |
| 40 void SetUpFirstLaunchFieldTrial(bool is_stable_channel) { |
| 41 // Check first if a server side config superceeded this experiment. |
| 42 if (base::FieldTrialList::TrialExists(kPopularSitesFieldTrialName)) |
| 43 return; |
| 44 |
| 45 // Stable channels will run with 10% probability. |
| 46 // Non-stable channels will run with 50% probability. |
| 47 const base::FieldTrial::Probability kTotalProbability = 100; |
| 48 const base::FieldTrial::Probability kEnabledAndControlProbability = |
| 49 is_stable_channel ? 10 : 50; |
| 50 |
| 51 // Experiment enabled until March 15, 2017. By default, disabled. |
| 52 scoped_refptr<base::FieldTrial> trial( |
| 53 base::FieldTrialList::FactoryGetFieldTrial( |
| 54 kPopularSitesFieldTrialName, kTotalProbability, |
| 55 kPopularSiteDefaultGroup, 2017, 3, 15, // Mar 15, 2017 |
| 56 base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr)); |
| 57 |
| 58 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 59 if (command_line->HasSwitch(ntp_tiles::switches::kEnableNTPPopularSites)) { |
| 60 trial->AppendGroup(kPopularSiteEnabledCommandLineSwitchGroup, |
| 61 kTotalProbability); |
| 62 } else if (command_line->HasSwitch( |
| 63 ntp_tiles::switches::kDisableNTPPopularSites)) { |
| 64 trial->AppendGroup(kPopularSiteDisabledCommandLineSwitchGroup, |
| 65 kTotalProbability); |
| 66 } else { |
| 67 trial->AppendGroup(kPopularSiteControlGroup, kEnabledAndControlProbability); |
| 68 trial->AppendGroup(kPopularSiteEnabledGroup, kEnabledAndControlProbability); |
| 69 } |
| 70 } |
| 71 |
| 72 bool ShouldShowPopularSites() { |
| 73 // Note: It's important to query the field trial state first, to ensure that |
| 74 // UMA reports the correct group. |
| 75 const std::string group_name = |
| 76 base::FieldTrialList::FindFullName(kPopularSitesFieldTrialName); |
| 77 |
| 78 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 79 if (cmd_line->HasSwitch(switches::kDisableNTPPopularSites)) |
| 80 return false; |
| 81 |
| 82 if (cmd_line->HasSwitch(switches::kEnableNTPPopularSites)) |
| 83 return true; |
| 84 |
| 85 #if defined(OS_ANDROID) |
| 86 if (Java_MostVisitedSites_isPopularSitesForceEnabled( |
| 87 base::android::AttachCurrentThread())) { |
| 88 return true; |
| 89 } |
| 90 #endif |
| 91 |
| 92 return base::StartsWith(group_name, "Enabled", |
| 93 base::CompareCase::INSENSITIVE_ASCII); |
| 94 } |
| 95 |
| 96 } // namespace ntp_tiles |
OLD | NEW |