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_INPUT_SERVICE_LINUX_H_ | 5 #ifndef DEVICE_HID_INPUT_SERVICE_LINUX_H_ |
6 #define DEVICE_HID_INPUT_SERVICE_LINUX_H_ | 6 #define DEVICE_HID_INPUT_SERVICE_LINUX_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 class Observer { | 49 class Observer { |
50 public: | 50 public: |
51 virtual ~Observer() {} | 51 virtual ~Observer() {} |
52 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0; | 52 virtual void OnInputDeviceAdded(const InputDeviceInfo& info) = 0; |
53 virtual void OnInputDeviceRemoved(const std::string& id) = 0; | 53 virtual void OnInputDeviceRemoved(const std::string& id) = 0; |
54 }; | 54 }; |
55 | 55 |
56 InputServiceLinux(); | 56 InputServiceLinux(); |
57 virtual ~InputServiceLinux(); | 57 virtual ~InputServiceLinux(); |
58 | 58 |
| 59 // Returns the InputServiceLinux instance for the current process. Creates one |
| 60 // if none has been set. |
59 static InputServiceLinux* GetInstance(); | 61 static InputServiceLinux* GetInstance(); |
| 62 |
| 63 // Returns true if an InputServiceLinux instance has been set for the current |
| 64 // process. An instance is set on the first call to GetInstance() or |
| 65 // SetForTesting(). |
60 static bool HasInstance(); | 66 static bool HasInstance(); |
61 static void SetForTesting(InputServiceLinux* service); | 67 |
| 68 // Sets the InputServiceLinux instance for the current process. Cannot be |
| 69 // called if GetInstance() or SetForTesting() has already been called in the |
| 70 // current process. |service| will never be deleted. |
| 71 static void SetForTesting(std::unique_ptr<InputServiceLinux> service); |
62 | 72 |
63 void AddObserver(Observer* observer); | 73 void AddObserver(Observer* observer); |
64 void RemoveObserver(Observer* observer); | 74 void RemoveObserver(Observer* observer); |
65 | 75 |
66 // Returns list of all currently connected input/hid devices. | 76 // Returns list of all currently connected input/hid devices. |
67 virtual void GetDevices(std::vector<InputDeviceInfo>* devices); | 77 virtual void GetDevices(std::vector<InputDeviceInfo>* devices); |
68 | 78 |
69 // Returns an info about input device identified by |id|. When there're | 79 // Returns an info about input device identified by |id|. When there're |
70 // no input or hid device with such id, returns false and doesn't | 80 // no input or hid device with such id, returns false and doesn't |
71 // modify |info|. | 81 // modify |info|. |
72 bool GetDeviceInfo(const std::string& id, InputDeviceInfo* info) const; | 82 bool GetDeviceInfo(const std::string& id, InputDeviceInfo* info) const; |
73 | 83 |
74 protected: | 84 protected: |
75 void AddDevice(const InputDeviceInfo& info); | 85 void AddDevice(const InputDeviceInfo& info); |
76 void RemoveDevice(const std::string& id); | 86 void RemoveDevice(const std::string& id); |
77 | 87 |
78 bool CalledOnValidThread() const; | 88 bool CalledOnValidThread() const; |
79 | 89 |
80 DeviceMap devices_; | 90 DeviceMap devices_; |
81 base::ObserverList<Observer> observers_; | 91 base::ObserverList<Observer> observers_; |
82 | 92 |
83 private: | 93 private: |
84 friend std::default_delete<InputServiceLinux>; | |
85 | |
86 base::ThreadChecker thread_checker_; | 94 base::ThreadChecker thread_checker_; |
87 | 95 |
88 DISALLOW_COPY_AND_ASSIGN(InputServiceLinux); | 96 DISALLOW_COPY_AND_ASSIGN(InputServiceLinux); |
89 }; | 97 }; |
90 | 98 |
91 } // namespace device | 99 } // namespace device |
92 | 100 |
93 #endif // DEVICE_HID_INPUT_SERVICE_LINUX_H_ | 101 #endif // DEVICE_HID_INPUT_SERVICE_LINUX_H_ |
OLD | NEW |