droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 1 | // Copyright 2015 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 | // This file can be empty. Its purpose is to contain the relatively short lived |
| 6 | // definitions required for experimental flags. |
| 7 | |
| 8 | #include "ios/chrome/browser/experimental_flags.h" |
| 9 | |
rohitrao | 4b79d93 | 2015-12-02 19:37:38 | [diff] [blame] | 10 | #include <dispatch/dispatch.h> |
sdefresne | 60feea1 | 2015-06-04 08:39:51 | [diff] [blame] | 11 | #import <Foundation/Foundation.h> |
| 12 | |
lpromero | 6853727 | 2015-04-29 11:16:01 | [diff] [blame] | 13 | #include <string> |
| 14 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 15 | #include "base/command_line.h" |
vabr | 5b82ac3 | 2015-11-27 13:03:43 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
sdefresne | b53a987 | 2015-05-18 20:01:49 | [diff] [blame] | 17 | #include "base/strings/string_util.h" |
vabr | 5b82ac3 | 2015-11-27 13:03:43 | [diff] [blame] | 18 | #include "components/autofill/core/common/autofill_switches.h" |
lpromero | 6853727 | 2015-04-29 11:16:01 | [diff] [blame] | 19 | #include "components/variations/variations_associated_data.h" |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 20 | #include "ios/chrome/browser/chrome_switches.h" |
bzanotti | a5f249ed | 2015-06-24 10:02:59 | [diff] [blame] | 21 | #include "ios/web/public/web_view_creation_util.h" |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 22 | |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 23 | namespace { |
| 24 | NSString* const kEnableAlertOnBackgroundUpload = |
| 25 | @"EnableAlertsOnBackgroundUpload"; |
ioanap | 744ba198 | 2015-08-11 13:25:04 | [diff] [blame] | 26 | NSString* const kEnableViewCopyPasswords = @"EnableViewCopyPasswords"; |
vabr | 5b82ac3 | 2015-11-27 13:03:43 | [diff] [blame] | 27 | NSString* const kHeuristicsForPasswordGeneration = |
| 28 | @"HeuristicsForPasswordGeneration"; |
stkhapugin | 23ab73d8 | 2016-01-26 13:45:09 | [diff] [blame] | 29 | NSString* const kEnableReadingList = @"EnableReadingList"; |
jyquinn | c020e00 | 2016-07-06 15:21:25 | [diff] [blame] | 30 | NSString* const kUpdatePasswordUIEnabled = @"UpdatePasswordUIEnabled"; |
sklencarova | a066816e | 2016-07-11 16:09:46 | [diff] [blame] | 31 | NSString* const kEnableQRCodeReader = @"EnableQRCodeReader"; |
ioanap | d798d0b | 2016-07-27 16:33:46 | [diff] [blame] | 32 | NSString* const kEnableNewClearBrowsingDataUI = @"EnableNewClearBrowsingDataUI"; |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 33 | } // namespace |
| 34 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 35 | namespace experimental_flags { |
| 36 | |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 37 | bool IsAlertOnBackgroundUploadEnabled() { |
| 38 | return [[NSUserDefaults standardUserDefaults] |
| 39 | boolForKey:kEnableAlertOnBackgroundUpload]; |
| 40 | } |
| 41 | |
jbbegue | cba2cb0b | 2015-11-06 10:35:24 | [diff] [blame] | 42 | bool IsLRUSnapshotCacheEnabled() { |
| 43 | // Check if the experimental flag is forced on or off. |
| 44 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 45 | if (command_line->HasSwitch(switches::kEnableLRUSnapshotCache)) { |
| 46 | return true; |
| 47 | } else if (command_line->HasSwitch(switches::kDisableLRUSnapshotCache)) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | // Check if the finch experiment is turned on. |
| 52 | std::string group_name = |
| 53 | base::FieldTrialList::FindFullName("IOSLRUSnapshotCache"); |
| 54 | return base::StartsWith(group_name, "Enabled", |
| 55 | base::CompareCase::INSENSITIVE_ASCII); |
| 56 | } |
| 57 | |
ioanap | 744ba198 | 2015-08-11 13:25:04 | [diff] [blame] | 58 | bool IsViewCopyPasswordsEnabled() { |
| 59 | NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] |
| 60 | objectForKey:kEnableViewCopyPasswords]; |
| 61 | if ([viewCopyPasswordFlag isEqualToString:@"Enabled"]) |
| 62 | return true; |
| 63 | return false; |
| 64 | } |
| 65 | |
vabr | 5b82ac3 | 2015-11-27 13:03:43 | [diff] [blame] | 66 | bool IsPasswordGenerationEnabled() { |
| 67 | // This call activates the field trial, if needed, so it must come before any |
| 68 | // early returns. |
| 69 | std::string group_name = |
| 70 | base::FieldTrialList::FindFullName("PasswordGeneration"); |
| 71 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 72 | if (command_line->HasSwitch(switches::kEnableIOSPasswordGeneration)) |
| 73 | return true; |
| 74 | if (command_line->HasSwitch(switches::kDisableIOSPasswordGeneration)) |
| 75 | return false; |
| 76 | return group_name != "Disabled"; |
| 77 | } |
| 78 | |
| 79 | bool UseOnlyLocalHeuristicsForPasswordGeneration() { |
| 80 | if ([[NSUserDefaults standardUserDefaults] |
| 81 | boolForKey:kHeuristicsForPasswordGeneration]) { |
| 82 | return true; |
| 83 | } |
| 84 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 85 | return command_line->HasSwitch( |
| 86 | autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); |
| 87 | } |
| 88 | |
jbbegue | f9c1eaa | 2016-01-13 15:55:56 | [diff] [blame] | 89 | bool IsTabSwitcherEnabled() { |
| 90 | // Check if the experimental flag is forced on or off. |
| 91 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 92 | if (command_line->HasSwitch(switches::kEnableTabSwitcher)) { |
| 93 | return true; |
| 94 | } else if (command_line->HasSwitch(switches::kDisableTabSwitcher)) { |
| 95 | return false; |
| 96 | } |
| 97 | |
rohitrao | 0158507 | 2016-02-27 03:17:59 | [diff] [blame] | 98 | // Check if the finch experiment is turned on. |
jbbegue | f9c1eaa | 2016-01-13 15:55:56 | [diff] [blame] | 99 | std::string group_name = base::FieldTrialList::FindFullName("IOSTabSwitcher"); |
rohitrao | 0158507 | 2016-02-27 03:17:59 | [diff] [blame] | 100 | return base::StartsWith(group_name, "Enabled", |
| 101 | base::CompareCase::INSENSITIVE_ASCII); |
jbbegue | f9c1eaa | 2016-01-13 15:55:56 | [diff] [blame] | 102 | } |
| 103 | |
stkhapugin | 23ab73d8 | 2016-01-26 13:45:09 | [diff] [blame] | 104 | bool IsReadingListEnabled() { |
| 105 | return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableReadingList]; |
| 106 | } |
| 107 | |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 108 | bool IsAllBookmarksEnabled() { |
| 109 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 110 | if (command_line->HasSwitch(switches::kEnableAllBookmarksView)) { |
| 111 | return true; |
| 112 | } else if (command_line->HasSwitch(switches::kDisableAllBookmarksView)) { |
| 113 | return false; |
| 114 | } |
| 115 | |
noyau | 71a76b6 | 2016-05-13 13:02:10 | [diff] [blame] | 116 | // Check if the finch experiment exists. |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 117 | std::string group_name = |
| 118 | base::FieldTrialList::FindFullName("RemoveAllBookmarks"); |
| 119 | |
noyau | 71a76b6 | 2016-05-13 13:02:10 | [diff] [blame] | 120 | if (group_name.empty()) { |
| 121 | return true; // If no finch experiment, keep all bookmarks enabled. |
| 122 | } |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 123 | return base::StartsWith(group_name, "Enabled", |
| 124 | base::CompareCase::INSENSITIVE_ASCII); |
| 125 | } |
| 126 | |
mattreynolds | c9f1df5 | 2016-06-29 08:30:04 | [diff] [blame] | 127 | bool IsPhysicalWebEnabled() { |
| 128 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 129 | if (command_line->HasSwitch(switches::kEnableIOSPhysicalWeb)) { |
| 130 | return true; |
| 131 | } else if (command_line->HasSwitch(switches::kDisableIOSPhysicalWeb)) { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | // Check if the finch experiment is turned on |
| 136 | std::string group_name = |
| 137 | base::FieldTrialList::FindFullName("PhysicalWebEnabled"); |
| 138 | return base::StartsWith(group_name, "Enabled", |
| 139 | base::CompareCase::INSENSITIVE_ASCII); |
| 140 | } |
| 141 | |
jyquinn | c020e00 | 2016-07-06 15:21:25 | [diff] [blame] | 142 | bool IsUpdatePasswordUIEnabled() { |
| 143 | return [[NSUserDefaults standardUserDefaults] |
| 144 | boolForKey:kUpdatePasswordUIEnabled]; |
| 145 | } |
| 146 | |
sklencarova | a066816e | 2016-07-11 16:09:46 | [diff] [blame] | 147 | bool IsQRCodeReaderEnabled() { |
sklencarova | 39c8887a | 2016-07-19 14:45:57 | [diff] [blame] | 148 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 149 | if (command_line->HasSwitch(switches::kEnableQRScanner)) |
| 150 | return true; |
| 151 | |
| 152 | // Check if the finch experiment is turned on. |
sklencarova | a066816e | 2016-07-11 16:09:46 | [diff] [blame] | 153 | return [[NSUserDefaults standardUserDefaults] |
| 154 | boolForKey:kEnableQRCodeReader]; |
| 155 | } |
| 156 | |
ioanap | d798d0b | 2016-07-27 16:33:46 | [diff] [blame] | 157 | bool IsNewClearBrowsingDataUIEnabled() { |
| 158 | NSString* countersFlag = [[NSUserDefaults standardUserDefaults] |
| 159 | objectForKey:kEnableNewClearBrowsingDataUI]; |
| 160 | if ([countersFlag isEqualToString:@"Enabled"]) |
| 161 | return true; |
| 162 | return false; |
| 163 | } |
| 164 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 165 | } // namespace experimental_flags |