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_LINUX_H_
6 #define DEVICE_HID_HID_SERVICE_LINUX_H_
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h"
11 #include "device/hid/hid_device_info.h"
12 #include "device/hid/hid_service.h"
22 class HidServiceLinux
: public HidService
{
24 HidServiceLinux(scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
);
25 ~HidServiceLinux() override
;
27 void Connect(const HidDeviceId
& device_id
,
28 const ConnectCallback
& callback
) override
;
32 class FileThreadHelper
;
34 // These functions implement the process of locating, requesting access to and
35 // opening a device. Because this operation crosses multiple threads these
36 // functions are static and the necessary parameters are passed as a single
38 #if defined(OS_CHROMEOS)
39 static void OnPathOpened(scoped_ptr
<ConnectParams
> params
,
40 dbus::FileDescriptor fd
);
41 static void ValidateFdOnBlockingThread(scoped_ptr
<ConnectParams
> params
,
42 dbus::FileDescriptor fd
);
44 static void OpenOnBlockingThread(scoped_ptr
<ConnectParams
> params
);
46 static void FinishOpen(scoped_ptr
<ConnectParams
> params
);
47 static void CreateConnection(scoped_ptr
<ConnectParams
> params
);
49 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
50 scoped_refptr
<base::SingleThreadTaskRunner
> file_task_runner_
;
52 // The helper lives on the FILE thread and holds a weak reference back to the
53 // service that owns it.
54 FileThreadHelper
* helper_
;
55 base::WeakPtrFactory
<HidServiceLinux
> weak_factory_
;
57 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux
);
62 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_