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

Side by Side Diff: chrome/browser/usb/web_usb_detector.cc

Issue 2734933003: Enable WebUSB device detection when using the new Windows USB backend. (Closed)
Patch Set: Created 3 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/usb/web_usb_detector.h" 5 #include "chrome/browser/usb/web_usb_detector.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/feature_list.h"
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/net/referrer.h" 13 #include "chrome/browser/net/referrer.h"
13 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "chrome/grit/theme_resources.h" 18 #include "chrome/grit/theme_resources.h"
18 #include "content/public/common/origin_util.h" 19 #include "content/public/common/origin_util.h"
19 #include "device/base/device_client.h" 20 #include "device/base/device_client.h"
21 #include "device/base/features.h"
20 #include "device/usb/usb_device.h" 22 #include "device/usb/usb_device.h"
21 #include "device/usb/usb_ids.h" 23 #include "device/usb/usb_ids.h"
22 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/page_transition_types.h" 25 #include "ui/base/page_transition_types.h"
24 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/window_open_disposition.h" 27 #include "ui/base/window_open_disposition.h"
26 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
27 #include "ui/message_center/message_center.h" 29 #include "ui/message_center/message_center.h"
28 #include "ui/message_center/notification.h" 30 #include "ui/message_center/notification.h"
29 #include "ui/message_center/notification_delegate.h" 31 #include "ui/message_center/notification_delegate.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); 113 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate);
112 }; 114 };
113 115
114 } // namespace 116 } // namespace
115 117
116 WebUsbDetector::WebUsbDetector() : observer_(this) {} 118 WebUsbDetector::WebUsbDetector() : observer_(this) {}
117 119
118 WebUsbDetector::~WebUsbDetector() {} 120 WebUsbDetector::~WebUsbDetector() {}
119 121
120 void WebUsbDetector::Initialize() { 122 void WebUsbDetector::Initialize() {
121 // Disabled on Windows due to jank and hangs caused by enumerating devices. 123 #if defined(OS_WIN)
122 // https://crbug.com/656702 124 // The WebUSB device detector is disabled on Windows due to jank and hangs
123 #if !defined(OS_WIN) 125 // caused by enumerating devices. The new USB backend is designed to resolve
126 // these issues so enable it for testing. https://crbug.com/656702
127 if (!base::FeatureList::IsEnabled(device::kNewUsbBackend))
128 return;
129 #endif // defined(OS_WIN)
130
124 SCOPED_UMA_HISTOGRAM_TIMER("WebUsb.DetectorInitialization"); 131 SCOPED_UMA_HISTOGRAM_TIMER("WebUsb.DetectorInitialization");
125 device::UsbService* usb_service = 132 device::UsbService* usb_service =
126 device::DeviceClient::Get()->GetUsbService(); 133 device::DeviceClient::Get()->GetUsbService();
127 if (!usb_service) 134 if (!usb_service)
128 return; 135 return;
129 136
130 observer_.Add(usb_service); 137 observer_.Add(usb_service);
131 #endif
132 } 138 }
133 139
134 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) { 140 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) {
135 const base::string16& product_name = device->product_string(); 141 const base::string16& product_name = device->product_string();
136 if (product_name.empty()) { 142 if (product_name.empty()) {
137 return; 143 return;
138 } 144 }
139 145
140 const GURL& landing_page = device->webusb_landing_page(); 146 const GURL& landing_page = device->webusb_landing_page();
141 if (!landing_page.is_valid() || !content::IsOriginSecure(landing_page)) { 147 if (!landing_page.is_valid() || !content::IsOriginSecure(landing_page)) {
(...skipping 25 matching lines...) Expand all
167 } 173 }
168 174
169 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) { 175 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) {
170 std::string notification_id = device->guid(); 176 std::string notification_id = device->guid();
171 message_center::MessageCenter* message_center = 177 message_center::MessageCenter* message_center =
172 message_center::MessageCenter::Get(); 178 message_center::MessageCenter::Get();
173 if (message_center->FindVisibleNotificationById(notification_id)) { 179 if (message_center->FindVisibleNotificationById(notification_id)) {
174 message_center->RemoveNotification(notification_id, false /* by_user */); 180 message_center->RemoveNotification(notification_id, false /* by_user */);
175 } 181 }
176 } 182 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698