cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / device / devices_app / usb / device_impl.h
blobc8278355271ee7b35d0b9bf15a2212a6d553953a
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_USB_DEVICE_IMPL_H_
6 #define DEVICE_USB_DEVICE_IMPL_H_
8 #include "base/callback_forward.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "device/devices_app/usb/public/interfaces/device.mojom.h"
13 #include "device/usb/usb_device_handle.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.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"
18 namespace net {
19 class IOBuffer;
22 namespace device {
23 namespace usb {
25 // Implementation of the public Device interface. Instances of this class are
26 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe
27 // lifetime.
28 class DeviceImpl : public Device {
29 public:
30 DeviceImpl(scoped_refptr<UsbDeviceHandle> device_handle,
31 mojo::InterfaceRequest<Device> request);
32 ~DeviceImpl() override;
34 private:
35 using MojoTransferInCallback =
36 mojo::Callback<void(TransferStatus, mojo::Array<uint8_t>)>;
38 using MojoTransferOutCallback = mojo::Callback<void(TransferStatus)>;
40 // Closes the device if it's open. This will always set |handle_| to null.
41 void CloseHandle();
43 // Handles a UsbDeviceHandle::ClaimInterface response.
44 void OnClaimInterface(uint8_t interface_number,
45 const ClaimInterfaceCallback& callback,
46 bool result);
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);
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);
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);
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);
75 // Device implementation:
76 void Close(const CloseCallback& callback) override;
77 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override;
78 void SetConfiguration(uint8_t value,
79 const SetConfigurationCallback& callback) override;
80 void ClaimInterface(uint8_t interface_number,
81 const ClaimInterfaceCallback& callback) override;
82 void ReleaseInterface(uint8_t interface_number,
83 const ReleaseInterfaceCallback& callback) override;
84 void SetInterfaceAlternateSetting(
85 uint8_t interface_number,
86 uint8_t alternate_setting,
87 const SetInterfaceAlternateSettingCallback& callback) override;
88 void Reset(const ResetCallback& callback) override;
89 void ClearHalt(uint8_t endpoint, const ClearHaltCallback& callback) override;
90 void ControlTransferIn(ControlTransferParamsPtr params,
91 uint32_t length,
92 uint32_t timeout,
93 const ControlTransferInCallback& callback) override;
94 void ControlTransferOut(ControlTransferParamsPtr params,
95 mojo::Array<uint8_t> data,
96 uint32_t timeout,
97 const ControlTransferOutCallback& callback) override;
98 void GenericTransferIn(uint8_t endpoint_number,
99 uint32_t length,
100 uint32_t timeout,
101 const GenericTransferInCallback& callback) override;
102 void GenericTransferOut(uint8_t endpoint_number,
103 mojo::Array<uint8_t> data,
104 uint32_t timeout,
105 const GenericTransferOutCallback& callback) override;
106 void IsochronousTransferIn(
107 uint8_t endpoint_number,
108 uint32_t num_packets,
109 uint32_t packet_length,
110 uint32_t timeout,
111 const IsochronousTransferInCallback& callback) override;
112 void IsochronousTransferOut(
113 uint8_t endpoint_number,
114 mojo::Array<mojo::Array<uint8_t>> packets,
115 uint32_t timeout,
116 const IsochronousTransferOutCallback& callback) override;
118 mojo::StrongBinding<Device> binding_;
120 // The opened device handle. May be null if the device has been closed.
121 scoped_refptr<UsbDeviceHandle> device_handle_;
123 base::WeakPtrFactory<DeviceImpl> weak_factory_;
125 DISALLOW_COPY_AND_ASSIGN(DeviceImpl);
128 } // namespace usb
129 } // namespace device
131 #endif // DEVICE_USB_DEVICE_IMPL_H_