| Index: chrome/browser/usb/web_usb_permission_bubble_request.cc
|
| diff --git a/chrome/browser/usb/web_usb_permission_bubble_request.cc b/chrome/browser/usb/web_usb_permission_bubble_request.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d58f7827e2c29ef3e1dfe0db0712b14ba9857c55
|
| --- /dev/null
|
| +++ b/chrome/browser/usb/web_usb_permission_bubble_request.cc
|
| @@ -0,0 +1,46 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/usb/web_usb_permission_bubble_request.h"
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "device/devices_app/usb/type_converters.h"
|
| +#include "device/usb/usb_device.h"
|
| +
|
| +WebUsbPermissionBubbleRequest::WebUsbPermissionBubbleRequest(
|
| + const std::vector<scoped_refptr<device::UsbDevice>>& devices,
|
| + const webusb::WebUsbPermissionBubble::GetPermissionCallback& callback)
|
| + : devices_(devices), callback_(callback) {
|
| + num_devices_ = static_cast<int>(devices_.size());
|
| + for (const auto& device : devices) {
|
| + device_names_.push_back(base::UTF16ToASCII(device->product_string()));
|
| + }
|
| +}
|
| +
|
| +WebUsbPermissionBubbleRequest::~WebUsbPermissionBubbleRequest() {
|
| + if (!callback_.is_null()) {
|
| + callback_.Run(nullptr);
|
| + }
|
| +}
|
| +
|
| +void WebUsbPermissionBubbleRequest::Connect(int index) {
|
| + if (index >= 0 && index < num_devices_) {
|
| + device::usb::DeviceInfoPtr device_info_ptr =
|
| + device::usb::DeviceInfo::From(*devices_[index]);
|
| + callback_.Run(device_info_ptr.Pass());
|
| + } else {
|
| + callback_.Run(nullptr);
|
| + }
|
| + callback_.reset(); // reset callback so that it is only called once.
|
| +}
|
| +
|
| +void WebUsbPermissionBubbleRequest::Cancel() {
|
| + callback_.Run(nullptr);
|
| + callback_.reset(); // reset callback so that it is only called once.
|
| +}
|
| +
|
| +const std::vector<std::string>& WebUsbPermissionBubbleRequest::device_names()
|
| + const {
|
| + return device_names_;
|
| +}
|
|
|