sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 1 | // Copyright 2012 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 | // Implementation of about_flags for iOS that sets flags based on experimental |
| 6 | // settings. |
| 7 | |
| 8 | #include "ios/chrome/browser/about_flags.h" |
| 9 | |
avi | 57194367 | 2015-12-22 02:12:49 | [diff] [blame] | 10 | #include <stddef.h> |
| 11 | #include <stdint.h> |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 12 | #import <UIKit/UIKit.h> |
| 13 | |
| 14 | #include "base/bind.h" |
| 15 | #include "base/command_line.h" |
| 16 | #include "base/logging.h" |
avi | 57194367 | 2015-12-22 02:12:49 | [diff] [blame] | 17 | #include "base/macros.h" |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 18 | #include "base/memory/singleton.h" |
| 19 | #include "base/strings/stringprintf.h" |
| 20 | #include "base/strings/sys_string_conversions.h" |
| 21 | #include "base/sys_info.h" |
robliao | 59eed1a | 2016-10-28 17:12:16 | [diff] [blame] | 22 | #include "base/task_scheduler/switches.h" |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 23 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 24 | #include "components/flags_ui/feature_entry.h" |
| 25 | #include "components/flags_ui/feature_entry_macros.h" |
| 26 | #include "components/flags_ui/flags_storage.h" |
| 27 | #include "components/flags_ui/flags_ui_switches.h" |
noyau | 4cfb133 | 2016-10-25 17:05:42 | [diff] [blame] | 28 | #include "components/ntp_tiles/switches.h" |
olivierrobin | 0c6cd0ca | 2016-11-24 22:40:35 | [diff] [blame] | 29 | #include "components/reading_list/core/reading_list_switches.h" |
sdefresne | 3657978 | 2016-02-05 11:08:25 | [diff] [blame] | 30 | #include "components/strings/grit/components_strings.h" |
maxbogue | 455a57e3 | 2016-08-14 00:08:32 | [diff] [blame] | 31 | #include "components/sync/driver/sync_driver_switches.h" |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 32 | #include "google_apis/gaia/gaia_switches.h" |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 33 | #include "ios/chrome/browser/chrome_switches.h" |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 34 | #include "ios/chrome/browser/google_api_keys.h" |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 35 | #include "ios/chrome/grit/ios_strings.h" |
| 36 | #include "ios/web/public/user_agent.h" |
| 37 | #include "ios/web/public/web_view_creation_util.h" |
| 38 | |
| 39 | #if !defined(OFFICIAL_BUILD) |
| 40 | #include "components/variations/variations_switches.h" |
stkhapugin | c1be179 | 2016-12-13 14:30:53 | [diff] [blame] | 41 | |
| 42 | #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 43 | #error "This file requires ARC support." |
| 44 | #endif |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | namespace { |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 48 | // To add a new entry, add to the end of kFeatureEntries. There are two |
| 49 | // distinct types of entries: |
| 50 | // . SINGLE_VALUE: entry is either on or off. Use the SINGLE_VALUE_TYPE |
| 51 | // macro for this type supplying the command line to the macro. |
| 52 | // . MULTI_VALUE: a list of choices, the first of which should correspond to a |
| 53 | // deactivated state for this lab (i.e. no command line option). To specify |
| 54 | // this type of entry use the macro MULTI_VALUE_TYPE supplying it the |
| 55 | // array of choices. |
| 56 | // See the documentation of FeatureEntry for details on the fields. |
| 57 | // |
| 58 | // When adding a new choice, add it to the end of the list. |
| 59 | const flags_ui::FeatureEntry kFeatureEntries[] = { |
| 60 | {"contextual-search", IDS_IOS_FLAGS_CONTEXTUAL_SEARCH, |
mattreynolds | 1a4181f | 2016-10-05 23:50:00 | [diff] [blame] | 61 | IDS_IOS_FLAGS_CONTEXTUAL_SEARCH_DESCRIPTION, flags_ui::kOsIos, |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 62 | ENABLE_DISABLE_VALUE_TYPE(switches::kEnableContextualSearch, |
| 63 | switches::kDisableContextualSearch)}, |
mattreynolds | 1a4181f | 2016-10-05 23:50:00 | [diff] [blame] | 64 | {"ios-physical-web", IDS_IOS_FLAGS_PHYSICAL_WEB, |
| 65 | IDS_IOS_FLAGS_PHYSICAL_WEB_DESCRIPTION, flags_ui::kOsIos, |
| 66 | ENABLE_DISABLE_VALUE_TYPE(switches::kEnableIOSPhysicalWeb, |
| 67 | switches::kDisableIOSPhysicalWeb)}, |
robliao | 59eed1a | 2016-10-28 17:12:16 | [diff] [blame] | 68 | {"browser-task-scheduler", IDS_IOS_FLAGS_BROWSER_TASK_SCHEDULER_NAME, |
| 69 | IDS_IOS_FLAGS_BROWSER_TASK_SCHEDULER_DESCRIPTION, flags_ui::kOsIos, |
| 70 | ENABLE_DISABLE_VALUE_TYPE(switches::kEnableBrowserTaskScheduler, |
| 71 | switches::kDisableBrowserTaskScheduler)}, |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | // Add all switches from experimental flags to |command_line|. |
| 75 | void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) { |
| 76 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 77 | |
| 78 | // GAIA staging environment. |
| 79 | NSString* kGAIAEnvironment = @"GAIAEnvironment"; |
| 80 | NSString* gaia_environment = [defaults stringForKey:kGAIAEnvironment]; |
| 81 | if ([gaia_environment isEqualToString:@"Staging"]) { |
| 82 | command_line->AppendSwitchASCII(switches::kGoogleApisUrl, |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 83 | BUILDFLAG(GOOGLE_STAGING_API_URL)); |
| 84 | command_line->AppendSwitchASCII(switches::kLsoUrl, |
| 85 | BUILDFLAG(GOOGLE_STAGING_LSO_URL)); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 86 | } else if ([gaia_environment isEqualToString:@"Test"]) { |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 87 | command_line->AppendSwitchASCII(switches::kGaiaUrl, |
| 88 | BUILDFLAG(GOOGLE_TEST_OAUTH_URL)); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 89 | command_line->AppendSwitchASCII(switches::kGoogleApisUrl, |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 90 | BUILDFLAG(GOOGLE_TEST_API_URL)); |
| 91 | command_line->AppendSwitchASCII(switches::kLsoUrl, |
| 92 | BUILDFLAG(GOOGLE_TEST_LSO_URL)); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 93 | command_line->AppendSwitchASCII(switches::kSyncServiceURL, |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 94 | BUILDFLAG(GOOGLE_TEST_SYNC_URL)); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 95 | command_line->AppendSwitchASCII(switches::kOAuth2ClientID, |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 96 | BUILDFLAG(GOOGLE_TEST_OAUTH_CLIENT_ID)); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 97 | command_line->AppendSwitchASCII(switches::kOAuth2ClientSecret, |
sdefresne | e7fd9406 | 2016-12-12 13:21:08 | [diff] [blame] | 98 | BUILDFLAG(GOOGLE_TEST_OAUTH_CLIENT_SECRET)); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 99 | } |
| 100 | |
liaoyuke | df4f7e4 | 2017-01-07 00:21:10 | [diff] [blame] | 101 | // Populate command line flag for the tab strip auto scroll new tabs |
| 102 | // experiment from the configuration plist. |
| 103 | if ([defaults boolForKey:@"TabStripAutoScrollNewTabsDisabled"]) |
| 104 | command_line->AppendSwitch(switches::kDisableTabStripAutoScrollNewTabs); |
| 105 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 106 | // Populate command line flag for the Tab Switcher experiment from the |
| 107 | // configuration plist. |
| 108 | NSString* enableTabSwitcher = [defaults stringForKey:@"EnableTabSwitcher"]; |
| 109 | if ([enableTabSwitcher isEqualToString:@"Enabled"]) { |
| 110 | command_line->AppendSwitch(switches::kEnableTabSwitcher); |
| 111 | } else if ([enableTabSwitcher isEqualToString:@"Disabled"]) { |
| 112 | command_line->AppendSwitch(switches::kDisableTabSwitcher); |
| 113 | } |
| 114 | |
| 115 | // Populate command line flag for the SnapshotLRUCache experiment from the |
| 116 | // configuration plist. |
| 117 | NSString* enableLRUSnapshotCache = |
| 118 | [defaults stringForKey:@"SnapshotLRUCache"]; |
| 119 | if ([enableLRUSnapshotCache isEqualToString:@"Enabled"]) { |
| 120 | command_line->AppendSwitch(switches::kEnableLRUSnapshotCache); |
| 121 | } else if ([enableLRUSnapshotCache isEqualToString:@"Disabled"]) { |
| 122 | command_line->AppendSwitch(switches::kDisableLRUSnapshotCache); |
| 123 | } |
| 124 | |
noyau | c7892c1 | 2016-05-12 12:22:01 | [diff] [blame] | 125 | // Populate command line flag for the AllBookmarks from the |
| 126 | // configuration plist. |
| 127 | NSString* enableAllBookmarks = [defaults stringForKey:@"AllBookmarks"]; |
| 128 | if ([enableAllBookmarks isEqualToString:@"Enabled"]) { |
| 129 | command_line->AppendSwitch(switches::kEnableAllBookmarksView); |
| 130 | } else if ([enableAllBookmarks isEqualToString:@"Disabled"]) { |
| 131 | command_line->AppendSwitch(switches::kDisableAllBookmarksView); |
| 132 | } |
| 133 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 134 | // Populate command line flags from PasswordGenerationEnabled. |
| 135 | NSString* enablePasswordGenerationValue = |
| 136 | [defaults stringForKey:@"PasswordGenerationEnabled"]; |
| 137 | if ([enablePasswordGenerationValue isEqualToString:@"Enabled"]) { |
| 138 | command_line->AppendSwitch(switches::kEnableIOSPasswordGeneration); |
| 139 | } else if ([enablePasswordGenerationValue isEqualToString:@"Disabled"]) { |
| 140 | command_line->AppendSwitch(switches::kDisableIOSPasswordGeneration); |
| 141 | } |
| 142 | |
mattreynolds | c9f1df5 | 2016-06-29 08:30:04 | [diff] [blame] | 143 | // Populate command line flags from PhysicalWebEnabled. |
| 144 | NSString* enablePhysicalWebValue = |
| 145 | [defaults stringForKey:@"PhysicalWebEnabled"]; |
| 146 | if ([enablePhysicalWebValue isEqualToString:@"Enabled"]) { |
| 147 | command_line->AppendSwitch(switches::kEnableIOSPhysicalWeb); |
| 148 | } else if ([enablePhysicalWebValue isEqualToString:@"Disabled"]) { |
| 149 | command_line->AppendSwitch(switches::kDisableIOSPhysicalWeb); |
| 150 | } |
| 151 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 152 | // Web page replay flags. |
| 153 | BOOL webPageReplayEnabled = [defaults boolForKey:@"WebPageReplayEnabled"]; |
| 154 | NSString* webPageReplayProxy = |
| 155 | [defaults stringForKey:@"WebPageReplayProxyAddress"]; |
| 156 | if (webPageReplayEnabled && [webPageReplayProxy length]) { |
| 157 | command_line->AppendSwitch(switches::kIOSIgnoreCertificateErrors); |
| 158 | // 80 and 443 are the default ports from web page replay. |
| 159 | command_line->AppendSwitchASCII(switches::kIOSTestingFixedHttpPort, "80"); |
| 160 | command_line->AppendSwitchASCII(switches::kIOSTestingFixedHttpsPort, "443"); |
| 161 | command_line->AppendSwitchASCII( |
| 162 | switches::kIOSHostResolverRules, |
| 163 | "MAP * " + base::SysNSStringToUTF8(webPageReplayProxy)); |
| 164 | } |
| 165 | |
| 166 | if ([defaults boolForKey:@"EnableCredentialManagement"]) |
| 167 | command_line->AppendSwitch(switches::kEnableCredentialManagerAPI); |
| 168 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 169 | NSString* autoReloadEnabledValue = |
| 170 | [defaults stringForKey:@"AutoReloadEnabled"]; |
| 171 | if ([autoReloadEnabledValue isEqualToString:@"Enabled"]) { |
| 172 | command_line->AppendSwitch(switches::kEnableOfflineAutoReload); |
| 173 | } else if ([autoReloadEnabledValue isEqualToString:@"Disabled"]) { |
| 174 | command_line->AppendSwitch(switches::kDisableOfflineAutoReload); |
| 175 | } |
| 176 | |
| 177 | // Populate command line flags from EnableFastWebScrollViewInsets. |
| 178 | NSString* enableFastWebScrollViewInsets = |
| 179 | [defaults stringForKey:@"EnableFastWebScrollViewInsets"]; |
| 180 | if ([enableFastWebScrollViewInsets isEqualToString:@"Enabled"]) { |
| 181 | command_line->AppendSwitch(switches::kEnableIOSFastWebScrollViewInsets); |
| 182 | } else if ([enableFastWebScrollViewInsets isEqualToString:@"Disabled"]) { |
| 183 | command_line->AppendSwitch(switches::kDisableIOSFastWebScrollViewInsets); |
| 184 | } |
| 185 | |
| 186 | // Populate command line flags from ReaderModeEnabled. |
| 187 | if ([defaults boolForKey:@"ReaderModeEnabled"]) { |
| 188 | command_line->AppendSwitch(switches::kEnableReaderModeToolbarIcon); |
| 189 | |
| 190 | // Populate command line from ReaderMode Heuristics detection. |
| 191 | NSString* readerModeDetectionHeuristics = |
| 192 | [defaults stringForKey:@"ReaderModeDetectionHeuristics"]; |
| 193 | if (!readerModeDetectionHeuristics) { |
noyau | db4a2d6 | 2016-09-26 11:04:45 | [diff] [blame] | 194 | command_line->AppendSwitchASCII( |
| 195 | switches::kReaderModeHeuristics, |
| 196 | switches::reader_mode_heuristics::kOGArticle); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 197 | } else if ([readerModeDetectionHeuristics isEqualToString:@"AdaBoost"]) { |
noyau | db4a2d6 | 2016-09-26 11:04:45 | [diff] [blame] | 198 | command_line->AppendSwitchASCII( |
| 199 | switches::kReaderModeHeuristics, |
| 200 | switches::reader_mode_heuristics::kAdaBoost); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 201 | } else { |
| 202 | DCHECK([readerModeDetectionHeuristics isEqualToString:@"Off"]); |
noyau | db4a2d6 | 2016-09-26 11:04:45 | [diff] [blame] | 203 | command_line->AppendSwitchASCII(switches::kReaderModeHeuristics, |
| 204 | switches::reader_mode_heuristics::kNone); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
noyau | e0884e4 | 2016-11-08 15:26:41 | [diff] [blame] | 208 | // Populate command line flags from EnablePopularSites. |
| 209 | NSString* EnablePopularSites = [defaults stringForKey:@"EnablePopularSites"]; |
| 210 | if ([EnablePopularSites isEqualToString:@"Enabled"]) { |
noyau | 4cfb133 | 2016-10-25 17:05:42 | [diff] [blame] | 211 | command_line->AppendSwitch(ntp_tiles::switches::kEnableNTPPopularSites); |
noyau | e0884e4 | 2016-11-08 15:26:41 | [diff] [blame] | 212 | } else if ([EnablePopularSites isEqualToString:@"Disabled"]) { |
| 213 | command_line->AppendSwitch(ntp_tiles::switches::kDisableNTPPopularSites); |
noyau | 4cfb133 | 2016-10-25 17:05:42 | [diff] [blame] | 214 | } |
| 215 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 216 | // Set the UA flag if UseMobileSafariUA is enabled. |
| 217 | if ([defaults boolForKey:@"UseMobileSafariUA"]) { |
| 218 | // Safari uses "Vesion/", followed by the OS version excluding bugfix, where |
| 219 | // Chrome puts its product token. |
avi | 57194367 | 2015-12-22 02:12:49 | [diff] [blame] | 220 | int32_t major = 0; |
| 221 | int32_t minor = 0; |
| 222 | int32_t bugfix = 0; |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 223 | base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| 224 | std::string product = base::StringPrintf("Version/%d.%d", major, minor); |
| 225 | |
| 226 | command_line->AppendSwitchASCII(switches::kUserAgent, |
| 227 | web::BuildUserAgentFromProduct(product)); |
| 228 | } |
| 229 | |
sklencarova | 39c8887a | 2016-07-19 14:45:57 | [diff] [blame] | 230 | // Populate command line flags from QRScanner. |
jif | 3df1b40d | 2016-09-20 18:56:36 | [diff] [blame] | 231 | if ([defaults boolForKey:@"DisableQRCodeReader"]) { |
sklencarova | c8a562c5 | 2016-09-12 10:20:34 | [diff] [blame] | 232 | command_line->AppendSwitch(switches::kDisableQRScanner); |
jif | 3df1b40d | 2016-09-20 18:56:36 | [diff] [blame] | 233 | } else { |
| 234 | command_line->AppendSwitch(switches::kEnableQRScanner); |
sklencarova | 39c8887a | 2016-07-19 14:45:57 | [diff] [blame] | 235 | } |
| 236 | |
jdonnelly | 1ca9fd8b | 2016-08-11 02:29:12 | [diff] [blame] | 237 | // Populate command line flag for the Payment Request API. |
| 238 | NSString* enable_payment_request = |
| 239 | [defaults stringForKey:@"EnablePaymentRequest"]; |
| 240 | if ([enable_payment_request isEqualToString:@"Enabled"]) { |
| 241 | command_line->AppendSwitch(switches::kEnablePaymentRequest); |
| 242 | } else if ([enable_payment_request isEqualToString:@"Disabled"]) { |
| 243 | command_line->AppendSwitch(switches::kDisablePaymentRequest); |
| 244 | } |
| 245 | |
sklencarova | 6eaf8fc | 2016-09-13 10:02:34 | [diff] [blame] | 246 | // Populate command line flag for Spotlight Actions. |
jif | e9171ba | 2016-09-20 19:00:03 | [diff] [blame] | 247 | if ([defaults boolForKey:@"DisableSpotlightActions"]) { |
sklencarova | 6eaf8fc | 2016-09-13 10:02:34 | [diff] [blame] | 248 | command_line->AppendSwitch(switches::kDisableSpotlightActions); |
| 249 | } |
| 250 | |
gambard | 91ee34f | 2016-11-30 17:33:03 | [diff] [blame] | 251 | // Populate command line flag for the Rename "Save Image" to "Download Image" |
| 252 | // experiment. |
| 253 | NSString* enableDownloadRenaming = |
| 254 | [defaults stringForKey:@"EnableDownloadRenaming"]; |
| 255 | if ([enableDownloadRenaming isEqualToString:@"Enabled"]) { |
| 256 | command_line->AppendSwitch(switches::kEnableDownloadImageRenaming); |
| 257 | } else if ([enableDownloadRenaming isEqualToString:@"Disabled"]) { |
| 258 | command_line->AppendSwitch(switches::kDisableDownloadImageRenaming); |
| 259 | } |
| 260 | |
gambard | d2e44fb | 2017-01-25 09:14:21 | [diff] [blame^] | 261 | // Populate command line flag for Suggestions UI display. |
| 262 | NSString* enableSuggestions = [defaults stringForKey:@"EnableSuggestions"]; |
| 263 | if ([enableSuggestions isEqualToString:@"Enabled"]) { |
| 264 | command_line->AppendSwitch(switches::kEnableSuggestionsUI); |
| 265 | } else if ([enableSuggestions isEqualToString:@"Disabled"]) { |
| 266 | command_line->AppendSwitch(switches::kDisableSuggestionsUI); |
| 267 | } |
| 268 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 269 | // Freeform commandline flags. These are added last, so that any flags added |
| 270 | // earlier in this function take precedence. |
| 271 | if ([defaults boolForKey:@"EnableFreeformCommandLineFlags"]) { |
| 272 | base::CommandLine::StringVector flags; |
| 273 | // Append an empty "program" argument. |
| 274 | flags.push_back(""); |
| 275 | |
| 276 | // The number of flags corresponds to the number of text fields in |
| 277 | // Experimental.plist. |
| 278 | const int kNumFreeformFlags = 5; |
| 279 | for (int i = 1; i <= kNumFreeformFlags; ++i) { |
| 280 | NSString* key = |
| 281 | [NSString stringWithFormat:@"FreeformCommandLineFlag%d", i]; |
| 282 | NSString* flag = [defaults stringForKey:key]; |
| 283 | if ([flag length]) { |
| 284 | flags.push_back(base::SysNSStringToUTF8(flag)); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | base::CommandLine temp_command_line(flags); |
| 289 | command_line->AppendArguments(temp_command_line, false); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | bool SkipConditionalFeatureEntry(const flags_ui::FeatureEntry& entry) { |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | class FlagsStateSingleton { |
| 298 | public: |
| 299 | FlagsStateSingleton() |
| 300 | : flags_state_(kFeatureEntries, arraysize(kFeatureEntries)) {} |
| 301 | ~FlagsStateSingleton() {} |
| 302 | |
| 303 | static FlagsStateSingleton* GetInstance() { |
| 304 | return base::Singleton<FlagsStateSingleton>::get(); |
| 305 | } |
| 306 | |
| 307 | static flags_ui::FlagsState* GetFlagsState() { |
| 308 | return &GetInstance()->flags_state_; |
| 309 | } |
| 310 | |
| 311 | private: |
| 312 | flags_ui::FlagsState flags_state_; |
| 313 | |
| 314 | DISALLOW_COPY_AND_ASSIGN(FlagsStateSingleton); |
| 315 | }; |
| 316 | } // namespace |
| 317 | |
| 318 | void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, |
| 319 | base::CommandLine* command_line) { |
| 320 | FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches( |
sdefresne | c976390 | 2015-12-02 10:30:11 | [diff] [blame] | 321 | flags_storage, command_line, flags_ui::kAddSentinels, |
| 322 | switches::kEnableIOSFeatures, switches::kDisableIOSFeatures); |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 323 | AppendSwitchesFromExperimentalSettings(command_line); |
| 324 | } |
| 325 | |
jkrcal | bf07337 | 2016-07-29 07:21:31 | [diff] [blame] | 326 | std::vector<std::string> RegisterAllFeatureVariationParameters( |
| 327 | flags_ui::FlagsStorage* flags_storage, |
| 328 | base::FeatureList* feature_list) { |
| 329 | return FlagsStateSingleton::GetFlagsState() |
| 330 | ->RegisterAllFeatureVariationParameters(flags_storage, feature_list); |
| 331 | } |
| 332 | |
sdefresne | 14900ee | 2015-11-27 14:43:21 | [diff] [blame] | 333 | void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage, |
| 334 | flags_ui::FlagAccess access, |
| 335 | base::ListValue* supported_entries, |
| 336 | base::ListValue* unsupported_entries) { |
| 337 | FlagsStateSingleton::GetFlagsState()->GetFlagFeatureEntries( |
| 338 | flags_storage, access, supported_entries, unsupported_entries, |
| 339 | base::Bind(&SkipConditionalFeatureEntry)); |
| 340 | } |
| 341 | |
| 342 | void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, |
| 343 | const std::string& internal_name, |
| 344 | bool enable) { |
| 345 | FlagsStateSingleton::GetFlagsState()->SetFeatureEntryEnabled( |
| 346 | flags_storage, internal_name, enable); |
| 347 | } |
| 348 | |
| 349 | void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) { |
| 350 | FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage); |
| 351 | } |
| 352 | |
| 353 | namespace testing { |
| 354 | |
| 355 | const flags_ui::FeatureEntry* GetFeatureEntries(size_t* count) { |
| 356 | *count = arraysize(kFeatureEntries); |
| 357 | return kFeatureEntries; |
| 358 | } |
| 359 | |
| 360 | } // namespace testing |