Skip to content

Commit

Permalink
usb: Add separate flag for the device detector
Browse files Browse the repository at this point in the history
Now that the new USB backend has been enabled by default on Windows we
want to remove the old code path but there are still some rare issues
which can be caused by Chrome enumerating USB devices. This flag should
provide a workaround for those issues by not having USB enumeration
running at all times while not requiring us to continue to support the
old backend since the new one is overall better.

Bug: 1041289,1167343,1239949
Change-Id: I45b864018a56f77bf0f241220a7fc553efa68742
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3183620
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#924994}
  • Loading branch information
reillyeon authored and Chromium LUCI CQ committed Sep 25, 2021
1 parent 118c41d commit 3c560fa
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3315,6 +3315,10 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kWebBluetoothNewPermissionsBackendDescription,
kOsAndroid | kOsDesktop,
FEATURE_VALUE_TYPE(features::kWebBluetoothNewPermissionsBackend)},
{"enable-webusb-device-detection",
flag_descriptions::kWebUsbDeviceDetectionName,
flag_descriptions::kWebUsbDeviceDetectionDescription, kOsDesktop,
FEATURE_VALUE_TYPE(features::kWebUsbDeviceDetection)},
#if defined(USE_AURA)
{"overscroll-history-navigation",
flag_descriptions::kOverscrollHistoryNavigationName,
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/browser_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ bool ShouldTriggerNetworkDataMigration() {
return false;
}

// Enables runtime detection of USB devices which provide a WebUSB landing page
// descriptor.
const base::Feature kWebUsbDeviceDetection{"WebUsbDeviceDetection",
base::FEATURE_ENABLED_BY_DEFAULT};

} // namespace features
2 changes: 2 additions & 0 deletions chrome/browser/browser_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern const base::Feature kTriggerNetworkDataMigration;
// determine whether data migration should occur or not.
bool ShouldTriggerNetworkDataMigration();

extern const base::Feature kWebUsbDeviceDetection;

} // namespace features

#endif // CHROME_BROWSER_BROWSER_FEATURES_H_
5 changes: 5 additions & 0 deletions chrome/browser/flag-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,11 @@
"owners": [ "mcasas", "chromeos-gfx-video@google.com" ],
"expiry_milestone": 88
},
{
"name": "enable-webusb-device-detection",
"owners": [ "reillyg", "deviceapi-team@google.com" ],
"expiry_milestone": 104
},
{
"name": "enable-windows-gaming-input-data-fetcher",
"owners": [ "qiaye@microsoft.com" ],
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,13 @@ const char kWebrtcUseMinMaxVEADimensionsDescription[] =
"When enabled, WebRTC will only use the Video Encode Accelerator for "
"video resolutions inside those published as supported.";

const char kWebUsbDeviceDetectionName[] =
"Automatic detection of WebUSB-compatible devices";
const char kWebUsbDeviceDetectionDescription[] =
"When enabled, the user will be notified when a device which advertises "
"support for WebUSB is connected. Disable if problems with USB devices are "
"observed when the browser is running.";

const char kWebXrForceRuntimeName[] = "Force WebXr Runtime";
const char kWebXrForceRuntimeDescription[] =
"Force the browser to use a particular runtime, even if it would not "
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,9 @@ extern const char kWebrtcSrtpAesGcmDescription[];
extern const char kWebrtcUseMinMaxVEADimensionsName[];
extern const char kWebrtcUseMinMaxVEADimensionsDescription[];

extern const char kWebUsbDeviceDetectionName[];
extern const char kWebUsbDeviceDetectionDescription[];

extern const char kWebXrForceRuntimeName[];
extern const char kWebXrForceRuntimeDescription[];

Expand Down
11 changes: 4 additions & 7 deletions chrome/browser/usb/web_usb_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/net/referrer.h"
#include "chrome/browser/notifications/system_notification_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand All @@ -28,7 +29,6 @@
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/device_service.h"
#include "content/public/browser/web_contents.h"
#include "device/base/features.h"
#include "services/device/public/mojom/usb_device.mojom.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
Expand Down Expand Up @@ -184,13 +184,10 @@ WebUsbDetector::WebUsbDetector() = default;
WebUsbDetector::~WebUsbDetector() = default;

void WebUsbDetector::Initialize() {
#if defined(OS_WIN)
// The WebUSB device detector is disabled on Windows due to jank and hangs
// caused by enumerating devices. The new USB backend is designed to resolve
// these issues so enable it for testing. https://crbug.com/656702
if (!base::FeatureList::IsEnabled(device::kNewUsbBackend))
// The WebUSB device detector can be disabled if it causes trouble due to
// buggy devices and drivers.
if (!base::FeatureList::IsEnabled(features::kWebUsbDeviceDetection))
return;
#endif // defined(OS_WIN)

// Tests may set a fake manager.
if (!device_manager_) {
Expand Down
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50086,6 +50086,7 @@ from previous Chrome versions.
<int value="-15879016"
label="OmniboxUIExperimentUnboldSuggestionText:disabled"/>
<int value="-13918890" label="disable-download-notification"/>
<int value="-13180015" label="WebUsbDeviceDetection:disabled"/>
<int value="-12225998" label="ShareButtonInTopToolbar:disabled"/>
<int value="-11983392"
label="MagnifierContinuousMouseFollowingModeSetting:enabled"/>
Expand Down Expand Up @@ -52410,6 +52411,7 @@ from previous Chrome versions.
<int value="1803465156" label="enable-zero-suggest-most-visited"/>
<int value="1803470125" label="SyncUSSSessions:enabled"/>
<int value="1803914892" label="TemporaryUnexpireFlagsM76:enabled"/>
<int value="1806450300" label="WebUsbDeviceDetection:enabled"/>
<int value="1807374811" label="CCTModuleCache:enabled"/>
<int value="1809940714" label="SpeculativeLaunchServiceWorker:disabled"/>
<int value="1810258949" label="DisplayLocking:enabled"/>
Expand Down

0 comments on commit 3c560fa

Please sign in to comment.