Chromium Code Reviews| 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 |
| 49 // Returns the TaskRunner for device::InputServiceLinux. Make it static so | |
| 50 // that all InputServiceProxy instances and code that needs access to | |
| 51 // device::InputServiceLinux uses the same TaskRunner. | |
| 52 static scoped_refptr<base::TaskRunner> GetInputServiceTaskRunner(); | |
|
achuithb
2017/06/19 22:34:42
Should we include base/memory/ref_counted.h or is
xiyuan
2017/06/19 23:00:26
You are right that we should include ref_counted.h
| |
| 53 | |
| 50 // Should be called once before any InputServiceProxy instance is created. | 54 // Should be called once before any InputServiceProxy instance is created. |
| 51 static void SetThreadIdForTesting(content::BrowserThread::ID thread_id); | 55 static void SetUseUIThreadForTesting(bool use_ui_thread); |
| 52 | 56 |
| 53 private: | 57 private: |
| 54 static content::BrowserThread::ID thread_identifier_; | |
| 55 | |
| 56 class ServiceObserver; | 58 class ServiceObserver; |
| 57 | 59 |
| 58 void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info); | 60 void OnDeviceAdded(const device::InputServiceLinux::InputDeviceInfo& info); |
| 59 void OnDeviceRemoved(const std::string& id); | 61 void OnDeviceRemoved(const std::string& id); |
| 60 | 62 |
| 61 base::ObserverList<Observer> observers_; | 63 base::ObserverList<Observer> observers_; |
| 62 std::unique_ptr<ServiceObserver> service_observer_; | 64 std::unique_ptr<ServiceObserver> service_observer_; |
| 63 | 65 |
| 64 base::ThreadChecker thread_checker_; | 66 THREAD_CHECKER(thread_checker_); |
| 65 | |
| 66 scoped_refptr<base::TaskRunner> task_runner_; | |
| 67 | 67 |
| 68 base::WeakPtrFactory<InputServiceProxy> weak_factory_; | 68 base::WeakPtrFactory<InputServiceProxy> weak_factory_; |
| 69 | 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(InputServiceProxy); | 70 DISALLOW_COPY_AND_ASSIGN(InputServiceProxy); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 } // namespace chromeos | 73 } // namespace chromeos |
| 74 | 74 |
| 75 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ | 75 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_INPUT_SERVICE_PROXY_H_ |
| OLD | NEW |