| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_HID_HID_SERVICE_LINUX_H_ | 5 #ifndef DEVICE_HID_HID_SERVICE_LINUX_H_ |
| 6 #define DEVICE_HID_HID_SERVICE_LINUX_H_ | 6 #define DEVICE_HID_HID_SERVICE_LINUX_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "device/hid/hid_device_info.h" | 15 #include "device/hid/hid_device_info.h" |
| 16 #include "device/hid/hid_service.h" | 16 #include "device/hid/hid_service.h" |
| 17 | 17 |
| 18 namespace device { | 18 namespace device { |
| 19 | 19 |
| 20 class HidServiceLinux : public HidService { | 20 class HidServiceLinux : public HidService { |
| 21 public: | 21 public: |
| 22 HidServiceLinux(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); | 22 HidServiceLinux( |
| 23 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
| 23 ~HidServiceLinux() override; | 24 ~HidServiceLinux() override; |
| 24 | 25 |
| 25 // HidService: | 26 // HidService: |
| 26 void Shutdown() override; | 27 void Shutdown() override; |
| 27 void Connect(const HidDeviceId& device_id, | 28 void Connect(const HidDeviceId& device_id, |
| 28 const ConnectCallback& callback) override; | 29 const ConnectCallback& callback) override; |
| 29 | 30 |
| 30 private: | 31 private: |
| 31 struct ConnectParams; | 32 struct ConnectParams; |
| 32 class FileThreadHelper; | 33 class FileThreadHelper; |
| 33 | 34 |
| 34 // These functions implement the process of locating, requesting access to and | 35 // These functions implement the process of locating, requesting access to and |
| 35 // opening a device. Because this operation crosses multiple threads these | 36 // opening a device. Because this operation crosses multiple threads these |
| 36 // functions are static and the necessary parameters are passed as a single | 37 // functions are static and the necessary parameters are passed as a single |
| 37 // struct. | 38 // struct. |
| 38 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 39 static void OnPathOpenComplete(std::unique_ptr<ConnectParams> params, | 40 static void OnPathOpenComplete(std::unique_ptr<ConnectParams> params, |
| 40 base::ScopedFD fd); | 41 base::ScopedFD fd); |
| 41 static void OnPathOpenError(const std::string& device_path, | 42 static void OnPathOpenError(const std::string& device_path, |
| 42 const ConnectCallback& callback, | 43 const ConnectCallback& callback, |
| 43 const std::string& error_name, | 44 const std::string& error_name, |
| 44 const std::string& error_message); | 45 const std::string& error_message); |
| 45 #else | 46 #else |
| 46 static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params); | 47 static void OpenOnBlockingThread(std::unique_ptr<ConnectParams> params); |
| 47 #endif | 48 #endif |
| 48 static void FinishOpen(std::unique_ptr<ConnectParams> params); | 49 static void FinishOpen(std::unique_ptr<ConnectParams> params); |
| 49 static void CreateConnection(std::unique_ptr<ConnectParams> params); | 50 static void CreateConnection(std::unique_ptr<ConnectParams> params); |
| 50 | 51 |
| 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 52 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 52 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 53 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 53 | 54 |
| 54 // The helper lives on the FILE thread and holds a weak reference back to the | 55 // The helper lives on the FILE thread and holds a weak reference back to the |
| 55 // service that owns it. | 56 // service that owns it. |
| 56 std::unique_ptr<FileThreadHelper> helper_; | 57 std::unique_ptr<FileThreadHelper> helper_; |
| 57 base::WeakPtrFactory<HidServiceLinux> weak_factory_; | 58 base::WeakPtrFactory<HidServiceLinux> weak_factory_; |
| 58 | 59 |
| 59 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); | 60 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 } // namespace device | 63 } // namespace device |
| 63 | 64 |
| 64 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_ | 65 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_ |
| OLD | NEW |