|
7 | 7 |
|
8 | 8 | #include "ios/chrome/browser/experimental_flags.h"
|
9 | 9 |
|
| 10 | +#include <dispatch/dispatch.h> |
10 | 11 | #import <Foundation/Foundation.h>
|
11 | 12 |
|
12 | 13 | #include <string>
|
@@ -74,49 +75,84 @@ bool IsLRUSnapshotCacheEnabled() {
|
74 | 75 | base::CompareCase::INSENSITIVE_ASCII);
|
75 | 76 | }
|
76 | 77 |
|
77 |
| -bool IsWKWebViewEnabled() { |
78 |
| - // If g_wkwebview_trial_eligibility hasn't been set, default it to |
79 |
| - // ineligibile. This ensures future calls to try to set it will DCHECK. |
80 |
| - if (g_wkwebview_trial_eligibility == WKWebViewEligibility::UNSET) { |
81 |
| - g_wkwebview_trial_eligibility = WKWebViewEligibility::INELIGIBLE; |
82 |
| - } |
| 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 | +} |
83 | 125 |
|
84 |
| - // If WKWebView isn't supported, don't activate the experiment at all. This |
85 |
| - // avoids someone being slotted into the WKWebView bucket (and thus reporting |
86 |
| - // as WKWebView), but actually running UIWebView. |
87 |
| - if (!web::IsWKWebViewSupported()) |
| 126 | +bool IsWKWebViewEnabled() { |
| 127 | + if (!CanCheckWKWebViewExperiment()) { |
88 | 128 | return false;
|
| 129 | + } |
89 | 130 |
|
90 |
| - // Check for a flag forcing a specific group. |
| 131 | + // Check if the experimental flag is turned on. |
91 | 132 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
92 |
| - bool force_enable = command_line->HasSwitch(switches::kEnableIOSWKWebView); |
93 |
| - bool force_disable = command_line->HasSwitch(switches::kDisableIOSWKWebView); |
94 |
| - bool trial_overridden = force_enable || force_disable; |
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) |
| 133 | + if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) |
| 134 | + return true; |
| 135 | + else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) |
102 | 136 | return false;
|
103 | 137 |
|
104 | 138 | // Now that it's been established that user is a candidate, set up the trial
|
105 | 139 | // by checking the group.
|
106 | 140 | std::string group_name =
|
107 | 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 | 143 | // Check if the finch experiment is turned on.
|
116 | 144 | return base::StartsWith(group_name, "Enabled",
|
117 | 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 | 156 | bool AreKeyboardCommandsEnabled() {
|
121 | 157 | return !base::CommandLine::ForCurrentProcess()->HasSwitch(
|
122 | 158 | switches::kDisableKeyboardCommands);
|
|
0 commit comments