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_
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"
32 class HidServiceWin
: public HidService
, public DeviceMonitorWin::Observer
{
34 HidServiceWin(scoped_refptr
<base::SingleThreadTaskRunner
> file_task_runner
);
36 virtual void Connect(const HidDeviceId
& device_id
,
37 const ConnectCallback
& callback
) override
;
40 virtual ~HidServiceWin();
42 static void EnumerateOnFileThread(
43 base::WeakPtr
<HidServiceWin
> service
,
44 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
);
45 static void CollectInfoFromButtonCaps(PHIDP_PREPARSED_DATA preparsed_data
,
46 HIDP_REPORT_TYPE report_type
,
47 USHORT button_caps_length
,
48 HidCollectionInfo
* collection_info
);
49 static void CollectInfoFromValueCaps(PHIDP_PREPARSED_DATA preparsed_data
,
50 HIDP_REPORT_TYPE report_type
,
51 USHORT value_caps_length
,
52 HidCollectionInfo
* collection_info
);
53 static void AddDeviceOnFileThread(
54 base::WeakPtr
<HidServiceWin
> service
,
55 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner
,
56 const std::string
& device_path
);
58 // DeviceMonitorWin::Observer implementation:
59 void OnDeviceAdded(const GUID
& class_guid
,
60 const std::string
& device_path
) override
;
61 void OnDeviceRemoved(const GUID
& class_guid
,
62 const std::string
& device_path
) override
;
64 // Tries to open the device read-write and falls back to read-only.
65 static base::win::ScopedHandle
OpenDevice(const std::string
& device_path
);
67 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
68 scoped_refptr
<base::SingleThreadTaskRunner
> file_task_runner_
;
69 ScopedObserver
<DeviceMonitorWin
, DeviceMonitorWin::Observer
> device_observer_
;
70 base::WeakPtrFactory
<HidServiceWin
> weak_factory_
;
72 DISALLOW_COPY_AND_ASSIGN(HidServiceWin
);
77 #endif // DEVICE_HID_HID_SERVICE_WIN_H_