| OLD | NEW |
| (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 "components/webusb/webusb_browser_client.h" | |
| 8 #include "device/core/device_client.h" | |
| 9 #include "device/usb/usb_device.h" | |
| 10 #include "device/usb/usb_ids.h" | |
| 11 | |
| 12 namespace webusb { | |
| 13 | |
| 14 WebUsbDetector::WebUsbDetector(WebUsbBrowserClient* webusb_browser_client) | |
| 15 : webusb_browser_client_(webusb_browser_client), observer_(this) { | |
| 16 Initialize(); | |
| 17 } | |
| 18 | |
| 19 WebUsbDetector::~WebUsbDetector() {} | |
| 20 | |
| 21 void WebUsbDetector::Initialize() { | |
| 22 if (!webusb_browser_client_) { | |
| 23 return; | |
| 24 } | |
| 25 | |
| 26 device::UsbService* usb_service = | |
| 27 device::DeviceClient::Get()->GetUsbService(); | |
| 28 if (!usb_service) | |
| 29 return; | |
| 30 | |
| 31 observer_.Add(usb_service); | |
| 32 } | |
| 33 | |
| 34 void WebUsbDetector::OnDeviceAdded(scoped_refptr<device::UsbDevice> device) { | |
| 35 const base::string16& product_name = device->product_string(); | |
| 36 if (product_name.empty()) { | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 const GURL& landing_page = device->webusb_landing_page(); | |
| 41 if (!landing_page.is_valid()) { | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 std::string notification_id = device->guid(); | |
| 46 | |
| 47 webusb_browser_client_->OnDeviceAdded(product_name, landing_page, | |
| 48 notification_id); | |
| 49 } | |
| 50 | |
| 51 void WebUsbDetector::OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) { | |
| 52 std::string notification_id = device->guid(); | |
| 53 webusb_browser_client_->OnDeviceRemoved(notification_id); | |
| 54 } | |
| 55 | |
| 56 } // namespace webusb | |
| OLD | NEW |