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

Side by Side Diff: components/webusb/webusb_detector.cc

Issue 1289423002: Add webusb notification UI code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use USB_DEVICE_NAME instead of USB_DEVICE_PRODUCT_NAME in generated_resources.grd Created 5 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/webusb/webusb_detector.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "components/webusb/webusb_browser_client.h"
9 #include "device/core/device_client.h"
10 #include "device/usb/usb_device.h"
11 #include "device/usb/usb_ids.h"
12
13 namespace webusb {
14
15 WebUsbDetector::WebUsbDetector(WebUsbBrowserClient* webusb_browser_client)
16 : webusb_browser_client_(webusb_browser_client), observer_(this) {
17 Initialize();
18 }
19
20 WebUsbDetector::~WebUsbDetector() {}
21
22 void WebUsbDetector::Initialize() {
23 if (!webusb_browser_client_) {
24 return;
25 }
26
27 device::UsbService* usb_service =
28 device::DeviceClient::Get()->GetUsbService();
29 if (!usb_service)
30 return;
31
32 observer_.Add(usb_service);
33 }
34
35 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) {
36 const base::string16& product_name = device->product_string();
37 if (product_name.empty()) {
38 return;
39 }
40
41 const GURL& landing_page = device->webusb_landing_page();
42 if (!landing_page.is_valid()) {
43 return;
44 }
45
46 std::string notification_id = device->guid();
47
48 webusb_browser_client_->OnDeviceAdded(product_name, landing_page,
49 notification_id);
50 }
51
52 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) {
53 std::string notification_id = device->guid();
54 webusb_browser_client_->OnDeviceRemoved(notification_id);
55 }
56
57 } // namespace webusb
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698