| 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 #include <dispatch/dispatch.h> |
| 11 #import <Foundation/Foundation.h> | 11 #import <Foundation/Foundation.h> |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "components/autofill/core/common/autofill_switches.h" | 18 #include "components/autofill/core/common/autofill_switches.h" |
| 19 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h" | 19 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h" |
| 20 #include "components/variations/variations_associated_data.h" | 20 #include "components/variations/variations_associated_data.h" |
| 21 #include "ios/chrome/browser/chrome_switches.h" | 21 #include "ios/chrome/browser/chrome_switches.h" |
| 22 #include "ios/web/public/web_view_creation_util.h" | 22 #include "ios/web/public/web_view_creation_util.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 NSString* const kEnableAlertOnBackgroundUpload = | 25 NSString* const kEnableAlertOnBackgroundUpload = |
| 26 @"EnableAlertsOnBackgroundUpload"; | 26 @"EnableAlertsOnBackgroundUpload"; |
| 27 NSString* const kEnableViewCopyPasswords = @"EnableViewCopyPasswords"; | 27 NSString* const kEnableViewCopyPasswords = @"EnableViewCopyPasswords"; |
| 28 NSString* const kHeuristicsForPasswordGeneration = | 28 NSString* const kHeuristicsForPasswordGeneration = |
| 29 @"HeuristicsForPasswordGeneration"; | 29 @"HeuristicsForPasswordGeneration"; |
| 30 const char* const kWKWebViewTrialName = "IOSUseWKWebView"; |
| 30 | 31 |
| 31 enum class WKWebViewEligibility { | 32 enum class WKWebViewEligibility { |
| 32 // UNSET indicates that no explicit call to set eligibility has been made, | 33 // UNSET indicates that no explicit call to set eligibility has been made, |
| 33 // nor has a default value been assumed due to checking eligibility. | 34 // nor has a default value been assumed due to checking eligibility. |
| 34 UNSET, | 35 UNSET, |
| 35 ELIGIBLE, | 36 ELIGIBLE, |
| 36 INELIGIBLE | 37 INELIGIBLE |
| 37 }; | 38 }; |
| 38 WKWebViewEligibility g_wkwebview_trial_eligibility = | 39 WKWebViewEligibility g_wkwebview_trial_eligibility = |
| 39 WKWebViewEligibility::UNSET; | 40 WKWebViewEligibility::UNSET; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 }); | 122 }); |
| 122 | 123 |
| 123 return ok_to_check_finch; | 124 return ok_to_check_finch; |
| 124 } | 125 } |
| 125 | 126 |
| 126 bool IsWKWebViewEnabled() { | 127 bool IsWKWebViewEnabled() { |
| 127 if (!CanCheckWKWebViewExperiment()) { | 128 if (!CanCheckWKWebViewExperiment()) { |
| 128 return false; | 129 return false; |
| 129 } | 130 } |
| 130 | 131 |
| 132 // Now that it's been established that user is a candidate, set up the trial |
| 133 // by checking the group. |
| 134 std::string group_name = |
| 135 base::FieldTrialList::FindFullName(kWKWebViewTrialName); |
| 136 |
| 131 // Check if the experimental flag is turned on. | 137 // Check if the experimental flag is turned on. |
| 132 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 138 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 133 if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) | 139 if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) |
| 134 return true; | 140 return true; |
| 135 else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) | 141 else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) |
| 136 return false; | 142 return false; |
| 137 | 143 |
| 138 // Now that it's been established that user is a candidate, set up the trial | |
| 139 // by checking the group. | |
| 140 std::string group_name = | |
| 141 base::FieldTrialList::FindFullName("IOSUseWKWebView"); | |
| 142 | |
| 143 // Check if the finch experiment is turned on. | 144 // Check if the finch experiment is turned on. |
| 144 return base::StartsWith(group_name, "Enabled", | 145 return base::StartsWith(group_name, "Enabled", |
| 145 base::CompareCase::INSENSITIVE_ASCII); | 146 base::CompareCase::INSENSITIVE_ASCII); |
| 146 } | 147 } |
| 147 | 148 |
| 149 bool IsTargetedToWKWebViewExperimentControlGroup() { |
| 150 base::FieldTrial* trial = base::FieldTrialList::Find(kWKWebViewTrialName); |
| 151 if (!trial) |
| 152 return false; |
| 153 std::string group_name = trial->GetGroupNameWithoutActivation(); |
| 154 return base::StartsWith(group_name, "Control", |
| 155 base::CompareCase::INSENSITIVE_ASCII); |
| 156 } |
| 157 |
| 158 bool IsInWKWebViewExperimentControlGroup() { |
| 159 if (!CanCheckWKWebViewExperiment()) { |
| 160 return false; |
| 161 } |
| 162 std::string group_name = |
| 163 base::FieldTrialList::FindFullName(kWKWebViewTrialName); |
| 164 return base::StartsWith(group_name, "Control", |
| 165 base::CompareCase::INSENSITIVE_ASCII); |
| 166 } |
| 167 |
| 148 std::string GetWKWebViewSearchParams() { | 168 std::string GetWKWebViewSearchParams() { |
| 149 if (!CanCheckWKWebViewExperiment()) { | 169 if (!CanCheckWKWebViewExperiment()) { |
| 150 return std::string(); | 170 return std::string(); |
| 151 } | 171 } |
| 152 | 172 |
| 153 return variations::GetVariationParamValue("IOSUseWKWebView", "esrch"); | 173 return variations::GetVariationParamValue(kWKWebViewTrialName, "esrch"); |
| 154 } | 174 } |
| 155 | 175 |
| 156 bool AreKeyboardCommandsEnabled() { | 176 bool AreKeyboardCommandsEnabled() { |
| 157 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 177 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 158 switches::kDisableKeyboardCommands); | 178 switches::kDisableKeyboardCommands); |
| 159 } | 179 } |
| 160 | 180 |
| 161 bool IsViewCopyPasswordsEnabled() { | 181 bool IsViewCopyPasswordsEnabled() { |
| 162 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] | 182 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] |
| 163 objectForKey:kEnableViewCopyPasswords]; | 183 objectForKey:kEnableViewCopyPasswords]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 183 if ([[NSUserDefaults standardUserDefaults] | 203 if ([[NSUserDefaults standardUserDefaults] |
| 184 boolForKey:kHeuristicsForPasswordGeneration]) { | 204 boolForKey:kHeuristicsForPasswordGeneration]) { |
| 185 return true; | 205 return true; |
| 186 } | 206 } |
| 187 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 207 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 188 return command_line->HasSwitch( | 208 return command_line->HasSwitch( |
| 189 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); | 209 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); |
| 190 } | 210 } |
| 191 | 211 |
| 192 } // namespace experimental_flags | 212 } // namespace experimental_flags |
| OLD | NEW |