Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / device / hid / hid_service_win.h
blobad862510183d5aa46b12968081914248bbafc84e
1 // Copyright 2014 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_HID_HID_SERVICE_WIN_H_
6 #define DEVICE_HID_HID_SERVICE_WIN_H_
8 #include <windows.h>
9 #include <hidclass.h>
11 extern "C" {
12 #include <hidsdi.h>
13 #include <hidpi.h>
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/scoped_observer.h"
19 #include "base/win/scoped_handle.h"
20 #include "device/core/device_monitor_win.h"
21 #include "device/hid/hid_device_info.h"
22 #include "device/hid/hid_service.h"
24 namespace base {
25 namespace win {
26 class MessageWindow;
30 namespace device {
32 class HidServiceWin : public HidService, public DeviceMonitorWin::Observer {
33 public:
34 HidServiceWin(scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
35 ~HidServiceWin() override;
37 void Connect(const HidDeviceId& device_id,
38 const ConnectCallback& callback) override;
40 private:
41 static void EnumerateOnFileThread(
42 base::WeakPtr<HidServiceWin> service,
43 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
44 static void CollectInfoFromButtonCaps(PHIDP_PREPARSED_DATA preparsed_data,
45 HIDP_REPORT_TYPE report_type,
46 USHORT button_caps_length,
47 HidCollectionInfo* collection_info);
48 static void CollectInfoFromValueCaps(PHIDP_PREPARSED_DATA preparsed_data,
49 HIDP_REPORT_TYPE report_type,
50 USHORT value_caps_length,
51 HidCollectionInfo* collection_info);
52 static void AddDeviceOnFileThread(
53 base::WeakPtr<HidServiceWin> service,
54 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
55 const std::string& device_path);
57 // DeviceMonitorWin::Observer implementation:
58 void OnDeviceAdded(const GUID& class_guid,
59 const std::string& device_path) override;
60 void OnDeviceRemoved(const GUID& class_guid,
61 const std::string& device_path) override;
63 // Tries to open the device read-write and falls back to read-only.
64 static base::win::ScopedHandle OpenDevice(const std::string& device_path);
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
67 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
68 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_;
69 base::WeakPtrFactory<HidServiceWin> weak_factory_;
71 DISALLOW_COPY_AND_ASSIGN(HidServiceWin);
74 } // namespace device
76 #endif // DEVICE_HID_HID_SERVICE_WIN_H_