summaryrefslogtreecommitdiffstats
path: root/content/renderer/usb/web_usb_device_impl.h
blob: dea2e8f24aff718fd187ae9d7b388a1efb52a766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_USB_WEB_USB_DEVICE_IMPL_H_
#define CONTENT_RENDERER_USB_WEB_USB_DEVICE_IMPL_H_

#include <stddef.h>
#include <stdint.h>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "device/usb/public/interfaces/device.mojom.h"
#include "device/usb/public/interfaces/device_manager.mojom.h"
#include "mojo/shell/public/interfaces/interface_provider.mojom.h"
#include "third_party/WebKit/public/platform/modules/webusb/WebUSBDevice.h"
#include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h"
#include "third_party/WebKit/public/platform/modules/webusb/WebUSBError.h"

namespace mojo {
class Shell;
}

namespace content {

class WebUSBDeviceImpl : public blink::WebUSBDevice {
 public:
  WebUSBDeviceImpl(device::usb::DevicePtr device,
                   const blink::WebUSBDeviceInfo& device_info);
  ~WebUSBDeviceImpl() override;

 private:
  // blink::WebUSBDevice implementation:
  const blink::WebUSBDeviceInfo& info() const override;
  void open(blink::WebUSBDeviceOpenCallbacks* callbacks) override;
  void close(blink::WebUSBDeviceCloseCallbacks* callbacks) override;
  void setConfiguration(
      uint8_t configuration_value,
      blink::WebUSBDeviceSetConfigurationCallbacks* callbacks) override;
  void claimInterface(
      uint8_t interface_number,
      blink::WebUSBDeviceClaimInterfaceCallbacks* callbacks) override;
  void releaseInterface(
      uint8_t interface_number,
      blink::WebUSBDeviceReleaseInterfaceCallbacks* callbacks) override;
  void setInterface(uint8_t interface_number,
                    uint8_t alternate_setting,
                    blink::WebUSBDeviceSetInterfaceAlternateSettingCallbacks*
                        callbacks) override;
  void clearHalt(uint8_t endpoint_number,
                 blink::WebUSBDeviceClearHaltCallbacks* callbacks) override;
  void controlTransfer(
      const blink::WebUSBDevice::ControlTransferParameters& parameters,
      uint8_t* data,
      size_t data_size,
      unsigned int timeout,
      blink::WebUSBDeviceTransferCallbacks* callbacks) override;
  void transfer(blink::WebUSBDevice::TransferDirection direction,
                uint8_t endpoint_number,
                uint8_t* data,
                size_t data_size,
                unsigned int timeout,
                blink::WebUSBDeviceTransferCallbacks* callbacks) override;
  void isochronousTransfer(
      blink::WebUSBDevice::TransferDirection direction,
      uint8_t endpoint_number,
      uint8_t* data,
      size_t data_size,
      blink::WebVector<uint32_t> packet_lengths,
      unsigned int timeout,
      blink::WebUSBDeviceTransferCallbacks* callbacks) override;
  void reset(blink::WebUSBDeviceResetCallbacks* callbacks) override;

  device::usb::DevicePtr device_;
  blink::WebUSBDeviceInfo device_info_;

  base::WeakPtrFactory<WebUSBDeviceImpl> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(WebUSBDeviceImpl);
};

}  // namespace content

#endif  // CONTENT_RENDERER_USB_WEB_USB_DEVICE_IMPL_H_