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_MOJO_DEVICE_IMPL_H_ | 5 #ifndef DEVICE_USB_MOJO_DEVICE_IMPL_H_ |
6 #define DEVICE_USB_MOJO_DEVICE_IMPL_H_ | 6 #define DEVICE_USB_MOJO_DEVICE_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/scoped_observer.h" |
14 #include "device/usb/public/interfaces/device.mojom.h" | 15 #include "device/usb/public/interfaces/device.mojom.h" |
15 #include "device/usb/public/interfaces/permission_provider.mojom.h" | 16 #include "device/usb/public/interfaces/permission_provider.mojom.h" |
| 17 #include "device/usb/usb_device.h" |
16 #include "device/usb/usb_device_handle.h" | 18 #include "device/usb/usb_device_handle.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 19 #include "mojo/public/cpp/bindings/binding.h" |
18 #include "mojo/public/cpp/bindings/callback.h" | 20 #include "mojo/public/cpp/bindings/callback.h" |
19 #include "mojo/public/cpp/bindings/interface_request.h" | 21 #include "mojo/public/cpp/bindings/interface_request.h" |
20 | 22 |
21 namespace net { | 23 namespace net { |
22 class IOBuffer; | 24 class IOBuffer; |
23 } | 25 } |
24 | 26 |
25 namespace device { | 27 namespace device { |
26 namespace usb { | 28 namespace usb { |
27 | 29 |
28 // Implementation of the public Device interface. Instances of this class are | 30 // Implementation of the public Device interface. Instances of this class are |
29 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe | 31 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe |
30 // lifetime. | 32 // lifetime. |
31 class DeviceImpl : public Device { | 33 class DeviceImpl : public Device, public device::UsbDevice::Observer { |
32 public: | 34 public: |
33 DeviceImpl(scoped_refptr<UsbDevice> device, | 35 DeviceImpl(scoped_refptr<UsbDevice> device, |
34 PermissionProviderPtr permission_provider, | 36 PermissionProviderPtr permission_provider, |
35 mojo::InterfaceRequest<Device> request); | 37 mojo::InterfaceRequest<Device> request); |
36 ~DeviceImpl() override; | 38 ~DeviceImpl() override; |
37 | 39 |
38 private: | 40 private: |
39 // Closes the device if it's open. This will always set |device_handle_| to | 41 // Closes the device if it's open. This will always set |device_handle_| to |
40 // null. | 42 // null. |
41 void CloseHandle(); | 43 void CloseHandle(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 mojo::Array<uint32_t> packet_lengths, | 89 mojo::Array<uint32_t> packet_lengths, |
88 uint32_t timeout, | 90 uint32_t timeout, |
89 const IsochronousTransferInCallback& callback) override; | 91 const IsochronousTransferInCallback& callback) override; |
90 void IsochronousTransferOut( | 92 void IsochronousTransferOut( |
91 uint8_t endpoint_number, | 93 uint8_t endpoint_number, |
92 mojo::Array<uint8_t> data, | 94 mojo::Array<uint8_t> data, |
93 mojo::Array<uint32_t> packet_lengths, | 95 mojo::Array<uint32_t> packet_lengths, |
94 uint32_t timeout, | 96 uint32_t timeout, |
95 const IsochronousTransferOutCallback& callback) override; | 97 const IsochronousTransferOutCallback& callback) override; |
96 | 98 |
97 mojo::Binding<Device> binding_; | 99 // device::UsbDevice::Observer implementation: |
| 100 void OnDeviceRemoved(scoped_refptr<device::UsbDevice>) override; |
98 | 101 |
99 scoped_refptr<UsbDevice> device_; | 102 scoped_refptr<UsbDevice> device_; |
| 103 ScopedObserver<device::UsbDevice, device::UsbDevice::Observer> observer_; |
| 104 |
100 // The device handle. Will be null before the device is opened and after it | 105 // The device handle. Will be null before the device is opened and after it |
101 // has been closed. | 106 // has been closed. |
102 scoped_refptr<UsbDeviceHandle> device_handle_; | 107 scoped_refptr<UsbDeviceHandle> device_handle_; |
103 PermissionProviderPtr permission_provider_; | 108 PermissionProviderPtr permission_provider_; |
104 | 109 |
| 110 mojo::Binding<Device> binding_; |
105 base::WeakPtrFactory<DeviceImpl> weak_factory_; | 111 base::WeakPtrFactory<DeviceImpl> weak_factory_; |
106 | 112 |
107 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); | 113 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); |
108 }; | 114 }; |
109 | 115 |
110 } // namespace usb | 116 } // namespace usb |
111 } // namespace device | 117 } // namespace device |
112 | 118 |
113 #endif // DEVICE_USB_MOJO_DEVICE_IMPL_H_ | 119 #endif // DEVICE_USB_MOJO_DEVICE_IMPL_H_ |
OLD | NEW |