Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ios/chrome/browser/experimental_flags.mm

Issue 1495643002: Adds an IOSWebViewTypeParam() method to SearchTermsData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "components/autofill/core/common/autofill_switches.h" 18 #include "components/autofill/core/common/autofill_switches.h"
18 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h" 19 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h"
19 #include "components/variations/variations_associated_data.h" 20 #include "components/variations/variations_associated_data.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return false; 68 return false;
68 } 69 }
69 70
70 // Check if the finch experiment is turned on. 71 // Check if the finch experiment is turned on.
71 std::string group_name = 72 std::string group_name =
72 base::FieldTrialList::FindFullName("IOSLRUSnapshotCache"); 73 base::FieldTrialList::FindFullName("IOSLRUSnapshotCache");
73 return base::StartsWith(group_name, "Enabled", 74 return base::StartsWith(group_name, "Enabled",
74 base::CompareCase::INSENSITIVE_ASCII); 75 base::CompareCase::INSENSITIVE_ASCII);
75 } 76 }
76 77
78 // Helper method that returns true if it is safe to check the finch group for
79 // the IOSUseWKWebView experiment. Some users are ineligible to be in the
80 // trial, so for those users, this method returns false. If this method returns
81 // false, do not check for the current finch group, as doing so will incorrectly
82 // mark the current user as being in the experiment.
83 bool CanCheckWKWebViewExperiment() {
84 // True if this user is eligible for the WKWebView experiment and it is ok to
85 // check the experiment group.
86 static bool ok_to_check_finch = false;
87 static dispatch_once_t once;
88 dispatch_once(&once, ^{
89 // If g_wkwebview_trial_eligibility hasn't been set, default it to
90 // ineligible. This ensures future calls to try to set it will DCHECK.
91 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::UNSET) {
92 g_wkwebview_trial_eligibility = WKWebViewEligibility::INELIGIBLE;
93 }
94
95 // If WKWebView isn't supported, don't activate the experiment at all. This
96 // avoids someone being slotted into the WKWebView bucket (and thus
97 // reporting as WKWebView), but actually running UIWebView.
98 if (!web::IsWKWebViewSupported()) {
99 ok_to_check_finch = false;
100 return;
101 }
102
103 // Check for a flag forcing a specific group. Even ineligible users can be
104 // opted into WKWebView if an override flag is set.
105 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
106 bool trial_overridden =
107 command_line->HasSwitch(switches::kEnableIOSWKWebView) ||
108 command_line->HasSwitch(switches::kDisableIOSWKWebView);
109
110 // If the user isn't eligible for the trial (i.e., their state is such that
111 // they should not be automatically selected for the group), and there's no
112 // explicit override, don't check the group (again, to avoid having them
113 // report as part of a group at all).
114 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::INELIGIBLE &&
115 !trial_overridden) {
116 ok_to_check_finch = false;
117 return;
118 }
119
120 ok_to_check_finch = true;
121 });
122
123 return ok_to_check_finch;
124 }
125
77 bool IsWKWebViewEnabled() { 126 bool IsWKWebViewEnabled() {
78 // If g_wkwebview_trial_eligibility hasn't been set, default it to 127 if (!CanCheckWKWebViewExperiment()) {
79 // ineligibile. This ensures future calls to try to set it will DCHECK. 128 return false;
80 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::UNSET) {
81 g_wkwebview_trial_eligibility = WKWebViewEligibility::INELIGIBLE;
82 } 129 }
83 130
84 // If WKWebView isn't supported, don't activate the experiment at all. This 131 // Check if the experimental flag is turned on.
85 // avoids someone being slotted into the WKWebView bucket (and thus reporting
86 // as WKWebView), but actually running UIWebView.
87 if (!web::IsWKWebViewSupported())
88 return false;
89
90 // Check for a flag forcing a specific group.
91 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 132 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
92 bool force_enable = command_line->HasSwitch(switches::kEnableIOSWKWebView); 133 if (command_line->HasSwitch(switches::kEnableIOSWKWebView))
93 bool force_disable = command_line->HasSwitch(switches::kDisableIOSWKWebView); 134 return true;
94 bool trial_overridden = force_enable || force_disable; 135 else if (command_line->HasSwitch(switches::kDisableIOSWKWebView))
95
96 // If the user isn't eligible for the trial (i.e., their state is such that
97 // they should not be automatically selected for the group), and there's no
98 // explicit override, don't check the group (again, to avoid having them
99 // report as part of a group at all).
100 if (g_wkwebview_trial_eligibility == WKWebViewEligibility::INELIGIBLE &&
101 !trial_overridden)
102 return false; 136 return false;
103 137
104 // Now that it's been established that user is a candidate, set up the trial 138 // Now that it's been established that user is a candidate, set up the trial
105 // by checking the group. 139 // by checking the group.
106 std::string group_name = 140 std::string group_name =
107 base::FieldTrialList::FindFullName("IOSUseWKWebView"); 141 base::FieldTrialList::FindFullName("IOSUseWKWebView");
108 142
109 // Check if the experimental flag is turned on.
110 if (force_enable)
111 return true;
112 else if (force_disable)
113 return false;
114
115 // Check if the finch experiment is turned on. 143 // Check if the finch experiment is turned on.
116 return base::StartsWith(group_name, "Enabled", 144 return base::StartsWith(group_name, "Enabled",
117 base::CompareCase::INSENSITIVE_ASCII); 145 base::CompareCase::INSENSITIVE_ASCII);
118 } 146 }
119 147
148 std::string GetWKWebViewSearchParams() {
149 if (!CanCheckWKWebViewExperiment()) {
150 return std::string();
151 }
152
153 return variations::GetVariationParamValue("IOSUseWKWebView", "esrch");
154 }
155
120 bool AreKeyboardCommandsEnabled() { 156 bool AreKeyboardCommandsEnabled() {
121 return !base::CommandLine::ForCurrentProcess()->HasSwitch( 157 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
122 switches::kDisableKeyboardCommands); 158 switches::kDisableKeyboardCommands);
123 } 159 }
124 160
125 bool IsViewCopyPasswordsEnabled() { 161 bool IsViewCopyPasswordsEnabled() {
126 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults] 162 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults]
127 objectForKey:kEnableViewCopyPasswords]; 163 objectForKey:kEnableViewCopyPasswords];
128 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"]) 164 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"])
129 return true; 165 return true;
(...skipping 17 matching lines...) Expand all
147 if ([[NSUserDefaults standardUserDefaults] 183 if ([[NSUserDefaults standardUserDefaults]
148 boolForKey:kHeuristicsForPasswordGeneration]) { 184 boolForKey:kHeuristicsForPasswordGeneration]) {
149 return true; 185 return true;
150 } 186 }
151 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 187 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
152 return command_line->HasSwitch( 188 return command_line->HasSwitch(
153 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration); 189 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration);
154 } 190 }
155 191
156 } // namespace experimental_flags 192 } // namespace experimental_flags
OLDNEW
« no previous file with comments | « ios/chrome/browser/experimental_flags.h ('k') | ios/chrome/browser/search_engines/ui_thread_search_terms_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698