summaryrefslogtreecommitdiff
path: root/chromium/device/usb/usb_device_win.h
blob: dd17683a7579ed05063de5d16c7ce5690cecfb96 (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
// Copyright 2017 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 DEVICE_USB_USB_DEVICE_WIN_H_
#define DEVICE_USB_USB_DEVICE_WIN_H_

#include <string>

#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "device/usb/usb_device.h"

namespace base {
class SequencedTaskRunner;
}

namespace device {

struct UsbDeviceDescriptor;

class UsbDeviceWin : public UsbDevice {
 public:
  // UsbDevice implementation:
  void Open(const OpenCallback& callback) override;

 protected:
  friend class UsbServiceWin;
  friend class UsbDeviceHandleWin;

  // Called by UsbServiceWin only;
  UsbDeviceWin(const std::string& device_path,
               const std::string& hub_path,
               int port_number,
               const std::string& driver_name,
               scoped_refptr<base::SequencedTaskRunner> task_runner);

  ~UsbDeviceWin() override;

  const std::string& device_path() const { return device_path_; }
  int port_number() const { return port_number_; }
  const std::string& driver_name() const { return driver_name_; }

  // Opens the device's parent hub in order to read the device, configuration
  // and string descriptors.
  void ReadDescriptors(const base::Callback<void(bool)>& callback);

 private:
  void OpenOnBlockingThread(const OpenCallback& callback);
  void OnReadDescriptors(const base::Callback<void(bool)>& callback,
                         scoped_refptr<UsbDeviceHandle> device_handle,
                         std::unique_ptr<UsbDeviceDescriptor> descriptor);
  void OnReadStringDescriptors(
      const base::Callback<void(bool)>& callback,
      scoped_refptr<UsbDeviceHandle> device_handle,
      std::unique_ptr<std::map<uint8_t, base::string16>> string_map);

 private:
  base::ThreadChecker thread_checker_;

  const std::string device_path_;
  const std::string hub_path_;
  const int port_number_;
  const std::string driver_name_;

  scoped_refptr<base::SequencedTaskRunner> task_runner_;
  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;

  DISALLOW_COPY_AND_ASSIGN(UsbDeviceWin);
};

}  // namespace device

#endif  // DEVICE_USB_USB_DEVICE_WIN_H_