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 "chrome/browser/usb/web_usb_permission_bubble_request.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "device/devices_app/usb/type_converters.h" |
| 9 #include "device/usb/usb_device.h" |
| 10 |
| 11 WebUsbPermissionBubbleRequest::WebUsbPermissionBubbleRequest( |
| 12 const std::vector<scoped_refptr<device::UsbDevice>>& devices, |
| 13 const webusb::WebUsbPermissionBubble::GetPermissionCallback& callback) |
| 14 : devices_(devices), callback_(callback) { |
| 15 num_devices_ = static_cast<int>(devices_.size()); |
| 16 for (const auto& device : devices) { |
| 17 device_names_.push_back(base::UTF16ToASCII(device->product_string())); |
| 18 } |
| 19 } |
| 20 |
| 21 WebUsbPermissionBubbleRequest::~WebUsbPermissionBubbleRequest() { |
| 22 if (!callback_.is_null()) { |
| 23 callback_.Run(nullptr); |
| 24 } |
| 25 } |
| 26 |
| 27 void WebUsbPermissionBubbleRequest::Connect(int index) { |
| 28 if (index >= 0 && index < num_devices_) { |
| 29 device::usb::DeviceInfoPtr device_info_ptr = |
| 30 device::usb::DeviceInfo::From(*devices_[index]); |
| 31 callback_.Run(device_info_ptr.Pass()); |
| 32 } else { |
| 33 callback_.Run(nullptr); |
| 34 } |
| 35 callback_.reset(); // reset callback so that it is only called once. |
| 36 } |
| 37 |
| 38 void WebUsbPermissionBubbleRequest::Cancel() { |
| 39 callback_.Run(nullptr); |
| 40 callback_.reset(); // reset callback so that it is only called once. |
| 41 } |
| 42 |
| 43 const std::vector<std::string>& WebUsbPermissionBubbleRequest::device_names() |
| 44 const { |
| 45 return device_names_; |
| 46 } |
OLD | NEW |