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 CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.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 "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "device/hid/input_service_linux.h" | 17 #include "device/hid/input_service_linux.h" |
19 | 18 |
20 namespace chromeos { | 19 namespace chromeos { |
21 | 20 |
22 // Proxy to device::InputServiceLinux. Should be created and used on the UI | 21 // Proxy to device::InputServiceLinux. Should be created and used on the UI |
23 // thread. | 22 // thread. |
24 class InputServiceProxy { | 23 class InputServiceProxy { |
25 public: | 24 public: |
26 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; | 25 typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo; |
27 | 26 |
(...skipping 12 matching lines...) Expand all Loading... | |
40 InputServiceProxy(); | 39 InputServiceProxy(); |
41 ~InputServiceProxy(); | 40 ~InputServiceProxy(); |
42 | 41 |
43 void AddObserver(Observer* observer); | 42 void AddObserver(Observer* observer); |
44 void RemoveObserver(Observer* observer); | 43 void RemoveObserver(Observer* observer); |
45 | 44 |
46 void GetDevices(const GetDevicesCallback& callback); | 45 void GetDevices(const GetDevicesCallback& callback); |
47 void GetDeviceInfo(const std::string& id, | 46 void GetDeviceInfo(const std::string& id, |
48 const GetDeviceInfoCallback& callback); | 47 const GetDeviceInfoCallback& callback); |
49 | 48 |
50 // Should be called once before any InputServiceProxy instance is created. | 49 // Should be called once before any InputServiceProxy instance is created. |
achuithb
2017/06/15 23:04:59
Should we move this comment after the using declar
xiyuan
2017/06/16 19:21:27
will do
| |
51 static void SetThreadIdForTesting(content::BrowserThread::ID thread_id); | 50 using TaskRunnerFactory = |
51 base::Callback<scoped_refptr<base::TaskRunner>(void)>; | |
achuithb
2017/06/15 23:04:59
I'm curious if this is the standard pattern now fo
xiyuan
2017/06/16 19:21:27
Not a standard pattern. I used this because it fit
| |
52 static void SetTaskRunnerFactoryForTesting(TaskRunnerFactory* factory); | |
52 | 53 |
53 private: | 54 private: |
54 static content::BrowserThread::ID thread_identifier_; | |
55 | |
56 class ServiceObserver; | 55 class ServiceObserver; |
57 | 56 |
58 void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info); | 57 void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info); |
59 void OnDeviceRemoved(const std::string& id); | 58 void OnDeviceRemoved(const std::string& id); |
60 | 59 |
61 base::ObserverList<Observer> observers_; | 60 base::ObserverList<Observer> observers_; |
62 std::unique_ptr<ServiceObserver> service_observer_; | 61 std::unique_ptr<ServiceObserver> service_observer_; |
63 | 62 |
64 base::ThreadChecker thread_checker_; | 63 base::ThreadChecker thread_checker_; |
65 | 64 |
66 scoped_refptr<base::TaskRunner> task_runner_; | 65 scoped_refptr<base::TaskRunner> task_runner_; |
67 | 66 |
68 base::WeakPtrFactory<InputServiceProxy> weak_factory_; | 67 base::WeakPtrFactory<InputServiceProxy> weak_factory_; |
69 | 68 |
70 DISALLOW_COPY_AND_ASSIGN(InputServiceProxy); | 69 DISALLOW_COPY_AND_ASSIGN(InputServiceProxy); |
71 }; | 70 }; |
72 | 71 |
73 } // namespace chromeos | 72 } // namespace chromeos |
74 | 73 |
75 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ | 74 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ |
OLD | NEW |