blob: 9218e898a40d629ddfbf52486cbba7aba606a721 [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";
sdefresne8b192a72015-05-13 13:25:1930} // namespace
31
drogerf83b91262015-03-05 19:45:1932namespace experimental_flags {
33
sdefresne8b192a72015-05-13 13:25:1934bool IsAlertOnBackgroundUploadEnabled() {
35 return [[NSUserDefaults standardUserDefaults]
36 boolForKey:kEnableAlertOnBackgroundUpload];
37}
38
jbbeguecba2cb0b2015-11-06 10:35:2439bool IsLRUSnapshotCacheEnabled() {
40 // Check if the experimental flag is forced on or off.
41 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
42 if (command_line->HasSwitch(switches::kEnableLRUSnapshotCache)) {
43 return true;
44 } else if (command_line->HasSwitch(switches::kDisableLRUSnapshotCache)) {
45 return false;
46 }
47
48 // Check if the finch experiment is turned on.
49 std::string group_name =
50 base::FieldTrialList::FindFullName("IOSLRUSnapshotCache");
51 return base::StartsWith(group_name, "Enabled",
52 base::CompareCase::INSENSITIVE_ASCII);
53}
54
ioanap744ba1982015-08-11 13:25:0455bool IsViewCopyPasswordsEnabled() {
56 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults]
57 objectForKey:kEnableViewCopyPasswords];
58 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"])
59 return true;
60 return false;
61}
62
vabr5b82ac32015-11-27 13:03:4363bool IsPasswordGenerationEnabled() {
64 // This call activates the field trial, if needed, so it must come before any
65 // early returns.
66 std::string group_name =
67 base::FieldTrialList::FindFullName("PasswordGeneration");
68 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
69 if (command_line->HasSwitch(switches::kEnableIOSPasswordGeneration))
70 return true;
71 if (command_line->HasSwitch(switches::kDisableIOSPasswordGeneration))
72 return false;
73 return group_name != "Disabled";
74}
75
76bool UseOnlyLocalHeuristicsForPasswordGeneration() {
77 if ([[NSUserDefaults standardUserDefaults]
78 boolForKey:kHeuristicsForPasswordGeneration]) {
79 return true;
80 }
81 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
82 return command_line->HasSwitch(
83 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration);
84}
85
jbbeguef9c1eaa2016-01-13 15:55:5686bool IsTabSwitcherEnabled() {
87 // Check if the experimental flag is forced on or off.
88 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
89 if (command_line->HasSwitch(switches::kEnableTabSwitcher)) {
90 return true;
91 } else if (command_line->HasSwitch(switches::kDisableTabSwitcher)) {
92 return false;
93 }
94
rohitrao01585072016-02-27 03:17:5995 // Check if the finch experiment is turned on.
jbbeguef9c1eaa2016-01-13 15:55:5696 std::string group_name = base::FieldTrialList::FindFullName("IOSTabSwitcher");
rohitrao01585072016-02-27 03:17:5997 return base::StartsWith(group_name, "Enabled",
98 base::CompareCase::INSENSITIVE_ASCII);
jbbeguef9c1eaa2016-01-13 15:55:5699}
100
stkhapugin23ab73d82016-01-26 13:45:09101bool IsReadingListEnabled() {
102 return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableReadingList];
103}
104
noyauc7892c12016-05-12 12:22:01105bool IsAllBookmarksEnabled() {
106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
107 if (command_line->HasSwitch(switches::kEnableAllBookmarksView)) {
108 return true;
109 } else if (command_line->HasSwitch(switches::kDisableAllBookmarksView)) {
110 return false;
111 }
112
113 // Check if the finch experiment is turned on. Flag is off by default.
114 std::string group_name =
115 base::FieldTrialList::FindFullName("RemoveAllBookmarks");
116
117 return base::StartsWith(group_name, "Enabled",
118 base::CompareCase::INSENSITIVE_ASCII);
119}
120
drogerf83b91262015-03-05 19:45:19121} // namespace experimental_flags