summaryrefslogtreecommitdiff
path: root/chromium/device/usb/usb_device_linux.h
blob: 6b6888f074af73c9d3a46c4fcc55d6ba8897a2e8 (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
// Copyright 2014 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_IMPL_H_
#define DEVICE_USB_USB_DEVICE_IMPL_H_

#include <stdint.h>

#include <string>
#include <utility>

#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "base/sequence_checker.h"
#include "build/build_config.h"
#include "device/usb/usb_device.h"

namespace base {
class SequencedTaskRunner;
}

namespace device {

struct UsbDeviceDescriptor;

class UsbDeviceLinux : public UsbDevice {
 public:
// UsbDevice implementation:
#if defined(OS_CHROMEOS)
  void CheckUsbAccess(const ResultCallback& callback) override;
#endif  // OS_CHROMEOS
  void Open(const OpenCallback& callback) override;

  const std::string& device_path() const { return device_path_; }

  // These functions are used during enumeration only. The values must not
  // change during the object's lifetime.
  void set_webusb_landing_page(const GURL& url) { webusb_landing_page_ = url; }

 protected:
  friend class UsbServiceLinux;

  // Called by UsbServiceLinux only.
  UsbDeviceLinux(const std::string& device_path,
                 const UsbDeviceDescriptor& descriptor,
                 const std::string& manufacturer_string,
                 const std::string& product_string,
                 const std::string& serial_number,
                 uint8_t active_configuration);

  ~UsbDeviceLinux() override;

 private:
#if defined(OS_CHROMEOS)
  void OnOpenRequestComplete(const OpenCallback& callback, base::ScopedFD fd);
  void OnOpenRequestError(const OpenCallback& callback,
                          const std::string& error_name,
                          const std::string& error_message);
#else
  void OpenOnBlockingThread(
      const OpenCallback& callback,
      scoped_refptr<base::SequencedTaskRunner> task_runner,
      scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
#endif  // defined(OS_CHROMEOS)
  void Opened(base::ScopedFD fd,
              const OpenCallback& callback,
              scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);

  base::SequenceChecker sequence_checker_;

  const std::string device_path_;

  DISALLOW_COPY_AND_ASSIGN(UsbDeviceLinux);
};

}  // namespace device

#endif  // DEVICE_USB_USB_DEVICE_IMPL_H_