Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1284)

Side by Side Diff: device/devices_app/usb/device_impl.h

Issue 1369643002: Add configuration and interface permission checks to DeviceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new method ot Android USB mocks. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_IMPL_H_ 5 #ifndef DEVICE_USB_DEVICE_IMPL_H_
6 #define DEVICE_USB_DEVICE_IMPL_H_ 6 #define DEVICE_USB_DEVICE_IMPL_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "device/devices_app/usb/public/interfaces/device.mojom.h" 12 #include "device/devices_app/usb/public/interfaces/device.mojom.h"
13 #include "device/devices_app/usb/public/interfaces/permission_provider.mojom.h"
13 #include "device/usb/usb_device_handle.h" 14 #include "device/usb/usb_device_handle.h"
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" 16 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" 17 #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"
17 18
18 namespace net { 19 namespace net {
19 class IOBuffer; 20 class IOBuffer;
20 } 21 }
21 22
22 namespace device { 23 namespace device {
23 namespace usb { 24 namespace usb {
24 25
25 // Implementation of the public Device interface. Instances of this class are 26 // Implementation of the public Device interface. Instances of this class are
26 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe 27 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe
27 // lifetime. 28 // lifetime.
28 class DeviceImpl : public Device { 29 class DeviceImpl : public Device {
29 public: 30 public:
30 DeviceImpl(scoped_refptr<UsbDevice> device,
31 mojo::InterfaceRequest<Device> request);
32 ~DeviceImpl() override;
33
34 private:
35 using MojoTransferInCallback = 31 using MojoTransferInCallback =
36 mojo::Callback<void(TransferStatus, mojo::Array<uint8_t>)>; 32 mojo::Callback<void(TransferStatus, mojo::Array<uint8_t>)>;
37 33
38 using MojoTransferOutCallback = mojo::Callback<void(TransferStatus)>; 34 using MojoTransferOutCallback = mojo::Callback<void(TransferStatus)>;
39 35
36 DeviceImpl(scoped_refptr<UsbDevice> device,
37 PermissionProviderPtr permission_provider,
38 mojo::InterfaceRequest<Device> request);
39 ~DeviceImpl() override;
40
41 private:
40 // Closes the device if it's open. This will always set |device_handle_| to 42 // Closes the device if it's open. This will always set |device_handle_| to
41 // null. 43 // null.
42 void CloseHandle(); 44 void CloseHandle();
43 45
46 // Checks interface permissions for control transfers.
47 void HasControlTransferPermission(ControlTransferRecipient recipient,
48 uint16_t index,
49 const base::Callback<void(bool)>& callback);
50
44 // Handles completion of an open request. 51 // Handles completion of an open request.
45 void OnOpen(const OpenCallback& callback, 52 void OnOpen(const OpenCallback& callback,
46 scoped_refptr<device::UsbDeviceHandle> handle); 53 scoped_refptr<device::UsbDeviceHandle> handle);
47 54
48 // Handles completion of an inbound transfer on the UsbDeviceHandle.
49 void OnTransferIn(const MojoTransferInCallback& callback,
50 UsbTransferStatus status,
51 scoped_refptr<net::IOBuffer> data,
52 size_t size);
53
54 // Handles completion of an outbound transfer on the UsbDeviceHandle.
55 void OnTransferOut(const MojoTransferOutCallback& callback,
56 UsbTransferStatus status,
57 scoped_refptr<net::IOBuffer> data,
58 size_t size);
59
60 // Handles completion of an inbound isochronous transfer on the
61 // UsbDeviceHandle.
62 void OnIsochronousTransferIn(const IsochronousTransferInCallback& callback,
63 uint32_t packet_length,
64 UsbTransferStatus status,
65 scoped_refptr<net::IOBuffer> data,
66 size_t size);
67
68 // Handles completion of an outbound isochronous transfer on the
69 // UsbDeviceHandle.
70 void OnIsochronousTransferOut(const MojoTransferOutCallback& callback,
71 UsbTransferStatus status,
72 scoped_refptr<net::IOBuffer> data,
73 size_t size);
74
75 // Device implementation: 55 // Device implementation:
76 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override; 56 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override;
77 void GetConfiguration(const GetConfigurationCallback& callback) override; 57 void GetConfiguration(const GetConfigurationCallback& callback) override;
78 void Open(const OpenCallback& callback) override; 58 void Open(const OpenCallback& callback) override;
79 void Close(const CloseCallback& callback) override; 59 void Close(const CloseCallback& callback) override;
80 void SetConfiguration(uint8_t value, 60 void SetConfiguration(uint8_t value,
81 const SetConfigurationCallback& callback) override; 61 const SetConfigurationCallback& callback) override;
82 void ClaimInterface(uint8_t interface_number, 62 void ClaimInterface(uint8_t interface_number,
83 const ClaimInterfaceCallback& callback) override; 63 const ClaimInterfaceCallback& callback) override;
84 void ReleaseInterface(uint8_t interface_number, 64 void ReleaseInterface(uint8_t interface_number,
(...skipping 25 matching lines...) Expand all
110 uint32_t num_packets, 90 uint32_t num_packets,
111 uint32_t packet_length, 91 uint32_t packet_length,
112 uint32_t timeout, 92 uint32_t timeout,
113 const IsochronousTransferInCallback& callback) override; 93 const IsochronousTransferInCallback& callback) override;
114 void IsochronousTransferOut( 94 void IsochronousTransferOut(
115 uint8_t endpoint_number, 95 uint8_t endpoint_number,
116 mojo::Array<mojo::Array<uint8_t>> packets, 96 mojo::Array<mojo::Array<uint8_t>> packets,
117 uint32_t timeout, 97 uint32_t timeout,
118 const IsochronousTransferOutCallback& callback) override; 98 const IsochronousTransferOutCallback& callback) override;
119 99
120 mojo::StrongBinding<Device> binding_; 100 mojo::Binding<Device> binding_;
121 101
122 scoped_refptr<UsbDevice> device_; 102 scoped_refptr<UsbDevice> device_;
123 // The device handle. Will be null before the device is opened and after it 103 // The device handle. Will be null before the device is opened and after it
124 // has been closed. 104 // has been closed.
125 scoped_refptr<UsbDeviceHandle> device_handle_; 105 scoped_refptr<UsbDeviceHandle> device_handle_;
106 PermissionProviderPtr permission_provider_;
126 107
127 base::WeakPtrFactory<DeviceImpl> weak_factory_; 108 base::WeakPtrFactory<DeviceImpl> weak_factory_;
128 109
129 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); 110 DISALLOW_COPY_AND_ASSIGN(DeviceImpl);
130 }; 111 };
131 112
132 } // namespace usb 113 } // namespace usb
133 } // namespace device 114 } // namespace device
134 115
135 #endif // DEVICE_USB_DEVICE_IMPL_H_ 116 #endif // DEVICE_USB_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698