blob: 9e772354a4ad3e36c15db17bfaee08e53242ea9f [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";
sdefresne8b192a72015-05-13 13:25:1931} // namespace
32
drogerf83b91262015-03-05 19:45:1933namespace experimental_flags {
34
sdefresne8b192a72015-05-13 13:25:1935bool IsAlertOnBackgroundUploadEnabled() {
36 return [[NSUserDefaults standardUserDefaults]
37 boolForKey:kEnableAlertOnBackgroundUpload];
38}
39
jbbeguecba2cb0b2015-11-06 10:35:2440bool 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
ioanap744ba1982015-08-11 13:25:0456bool IsViewCopyPasswordsEnabled() {
57 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults]
58 objectForKey:kEnableViewCopyPasswords];
59 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"])
60 return true;
61 return false;
62}
63
vabr5b82ac32015-11-27 13:03:4364bool 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
77bool 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
jbbeguef9c1eaa2016-01-13 15:55:5687bool 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
rohitrao01585072016-02-27 03:17:5996 // Check if the finch experiment is turned on.
jbbeguef9c1eaa2016-01-13 15:55:5697 std::string group_name = base::FieldTrialList::FindFullName("IOSTabSwitcher");
rohitrao01585072016-02-27 03:17:5998 return base::StartsWith(group_name, "Enabled",
99 base::CompareCase::INSENSITIVE_ASCII);
jbbeguef9c1eaa2016-01-13 15:55:56100}
101
stkhapugin23ab73d82016-01-26 13:45:09102bool IsReadingListEnabled() {
103 return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableReadingList];
104}
105
noyauc7892c12016-05-12 12:22:01106bool 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
noyau71a76b62016-05-13 13:02:10114 // Check if the finch experiment exists.
noyauc7892c12016-05-12 12:22:01115 std::string group_name =
116 base::FieldTrialList::FindFullName("RemoveAllBookmarks");
117
noyau71a76b62016-05-13 13:02:10118 if (group_name.empty()) {
119 return true; // If no finch experiment, keep all bookmarks enabled.
120 }
noyauc7892c12016-05-12 12:22:01121 return base::StartsWith(group_name, "Enabled",
122 base::CompareCase::INSENSITIVE_ASCII);
123}
124
mattreynoldsc9f1df52016-06-29 08:30:04125bool 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
jyquinnc020e002016-07-06 15:21:25140bool IsUpdatePasswordUIEnabled() {
141 return [[NSUserDefaults standardUserDefaults]
142 boolForKey:kUpdatePasswordUIEnabled];
143}
144
drogerf83b91262015-03-05 19:45:19145} // namespace experimental_flags