OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file can be empty. Its purpose is to contain the relatively short lived | 5 // This file can be empty. Its purpose is to contain the relatively short lived |
6 // definitions required for experimental flags. | 6 // definitions required for experimental flags. |
7 | 7 |
8 #include "ios/chrome/browser/experimental_flags.h" | 8 #include "ios/chrome/browser/experimental_flags.h" |
9 | 9 |
| 10 #include <dispatch/dispatch.h> |
10 #import <Foundation/Foundation.h> | 11 #import <Foundation/Foundation.h> |
11 | 12 |
12 #include <string> | 13 #include <string> |
13 | 14 |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h" | 17 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h" |
17 #include "components/variations/variations_associated_data.h" | 18 #include "components/variations/variations_associated_data.h" |
18 #include "ios/chrome/browser/chrome_switches.h" | 19 #include "ios/chrome/browser/chrome_switches.h" |
19 #include "ios/web/public/web_view_creation_util.h" | 20 #include "ios/web/public/web_view_creation_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return false; | 64 return false; |
64 } | 65 } |
65 | 66 |
66 // Check if the finch experiment is turned on. | 67 // Check if the finch experiment is turned on. |
67 std::string group_name = | 68 std::string group_name = |
68 base::FieldTrialList::FindFullName("IOSLRUSnapshotCache"); | 69 base::FieldTrialList::FindFullName("IOSLRUSnapshotCache"); |
69 return base::StartsWith(group_name, "Enabled", | 70 return base::StartsWith(group_name, "Enabled", |
70 base::CompareCase::INSENSITIVE_ASCII); | 71 base::CompareCase::INSENSITIVE_ASCII); |
71 } | 72 } |
72 | 73 |
| 74 // Helper method that returns true if it is safe to check the finch group for |
| 75 // the IOSUseWKWebView experiment. Some users are ineligible to be in the |
| 76 // trial, so for those users, this method returns false. If this method returns |
| 77 // false, do not check for the current finch group, as doing so will incorrectly |
| 78 // mark the current user as being in the experiment. |
| 79 bool CanCheckWKWebViewExperiment() { |
| 80 // True if this user is eligible for the WKWebView experiment and it is ok to |
| 81 // check the experiment group. |
| 82 static bool ok_to_check_finch = false; |
| 83 static dispatch_once_t once; |
| 84 dispatch_once(&once, ^{ |
| 85 // If g_wkwebview_trial_eligibility hasn't been set, default it to |
| 86 // ineligible. This ensures future calls to try to set it will DCHECK. |
| 87 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::UNSET) { |
| 88 g_wkwebview_trial_eligibility = WKWebViewEligibility::INELIGIBLE; |
| 89 } |
| 90 |
| 91 // If WKWebView isn't supported, don't activate the experiment at all. This |
| 92 // avoids someone being slotted into the WKWebView bucket (and thus |
| 93 // reporting as WKWebView), but actually running UIWebView. |
| 94 if (!web::IsWKWebViewSupported()) { |
| 95 ok_to_check_finch = false; |
| 96 return; |
| 97 } |
| 98 |
| 99 // Check for a flag forcing a specific group. Even ineligible users can be |
| 100 // opted into WKWebView if an override flag is set. |
| 101 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 102 bool trial_overridden = |
| 103 command_line->HasSwitch(switches::kEnableIOSWKWebView) || |
| 104 command_line->HasSwitch(switches::kDisableIOSWKWebView); |
| 105 |
| 106 // If the user isn't eligible for the trial (i.e., their state is such that |
| 107 // they should not be automatically selected for the group), and there's no |
| 108 // explicit override, don't check the group (again, to avoid having them |
| 109 // report as part of a group at all). |
| 110 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::INELIGIBLE && |
| 111 !trial_overridden) { |
| 112 ok_to_check_finch = false; |
| 113 return; |
| 114 } |
| 115 |
| 116 ok_to_check_finch = true; |
| 117 }); |
| 118 |
| 119 return ok_to_check_finch; |
| 120 } |
| 121 |
73 bool IsWKWebViewEnabled() { | 122 bool IsWKWebViewEnabled() { |
74 // If g_wkwebview_trial_eligibility hasn't been set, default it to | 123 if (!CanCheckWKWebViewExperiment()) { |
75 // ineligibile. This ensures future calls to try to set it will DCHECK. | 124 return false; |
76 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::UNSET) { | |
77 g_wkwebview_trial_eligibility = WKWebViewEligibility::INELIGIBLE; | |
78 } | 125 } |
79 | 126 |
80 // If WKWebView isn't supported, don't activate the experiment at all. This | 127 // Check if the experimental flag is turned on. |
81 // avoids someone being slotted into the WKWebView bucket (and thus reporting | |
82 // as WKWebView), but actually running UIWebView. | |
83 if (!web::IsWKWebViewSupported()) | |
84 return false; | |
85 | |
86 // Check for a flag forcing a specific group. | |
87 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 128 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
88 bool force_enable = command_line->HasSwitch(switches::kEnableIOSWKWebView); | 129 if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) |
89 bool force_disable = command_line->HasSwitch(switches::kDisableIOSWKWebView); | 130 return true; |
90 bool trial_overridden = force_enable || force_disable; | 131 else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) |
91 | |
92 // If the user isn't eligible for the trial (i.e., their state is such that | |
93 // they should not be automatically selected for the group), and there's no | |
94 // explicit override, don't check the group (again, to avoid having them | |
95 // report as part of a group at all). | |
96 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::INELIGIBLE && | |
97 !trial_overridden) | |
98 return false; | 132 return false; |
99 | 133 |
100 // Now that it's been established that user is a candidate, set up the trial | 134 // Now that it's been established that user is a candidate, set up the trial |
101 // by checking the group. | 135 // by checking the group. |
102 std::string group_name = | 136 std::string group_name = |
103 base::FieldTrialList::FindFullName("IOSUseWKWebView"); | 137 base::FieldTrialList::FindFullName("IOSUseWKWebView"); |
104 | 138 |
105 // Check if the experimental flag is turned on. | |
106 if (force_enable) | |
107 return true; | |
108 else if (force_disable) | |
109 return false; | |
110 | |
111 // Check if the finch experiment is turned on. | 139 // Check if the finch experiment is turned on. |
112 return base::StartsWith(group_name, "Enabled", | 140 return base::StartsWith(group_name, "Enabled", |
113 base::CompareCase::INSENSITIVE_ASCII); | 141 base::CompareCase::INSENSITIVE_ASCII); |
114 } | 142 } |
115 | 143 |
| 144 std::string GetWKWebViewSearchParams() { |
| 145 if (!CanCheckWKWebViewExperiment()) { |
| 146 return std::string(); |
| 147 } |
| 148 |
| 149 return variations::GetVariationParamValue("IOSUseWKWebView", "esrch"); |
| 150 } |
| 151 |
116 bool AreKeyboardCommandsEnabled() { | 152 bool AreKeyboardCommandsEnabled() { |
117 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 153 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
118 switches::kDisableKeyboardCommands); | 154 switches::kDisableKeyboardCommands); |
119 } | 155 } |
120 | 156 |
121 bool IsViewCopyPasswordsEnabled() { | 157 bool IsViewCopyPasswordsEnabled() { |
122 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] | 158 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] |
123 objectForKey:kEnableViewCopyPasswords]; | 159 objectForKey:kEnableViewCopyPasswords]; |
124 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"]) | 160 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"]) |
125 return true; | 161 return true; |
126 return false; | 162 return false; |
127 } | 163 } |
128 | 164 |
129 } // namespace experimental_flags | 165 } // namespace experimental_flags |
OLD | NEW |