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

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

Issue 2821723002: Move classes in the device.usb Mojo namespace to device.mojom (Closed)
Patch Set: fix usb_descriptors_fuzzer Created 3 years, 8 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_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 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/scoped_observer.h" 15 #include "base/scoped_observer.h"
16 #include "device/usb/mojo/permission_provider.h" 16 #include "device/usb/mojo/permission_provider.h"
17 #include "device/usb/public/interfaces/device.mojom.h" 17 #include "device/usb/public/interfaces/device.mojom.h"
18 #include "device/usb/usb_device.h" 18 #include "device/usb/usb_device.h"
19 #include "device/usb/usb_device_handle.h" 19 #include "device/usb/usb_device_handle.h"
20 #include "mojo/public/cpp/bindings/strong_binding.h" 20 #include "mojo/public/cpp/bindings/strong_binding.h"
21 21
22 namespace device { 22 namespace device {
23 namespace usb { 23 namespace usb {
24 24
25 class PermissionProvider; 25 class PermissionProvider;
26 26
27 // Implementation of the public Device interface. Instances of this class are 27 // Implementation of the public Device interface. Instances of this class are
28 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe 28 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe
29 // lifetime. 29 // lifetime.
30 class DeviceImpl : public Device, public device::UsbDevice::Observer { 30 class DeviceImpl : public mojom::UsbDevice, public device::UsbDevice::Observer {
31 public: 31 public:
32 static void Create(scoped_refptr<UsbDevice> device, 32 static void Create(scoped_refptr<device::UsbDevice> device,
33 base::WeakPtr<PermissionProvider> permission_provider, 33 base::WeakPtr<PermissionProvider> permission_provider,
34 DeviceRequest request); 34 mojom::UsbDeviceRequest request);
35 35
36 ~DeviceImpl() override; 36 ~DeviceImpl() override;
37 37
38 private: 38 private:
39 DeviceImpl(scoped_refptr<UsbDevice> device, 39 DeviceImpl(scoped_refptr<device::UsbDevice> device,
40 base::WeakPtr<PermissionProvider> permission_provider); 40 base::WeakPtr<PermissionProvider> permission_provider);
41 41
42 // 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
43 // null. 43 // null.
44 void CloseHandle(); 44 void CloseHandle();
45 45
46 // Checks interface permissions for control transfers. 46 // Checks interface permissions for control transfers.
47 bool HasControlTransferPermission(ControlTransferRecipient recipient, 47 bool HasControlTransferPermission(
48 uint16_t index); 48 mojom::UsbControlTransferRecipient recipient,
49 uint16_t index);
49 50
50 // Handles completion of an open request. 51 // Handles completion of an open request.
51 static void OnOpen(base::WeakPtr<DeviceImpl> device, 52 static void OnOpen(base::WeakPtr<DeviceImpl> device,
52 const OpenCallback& callback, 53 const OpenCallback& callback,
53 scoped_refptr<device::UsbDeviceHandle> handle); 54 scoped_refptr<device::UsbDeviceHandle> handle);
54 void OnPermissionGrantedForOpen(const OpenCallback& callback, bool granted); 55 void OnPermissionGrantedForOpen(const OpenCallback& callback, bool granted);
55 56
56 // Device implementation: 57 // Device implementation:
57 void Open(const OpenCallback& callback) override; 58 void Open(const OpenCallback& callback) override;
58 void Close(const CloseCallback& callback) override; 59 void Close(const CloseCallback& callback) override;
59 void SetConfiguration(uint8_t value, 60 void SetConfiguration(uint8_t value,
60 const SetConfigurationCallback& callback) override; 61 const SetConfigurationCallback& callback) override;
61 void ClaimInterface(uint8_t interface_number, 62 void ClaimInterface(uint8_t interface_number,
62 const ClaimInterfaceCallback& callback) override; 63 const ClaimInterfaceCallback& callback) override;
63 void ReleaseInterface(uint8_t interface_number, 64 void ReleaseInterface(uint8_t interface_number,
64 const ReleaseInterfaceCallback& callback) override; 65 const ReleaseInterfaceCallback& callback) override;
65 void SetInterfaceAlternateSetting( 66 void SetInterfaceAlternateSetting(
66 uint8_t interface_number, 67 uint8_t interface_number,
67 uint8_t alternate_setting, 68 uint8_t alternate_setting,
68 const SetInterfaceAlternateSettingCallback& callback) override; 69 const SetInterfaceAlternateSettingCallback& callback) override;
69 void Reset(const ResetCallback& callback) override; 70 void Reset(const ResetCallback& callback) override;
70 void ClearHalt(uint8_t endpoint, const ClearHaltCallback& callback) override; 71 void ClearHalt(uint8_t endpoint, const ClearHaltCallback& callback) override;
71 void ControlTransferIn(ControlTransferParamsPtr params, 72 void ControlTransferIn(mojom::UsbControlTransferParamsPtr params,
72 uint32_t length, 73 uint32_t length,
73 uint32_t timeout, 74 uint32_t timeout,
74 const ControlTransferInCallback& callback) override; 75 const ControlTransferInCallback& callback) override;
75 void ControlTransferOut(ControlTransferParamsPtr params, 76 void ControlTransferOut(mojom::UsbControlTransferParamsPtr params,
76 const std::vector<uint8_t>& data, 77 const std::vector<uint8_t>& data,
77 uint32_t timeout, 78 uint32_t timeout,
78 const ControlTransferOutCallback& callback) override; 79 const ControlTransferOutCallback& callback) override;
79 void GenericTransferIn(uint8_t endpoint_number, 80 void GenericTransferIn(uint8_t endpoint_number,
80 uint32_t length, 81 uint32_t length,
81 uint32_t timeout, 82 uint32_t timeout,
82 const GenericTransferInCallback& callback) override; 83 const GenericTransferInCallback& callback) override;
83 void GenericTransferOut(uint8_t endpoint_number, 84 void GenericTransferOut(uint8_t endpoint_number,
84 const std::vector<uint8_t>& data, 85 const std::vector<uint8_t>& data,
85 uint32_t timeout, 86 uint32_t timeout,
86 const GenericTransferOutCallback& callback) override; 87 const GenericTransferOutCallback& callback) override;
87 void IsochronousTransferIn( 88 void IsochronousTransferIn(
88 uint8_t endpoint_number, 89 uint8_t endpoint_number,
89 const std::vector<uint32_t>& packet_lengths, 90 const std::vector<uint32_t>& packet_lengths,
90 uint32_t timeout, 91 uint32_t timeout,
91 const IsochronousTransferInCallback& callback) override; 92 const IsochronousTransferInCallback& callback) override;
92 void IsochronousTransferOut( 93 void IsochronousTransferOut(
93 uint8_t endpoint_number, 94 uint8_t endpoint_number,
94 const std::vector<uint8_t>& data, 95 const std::vector<uint8_t>& data,
95 const std::vector<uint32_t>& packet_lengths, 96 const std::vector<uint32_t>& packet_lengths,
96 uint32_t timeout, 97 uint32_t timeout,
97 const IsochronousTransferOutCallback& callback) override; 98 const IsochronousTransferOutCallback& callback) override;
98 99
99 // device::UsbDevice::Observer implementation: 100 // device::UsbDevice::Observer implementation:
100 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override; 101 void OnDeviceRemoved(scoped_refptr<device::UsbDevice> device) override;
101 102
102 const scoped_refptr<UsbDevice> device_; 103 const scoped_refptr<device::UsbDevice> device_;
mcasas 2017/04/14 22:00:46 device:: namespace indication shouldn't be needed?
Reilly Grant (use Gerrit) 2017/04/14 22:15:30 I scratched my head over this for a long time and
103 base::WeakPtr<PermissionProvider> permission_provider_; 104 base::WeakPtr<PermissionProvider> permission_provider_;
104 ScopedObserver<device::UsbDevice, device::UsbDevice::Observer> observer_; 105 ScopedObserver<device::UsbDevice, device::UsbDevice::Observer> observer_;
105 106
106 // The device handle. Will be null before the device is opened and after it 107 // The device handle. Will be null before the device is opened and after it
107 // has been closed. 108 // has been closed.
108 scoped_refptr<UsbDeviceHandle> device_handle_; 109 scoped_refptr<UsbDeviceHandle> device_handle_;
109 110
110 mojo::StrongBindingPtr<Device> binding_; 111 mojo::StrongBindingPtr<mojom::UsbDevice> binding_;
111 base::WeakPtrFactory<DeviceImpl> weak_factory_; 112 base::WeakPtrFactory<DeviceImpl> weak_factory_;
112 113
113 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); 114 DISALLOW_COPY_AND_ASSIGN(DeviceImpl);
114 }; 115 };
115 116
116 } // namespace usb 117 } // namespace usb
117 } // namespace device 118 } // namespace device
118 119
119 #endif // DEVICE_USB_MOJO_DEVICE_IMPL_H_ 120 #endif // DEVICE_USB_MOJO_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698