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"; |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 31 | } // namespace |
| 32 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 33 | namespace experimental_flags { |
| 34 | |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 35 | bool IsAlertOnBackgroundUploadEnabled() { |
| 36 | return [[NSUserDefaults standardUserDefaults] |
| 37 | boolForKey:kEnableAlertOnBackgroundUpload]; |
| 38 | } |
| 39 | |
jbbegue | cba2cb0b | 2015-11-06 10:35:24 | [diff] [blame] | 40 | bool IsLRUSnapshotCacheEnabled() { |
| 41 | // Check if the experimental flag is forced on or off. |
| 42 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 43 | if (command_line->HasSwitch(switches::kEnableLRUSnapshotCache)) { |
| 44 | return true; |
| 45 | } else if (command_line->HasSwitch(switches::kDisableLRUSnapshotCache)) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // Check if the finch experiment is turned on. |
| 50 | std::string group_name = |
| 51 | base::FieldTrialList::FindFullName("IOSLRUSnapshotCache"); |
| 52 | return base::StartsWith(group_name, "Enabled", |
| 53 | base::CompareCase::INSENSITIVE_ASCII); |
| 54 | } |
| 55 | |
ioanap | 744ba198 | 2015-08-11 13:25:04 | [diff] [blame] | 56 | bool IsViewCopyPasswordsEnabled() { |
| 57 | NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] |
| 58 | objectForKey:kEnableViewCopyPasswords]; |
| 59 | if ([viewCopyPasswordFlag isEqualToString:@"Enabled"]) |
| 60 | return true; |
| 61 | return false; |
| 62 | } |
| 63 | |
vabr | 5b82ac3 | 2015-11-27 13:03:43 | [diff] [blame] | 64 | bool IsPasswordGenerationEnabled() { |
| 65 | // This call activates the field trial, if needed, so it must come before any |
| 66 | // early returns. |
| 67 | std::string group_name = |
| 68 | base::FieldTrialList::FindFullName("PasswordGeneration"); |
| 69 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 70 | if (command_line->HasSwitch(switches::kEnableIOSPasswordGeneration)) |
| 71 | return true; |
| 72 | if (command_line->HasSwitch(switches::kDisableIOSPasswordGeneration)) |
| 73 | return false; |
| 74 | return group_name != "Disabled"; |
| 75 | } |
| 76 | |
| 77 | bool UseOnlyLocalHeuristicsForPasswordGeneration() { |
| 78 | if ([[NSUserDefaults standardUserDefaults] |
| 79 | boolForKey:kHeuristicsForPasswordGeneration]) { |
| 80 | return true; |
| 81 | } |
| 82 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 83 | return command_line->HasSwitch( |
| 84 | autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); |
| 85 | } |
| 86 | |
jbbegue | f9c1eaa | 2016-01-13 15:55:56 | [diff] [blame] | 87 | bool IsTabSwitcherEnabled() { |
| 88 | // Check if the experimental flag is forced on or off. |
| 89 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 90 | if (command_line->HasSwitch(switches::kEnableTabSwitcher)) { |
| 91 | return true; |
| 92 | } else if (command_line->HasSwitch(switches::kDisableTabSwitcher)) { |
| 93 | return false; |
| 94 | } |
| 95 | |
rohitrao | 0158507 | 2016-02-27 03:17:59 | [diff] [blame] | 96 | // Check if the finch experiment is turned on. |
jbbegue | f9c1eaa | 2016-01-13 15:55:56 | [diff] [blame] | 97 | std::string group_name = base::FieldTrialList::FindFullName("IOSTabSwitcher"); |
rohitrao | 0158507 | 2016-02-27 03:17:59 | [diff] [blame] | 98 | return base::StartsWith(group_name, "Enabled", |
| 99 | base::CompareCase::INSENSITIVE_ASCII); |
jbbegue | f9c1eaa | 2016-01-13 15:55:56 | [diff] [blame] | 100 | } |
| 101 | |
stkhapugin | 23ab73d8 | 2016-01-26 13:45:09 | [diff] [blame] | 102 | bool IsReadingListEnabled() { |
| 103 | return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableReadingList]; |
| 104 | } |
| 105 | |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 106 | bool IsAllBookmarksEnabled() { |
| 107 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 108 | if (command_line->HasSwitch(switches::kEnableAllBookmarksView)) { |
| 109 | return true; |
| 110 | } else if (command_line->HasSwitch(switches::kDisableAllBookmarksView)) { |
| 111 | return false; |
| 112 | } |
| 113 | |
noyau | 71a76b6 | 2016-05-13 13:02:10 | [diff] [blame] | 114 | // Check if the finch experiment exists. |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 115 | std::string group_name = |
| 116 | base::FieldTrialList::FindFullName("RemoveAllBookmarks"); |
| 117 | |
noyau | 71a76b6 | 2016-05-13 13:02:10 | [diff] [blame] | 118 | if (group_name.empty()) { |
| 119 | return true; // If no finch experiment, keep all bookmarks enabled. |
| 120 | } |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 121 | return base::StartsWith(group_name, "Enabled", |
| 122 | base::CompareCase::INSENSITIVE_ASCII); |
| 123 | } |
| 124 | |
mattreynolds | c9f1df5 | 2016-06-29 08:30:04 | [diff] [blame] | 125 | bool IsPhysicalWebEnabled() { |
| 126 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 127 | if (command_line->HasSwitch(switches::kEnableIOSPhysicalWeb)) { |
| 128 | return true; |
| 129 | } else if (command_line->HasSwitch(switches::kDisableIOSPhysicalWeb)) { |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | // Check if the finch experiment is turned on |
| 134 | std::string group_name = |
| 135 | base::FieldTrialList::FindFullName("PhysicalWebEnabled"); |
| 136 | return base::StartsWith(group_name, "Enabled", |
| 137 | base::CompareCase::INSENSITIVE_ASCII); |
| 138 | } |
| 139 | |
jyquinn | c020e00 | 2016-07-06 15:21:25 | [diff] [blame^] | 140 | bool IsUpdatePasswordUIEnabled() { |
| 141 | return [[NSUserDefaults standardUserDefaults] |
| 142 | boolForKey:kUpdatePasswordUIEnabled]; |
| 143 | } |
| 144 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 145 | } // namespace experimental_flags |