OLD | NEW |
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 "content/renderer/usb/web_usb_client_impl.h" | 5 #include "content/renderer/usb/web_usb_client_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/move.h" | 15 #include "base/move.h" |
17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
18 #include "content/child/mojo/type_converters.h" | 17 #include "content/child/mojo/type_converters.h" |
19 #include "content/child/scoped_web_callbacks.h" | 18 #include "content/child/scoped_web_callbacks.h" |
20 #include "content/public/common/service_registry.h" | 19 #include "content/public/common/service_registry.h" |
21 #include "content/renderer/usb/type_converters.h" | 20 #include "content/renderer/usb/type_converters.h" |
22 #include "content/renderer/usb/web_usb_device_impl.h" | 21 #include "content/renderer/usb/web_usb_device_impl.h" |
23 #include "mojo/public/cpp/bindings/array.h" | 22 #include "mojo/public/cpp/bindings/array.h" |
24 #include "mojo/public/cpp/bindings/interface_request.h" | 23 #include "mojo/public/cpp/bindings/interface_request.h" |
25 #include "third_party/WebKit/public/platform/WebCallbacks.h" | 24 #include "third_party/WebKit/public/platform/WebCallbacks.h" |
26 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceFilter.h
" | 25 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceFilter.h
" |
27 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h" | 26 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h" |
28 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceRequestO
ptions.h" | 27 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceRequestO
ptions.h" |
29 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBError.h" | 28 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBError.h" |
30 | 29 |
31 namespace content { | 30 namespace content { |
32 | 31 |
33 namespace { | 32 namespace { |
34 | 33 |
35 const char kNoServiceError[] = "USB service unavailable."; | 34 const char kNoServiceError[] = "USB service unavailable."; |
36 | 35 |
37 // Generic default rejection handler for any WebUSB callbacks type. Assumes | 36 // Generic default rejection handler for any WebUSB callbacks type. Assumes |
38 // |CallbacksType| is a blink::WebCallbacks<T, const blink::WebUSBError&> | 37 // |CallbacksType| is a blink::WebCallbacks<T, const blink::WebUSBError&> |
39 // for any type |T|. | 38 // for any type |T|. |
40 template <typename CallbacksType> | 39 template <typename CallbacksType> |
41 void RejectCallbacksWithError(const blink::WebUSBError& error, | 40 void RejectCallbacksWithError(const blink::WebUSBError& error, |
42 scoped_ptr<CallbacksType> callbacks) { | 41 std::unique_ptr<CallbacksType> callbacks) { |
43 callbacks->onError(error); | 42 callbacks->onError(error); |
44 } | 43 } |
45 | 44 |
46 // Create a new ScopedWebCallbacks for WebUSB client callbacks, defaulting to | 45 // Create a new ScopedWebCallbacks for WebUSB client callbacks, defaulting to |
47 // a "no service" rejection. | 46 // a "no service" rejection. |
48 template <typename CallbacksType> | 47 template <typename CallbacksType> |
49 ScopedWebCallbacks<CallbacksType> MakeScopedUSBCallbacks( | 48 ScopedWebCallbacks<CallbacksType> MakeScopedUSBCallbacks( |
50 CallbacksType* callbacks) { | 49 CallbacksType* callbacks) { |
51 return make_scoped_web_callbacks( | 50 return make_scoped_web_callbacks( |
52 callbacks, | 51 callbacks, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 for (size_t i = 0; i < notification->devices_removed.size(); ++i) { | 170 for (size_t i = 0; i < notification->devices_removed.size(); ++i) { |
172 const device::usb::DeviceInfoPtr& device_info = | 171 const device::usb::DeviceInfoPtr& device_info = |
173 notification->devices_removed[i]; | 172 notification->devices_removed[i]; |
174 for (auto observer : observers_) | 173 for (auto observer : observers_) |
175 observer->onDeviceDisconnected(base::WrapUnique(new WebUSBDeviceImpl( | 174 observer->onDeviceDisconnected(base::WrapUnique(new WebUSBDeviceImpl( |
176 nullptr, mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); | 175 nullptr, mojo::ConvertTo<blink::WebUSBDeviceInfo>(device_info)))); |
177 } | 176 } |
178 } | 177 } |
179 | 178 |
180 } // namespace content | 179 } // namespace content |
OLD | NEW |