blob: df980e9f4110cc0e5199b18048df174976f44916 [file] [log] [blame]
drogerf83b91262015-03-05 19:45:191// 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
rohitrao4b79d932015-12-02 19:37:3810#include <dispatch/dispatch.h>
sdefresne60feea12015-06-04 08:39:5111#import <Foundation/Foundation.h>
12
lpromero68537272015-04-29 11:16:0113#include <string>
14
drogerf83b91262015-03-05 19:45:1915#include "base/command_line.h"
vabr5b82ac32015-11-27 13:03:4316#include "base/metrics/field_trial.h"
sdefresneb53a9872015-05-18 20:01:4917#include "base/strings/string_util.h"
vabr5b82ac32015-11-27 13:03:4318#include "components/autofill/core/common/autofill_switches.h"
lpromero68537272015-04-29 11:16:0119#include "components/variations/variations_associated_data.h"
drogerf83b91262015-03-05 19:45:1920#include "ios/chrome/browser/chrome_switches.h"
bzanottia5f249ed2015-06-24 10:02:5921#include "ios/web/public/web_view_creation_util.h"
drogerf83b91262015-03-05 19:45:1922
sdefresne8b192a72015-05-13 13:25:1923namespace {
24NSString* const kEnableAlertOnBackgroundUpload =
25 @"EnableAlertsOnBackgroundUpload";
ioanap744ba1982015-08-11 13:25:0426NSString* const kEnableViewCopyPasswords = @"EnableViewCopyPasswords";
vabr5b82ac32015-11-27 13:03:4327NSString* const kHeuristicsForPasswordGeneration =
28 @"HeuristicsForPasswordGeneration";
stkhapugin23ab73d82016-01-26 13:45:0929NSString* const kEnableReadingList = @"EnableReadingList";
jyquinnc020e002016-07-06 15:21:2530NSString* const kUpdatePasswordUIEnabled = @"UpdatePasswordUIEnabled";
sklencarovaa066816e2016-07-11 16:09:4631NSString* const kEnableQRCodeReader = @"EnableQRCodeReader";
ioanapd798d0b2016-07-27 16:33:4632NSString* const kEnableNewClearBrowsingDataUI = @"EnableNewClearBrowsingDataUI";
sdefresne8b192a72015-05-13 13:25:1933} // namespace
34
drogerf83b91262015-03-05 19:45:1935namespace experimental_flags {
36
sdefresne8b192a72015-05-13 13:25:1937bool IsAlertOnBackgroundUploadEnabled() {
38 return [[NSUserDefaults standardUserDefaults]
39 boolForKey:kEnableAlertOnBackgroundUpload];
40}
41
jbbeguecba2cb0b2015-11-06 10:35:2442bool 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
ioanap744ba1982015-08-11 13:25:0458bool IsViewCopyPasswordsEnabled() {
59 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults]
60 objectForKey:kEnableViewCopyPasswords];
61 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"])
62 return true;
63 return false;
64}
65
vabr5b82ac32015-11-27 13:03:4366bool 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
79bool 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
jbbeguef9c1eaa2016-01-13 15:55:5689bool 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
rohitrao01585072016-02-27 03:17:5998 // Check if the finch experiment is turned on.
jbbeguef9c1eaa2016-01-13 15:55:5699 std::string group_name = base::FieldTrialList::FindFullName("IOSTabSwitcher");
rohitrao01585072016-02-27 03:17:59100 return base::StartsWith(group_name, "Enabled",
101 base::CompareCase::INSENSITIVE_ASCII);
jbbeguef9c1eaa2016-01-13 15:55:56102}
103
stkhapugin23ab73d82016-01-26 13:45:09104bool IsReadingListEnabled() {
105 return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableReadingList];
106}
107
noyauc7892c12016-05-12 12:22:01108bool 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
noyau71a76b62016-05-13 13:02:10116 // Check if the finch experiment exists.
noyauc7892c12016-05-12 12:22:01117 std::string group_name =
118 base::FieldTrialList::FindFullName("RemoveAllBookmarks");
119
noyau71a76b62016-05-13 13:02:10120 if (group_name.empty()) {
121 return true; // If no finch experiment, keep all bookmarks enabled.
122 }
noyauc7892c12016-05-12 12:22:01123 return base::StartsWith(group_name, "Enabled",
124 base::CompareCase::INSENSITIVE_ASCII);
125}
126
mattreynoldsc9f1df52016-06-29 08:30:04127bool 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
jyquinnc020e002016-07-06 15:21:25142bool IsUpdatePasswordUIEnabled() {
143 return [[NSUserDefaults standardUserDefaults]
144 boolForKey:kUpdatePasswordUIEnabled];
145}
146
sklencarovaa066816e2016-07-11 16:09:46147bool IsQRCodeReaderEnabled() {
sklencarova39c8887a2016-07-19 14:45:57148 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.
sklencarovaa066816e2016-07-11 16:09:46153 return [[NSUserDefaults standardUserDefaults]
154 boolForKey:kEnableQRCodeReader];
155}
156
ioanapd798d0b2016-07-27 16:33:46157bool IsNewClearBrowsingDataUIEnabled() {
158 NSString* countersFlag = [[NSUserDefaults standardUserDefaults]
159 objectForKey:kEnableNewClearBrowsingDataUI];
160 if ([countersFlag isEqualToString:@"Enabled"])
161 return true;
162 return false;
163}
164
drogerf83b91262015-03-05 19:45:19165} // namespace experimental_flags