|
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>
|
@@ -70,49 +71,84 @@ bool IsLRUSnapshotCacheEnabled() {
|
70 | 71 | base::CompareCase::INSENSITIVE_ASCII);
|
71 | 72 | }
|
72 | 73 |
|
73 |
| -bool IsWKWebViewEnabled() { |
74 |
| - // If g_wkwebview_trial_eligibility hasn't been set, default it to |
75 |
| - // ineligibile. This ensures future calls to try to set it will DCHECK. |
76 |
| - if (g_wkwebview_trial_eligibility == WKWebViewEligibility::UNSET) { |
77 |
| - g_wkwebview_trial_eligibility = WKWebViewEligibility::INELIGIBLE; |
78 |
| - } |
| 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 | +} |
79 | 121 |
|
80 |
| - // If WKWebView isn't supported, don't activate the experiment at all. This |
81 |
| - // avoids someone being slotted into the WKWebView bucket (and thus reporting |
82 |
| - // as WKWebView), but actually running UIWebView. |
83 |
| - if (!web::IsWKWebViewSupported()) |
| 122 | +bool IsWKWebViewEnabled() { |
| 123 | + if (!CanCheckWKWebViewExperiment()) { |
84 | 124 | return false;
|
| 125 | + } |
85 | 126 |
|
86 |
| - // Check for a flag forcing a specific group. |
| 127 | + // Check if the experimental flag is turned on. |
87 | 128 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
88 |
| - bool force_enable = command_line->HasSwitch(switches::kEnableIOSWKWebView); |
89 |
| - bool force_disable = command_line->HasSwitch(switches::kDisableIOSWKWebView); |
90 |
| - bool trial_overridden = force_enable || force_disable; |
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) |
| 129 | + if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) |
| 130 | + return true; |
| 131 | + else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) |
98 | 132 | return false;
|
99 | 133 |
|
100 | 134 | // Now that it's been established that user is a candidate, set up the trial
|
101 | 135 | // by checking the group.
|
102 | 136 | std::string group_name =
|
103 | 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 | 139 | // Check if the finch experiment is turned on.
|
112 | 140 | return base::StartsWith(group_name, "Enabled",
|
113 | 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 | 152 | bool AreKeyboardCommandsEnabled() {
|
117 | 153 | return !base::CommandLine::ForCurrentProcess()->HasSwitch(
|
118 | 154 | switches::kDisableKeyboardCommands);
|
|
0 commit comments