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 #ifndef DEVICE_USB_DEVICE_MANAGER_IMPL_H_ | 5 #ifndef DEVICE_USB_DEVICE_MANAGER_IMPL_H_ |
6 #define DEVICE_USB_DEVICE_MANAGER_IMPL_H_ | 6 #define DEVICE_USB_DEVICE_MANAGER_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "device/usb/public/interfaces/device_manager.mojom.h" | 14 #include "device/usb/public/interfaces/device_manager.mojom.h" |
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | 16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
17 | 17 |
18 namespace base { | |
19 class SequencedTaskRunner; | |
20 } | |
21 | |
22 namespace mojo { | |
23 class ErrorHandler; | |
24 } | |
25 | |
26 namespace device { | 18 namespace device { |
27 | 19 |
28 class UsbDevice; | 20 class UsbDevice; |
29 class UsbDeviceFilter; | 21 class UsbDeviceFilter; |
30 class UsbDeviceHandle; | 22 class UsbDeviceHandle; |
31 | 23 |
32 namespace usb { | 24 namespace usb { |
33 | 25 |
34 class DeviceManagerDelegate; | 26 class DeviceManagerDelegate; |
35 | 27 |
36 // Implementation of the public DeviceManager interface. This interface can be | 28 // Implementation of the public DeviceManager interface. Clients in the browser |
37 // requested from the devices app located at "system:devices", if available. | 29 // can connect to this service via DeviceClient::ConnectToUSBDeviceManager. |
38 class DeviceManagerImpl : public DeviceManager { | 30 class DeviceManagerImpl : public DeviceManager { |
39 public: | 31 public: |
40 DeviceManagerImpl( | 32 DeviceManagerImpl(mojo::InterfaceRequest<DeviceManager> request, |
41 mojo::InterfaceRequest<DeviceManager> request, | 33 scoped_ptr<DeviceManagerDelegate> delegate); |
42 scoped_ptr<DeviceManagerDelegate> delegate, | |
43 scoped_refptr<base::SequencedTaskRunner> service_task_runner); | |
44 ~DeviceManagerImpl() override; | 34 ~DeviceManagerImpl() override; |
45 | 35 |
46 void set_error_handler(mojo::ErrorHandler* error_handler); | |
47 | |
48 private: | 36 private: |
49 // DeviceManager implementation: | 37 // DeviceManager implementation: |
50 void GetDevices(EnumerationOptionsPtr options, | 38 void GetDevices(EnumerationOptionsPtr options, |
51 const GetDevicesCallback& callback) override; | 39 const GetDevicesCallback& callback) override; |
52 void OpenDevice(const mojo::String& guid, | 40 void OpenDevice(const mojo::String& guid, |
53 mojo::InterfaceRequest<Device> device_request, | 41 mojo::InterfaceRequest<Device> device_request, |
54 const OpenDeviceCallback& callback) override; | 42 const OpenDeviceCallback& callback) override; |
55 | 43 |
56 // Callback to handle the async response from the underlying UsbService. | 44 // Callback to handle the async response from the underlying UsbService. |
57 void OnGetDevices(EnumerationOptionsPtr options, | 45 void OnGetDevices(const GetDevicesCallback& callback, |
58 const GetDevicesCallback& callback, | 46 const std::vector<UsbDeviceFilter>& filters, |
59 const std::vector<scoped_refptr<UsbDevice>>& devices); | 47 const std::vector<scoped_refptr<UsbDevice>>& devices); |
60 | 48 |
| 49 // Callback to handle the async Open response from a UsbDevice. |
| 50 void OnOpenDevice(const OpenDeviceCallback& callback, |
| 51 mojo::InterfaceRequest<Device> device_request, |
| 52 scoped_refptr<UsbDeviceHandle> device_handle); |
| 53 |
61 mojo::StrongBinding<DeviceManager> binding_; | 54 mojo::StrongBinding<DeviceManager> binding_; |
62 | 55 |
63 scoped_ptr<DeviceManagerDelegate> delegate_; | 56 scoped_ptr<DeviceManagerDelegate> delegate_; |
64 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | |
65 | 57 |
66 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_; | 58 base::WeakPtrFactory<DeviceManagerImpl> weak_factory_; |
67 | 59 |
68 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl); | 60 DISALLOW_COPY_AND_ASSIGN(DeviceManagerImpl); |
69 }; | 61 }; |
70 | 62 |
71 } // namespace usb | 63 } // namespace usb |
72 } // namespace device | 64 } // namespace device |
73 | 65 |
74 #endif // DEVICE_USB_DEVICE_MANAGER_IMPL_H_ | 66 #endif // DEVICE_USB_DEVICE_MANAGER_IMPL_H_ |
OLD | NEW |