blob: 59b6036d8b83e0977c84a238e922bfdaf50e1ae8 [file] [log] [blame]
[email protected]26958d12014-02-27 17:29:101// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]125724f2014-01-31 20:13:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef DEVICE_HID_HID_SERVICE_LINUX_H_
6#define DEVICE_HID_HID_SERVICE_LINUX_H_
7
[email protected]bca53b02014-04-10 15:11:148#include "base/compiler_specific.h"
[email protected]125724f2014-01-31 20:13:239#include "base/macros.h"
[email protected]03b640fd2014-07-26 18:25:3810#include "base/memory/weak_ptr.h"
[email protected]125724f2014-01-31 20:13:2311#include "device/hid/hid_device_info.h"
12#include "device/hid/hid_service.h"
13
14namespace device {
15
16class HidConnection;
17
reillyg56868de2014-12-04 00:26:2718class HidServiceLinux : public HidService {
[email protected]125724f2014-01-31 20:13:2319 public:
rockot1a51b922014-09-05 08:02:4420 HidServiceLinux(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
[email protected]125724f2014-01-31 20:13:2321
dcheng07c34a12014-10-29 18:55:1022 void Connect(const HidDeviceId& device_id,
23 const ConnectCallback& callback) override;
[email protected]125724f2014-01-31 20:13:2324
[email protected]125724f2014-01-31 20:13:2325 private:
reillyg56868de2014-12-04 00:26:2726 struct ConnectParams;
27 class Helper;
28 friend class Helper;
29
dcheng07c34a12014-10-29 18:55:1030 ~HidServiceLinux() override;
[email protected]125724f2014-01-31 20:13:2331
reillyg56868de2014-12-04 00:26:2732 // Constructs this services helper object that lives on the FILE thread.
33 static void StartHelper(
34 base::WeakPtr<HidServiceLinux> weak_ptr,
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
36
37 // These functions implement the process of locating, requesting access to and
38 // opening a device. Because this operation crosses multiple threads these
39 // functions are static and the necessary parameters are passed as a single
40 // struct.
41#if defined(OS_CHROMEOS)
42 static void OnRequestPathAccessComplete(scoped_ptr<ConnectParams> params,
43 bool success);
44#endif // defined(OS_CHROMEOS)
45 static void OpenDevice(scoped_ptr<ConnectParams> params);
46 static void ConnectImpl(scoped_ptr<ConnectParams> params);
[email protected]03b640fd2014-07-26 18:25:3847
reillyg7832a4e2014-10-11 01:52:4748 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
reillyg56868de2014-12-04 00:26:2749 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
[email protected]03b640fd2014-07-26 18:25:3850
reillyg56868de2014-12-04 00:26:2751 // The helper lives on the FILE thread and holds a weak reference back to the
52 // service that owns it.
[email protected]03b640fd2014-07-26 18:25:3853 base::WeakPtrFactory<HidServiceLinux> weak_factory_;
reillyg56868de2014-12-04 00:26:2754 scoped_ptr<Helper> helper_;
[email protected]03b640fd2014-07-26 18:25:3855
[email protected]125724f2014-01-31 20:13:2356 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux);
57};
58
59} // namespace device
60
61#endif // DEVICE_HID_HID_SERVICE_LINUX_H_