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 #include "ui/events/devices/device_data_manager.h" | 5 #include "ui/events/devices/device_data_manager.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/events/devices/input_device_event_observer.h" | 10 #include "ui/events/devices/input_device_event_observer.h" |
11 #include "ui/gfx/display.h" | 11 #include "ui/gfx/display.h" |
12 #include "ui/gfx/geometry/point3_f.h" | 12 #include "ui/gfx/geometry/point3_f.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 bool InputDeviceEquals(const ui::InputDevice& a, const ui::InputDevice& b) { | 18 bool InputDeviceEquals(const ui::InputDevice& a, const ui::InputDevice& b) { |
19 return a.id == b.id; | 19 return a.id == b.id; |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 // static | 24 // static |
25 DeviceDataManager* DeviceDataManager::instance_ = NULL; | 25 DeviceDataManager* DeviceDataManager::instance_ = NULL; |
26 | 26 |
27 DeviceDataManager::DeviceDataManager() { | 27 DeviceDataManager::DeviceDataManager() { |
28 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; | |
29 instance_ = this; | |
30 | |
31 base::AtExitManager::RegisterTask( | |
32 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); | |
33 | |
34 ClearTouchDeviceAssociations(); | 28 ClearTouchDeviceAssociations(); |
35 } | 29 } |
36 | 30 |
37 DeviceDataManager::~DeviceDataManager() { | 31 DeviceDataManager::~DeviceDataManager() { |
38 CHECK_EQ(this, instance_); | |
39 instance_ = NULL; | |
40 } | 32 } |
41 | 33 |
42 // static | 34 // static |
43 DeviceDataManager* DeviceDataManager::instance() { return instance_; } | 35 DeviceDataManager* DeviceDataManager::instance() { return instance_; } |
44 | 36 |
| 37 void DeviceDataManager::set_instance(DeviceDataManager* instance) { |
| 38 instance_ = instance; |
| 39 } |
| 40 |
45 // static | 41 // static |
46 void DeviceDataManager::CreateInstance() { | 42 void DeviceDataManager::CreateInstance() { |
47 if (instance()) | 43 if (instance()) |
48 return; | 44 return; |
49 | 45 |
50 new DeviceDataManager(); | 46 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; |
| 47 instance_ = new DeviceDataManager(); |
| 48 |
| 49 base::AtExitManager::RegisterTask(base::Bind(DeleteInstance)); |
| 50 } |
| 51 |
| 52 void DeviceDataManager::DeleteInstance() { |
| 53 if (instance_) { |
| 54 delete instance_; |
| 55 instance_ = NULL; |
| 56 } |
51 } | 57 } |
52 | 58 |
53 // static | 59 // static |
54 DeviceDataManager* DeviceDataManager::GetInstance() { | 60 DeviceDataManager* DeviceDataManager::GetInstance() { |
55 CHECK(instance_) << "DeviceDataManager was not created."; | 61 CHECK(instance_) << "DeviceDataManager was not created."; |
56 return instance_; | 62 return instance_; |
57 } | 63 } |
58 | 64 |
59 // static | 65 // static |
60 bool DeviceDataManager::HasInstance() { | 66 bool DeviceDataManager::HasInstance() { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 125 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
120 const std::vector<TouchscreenDevice>& devices) { | 126 const std::vector<TouchscreenDevice>& devices) { |
121 if (devices.size() == touchscreen_devices_.size() && | 127 if (devices.size() == touchscreen_devices_.size() && |
122 std::equal(devices.begin(), | 128 std::equal(devices.begin(), |
123 devices.end(), | 129 devices.end(), |
124 touchscreen_devices_.begin(), | 130 touchscreen_devices_.begin(), |
125 InputDeviceEquals)) { | 131 InputDeviceEquals)) { |
126 return; | 132 return; |
127 } | 133 } |
128 touchscreen_devices_ = devices; | 134 touchscreen_devices_ = devices; |
129 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 135 NotifyObserversTouchscreenDeviceConfigurationChanged(); |
130 observers_, | |
131 OnTouchscreenDeviceConfigurationChanged()); | |
132 } | 136 } |
133 | 137 |
134 void DeviceDataManager::OnKeyboardDevicesUpdated( | 138 void DeviceDataManager::OnKeyboardDevicesUpdated( |
135 const std::vector<KeyboardDevice>& devices) { | 139 const std::vector<KeyboardDevice>& devices) { |
136 if (devices.size() == keyboard_devices_.size() && | 140 if (devices.size() == keyboard_devices_.size() && |
137 std::equal(devices.begin(), | 141 std::equal(devices.begin(), |
138 devices.end(), | 142 devices.end(), |
139 keyboard_devices_.begin(), | 143 keyboard_devices_.begin(), |
140 InputDeviceEquals)) { | 144 InputDeviceEquals)) { |
141 return; | 145 return; |
142 } | 146 } |
143 keyboard_devices_ = devices; | 147 keyboard_devices_ = devices; |
144 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 148 NotifyObserversKeyboardDeviceConfigurationChanged(); |
145 observers_, | |
146 OnKeyboardDeviceConfigurationChanged()); | |
147 } | 149 } |
148 | 150 |
149 void DeviceDataManager::OnMouseDevicesUpdated( | 151 void DeviceDataManager::OnMouseDevicesUpdated( |
150 const std::vector<InputDevice>& devices) { | 152 const std::vector<InputDevice>& devices) { |
151 if (devices.size() == mouse_devices_.size() && | 153 if (devices.size() == mouse_devices_.size() && |
152 std::equal(devices.begin(), | 154 std::equal(devices.begin(), |
153 devices.end(), | 155 devices.end(), |
154 mouse_devices_.begin(), | 156 mouse_devices_.begin(), |
155 InputDeviceEquals)) { | 157 InputDeviceEquals)) { |
156 return; | 158 return; |
157 } | 159 } |
158 mouse_devices_ = devices; | 160 mouse_devices_ = devices; |
159 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 161 NotifyObserversMouseDeviceConfigurationChanged(); |
160 observers_, | |
161 OnMouseDeviceConfigurationChanged()); | |
162 } | 162 } |
163 | 163 |
164 void DeviceDataManager::OnTouchpadDevicesUpdated( | 164 void DeviceDataManager::OnTouchpadDevicesUpdated( |
165 const std::vector<InputDevice>& devices) { | 165 const std::vector<InputDevice>& devices) { |
166 if (devices.size() == touchpad_devices_.size() && | 166 if (devices.size() == touchpad_devices_.size() && |
167 std::equal(devices.begin(), | 167 std::equal(devices.begin(), |
168 devices.end(), | 168 devices.end(), |
169 touchpad_devices_.begin(), | 169 touchpad_devices_.begin(), |
170 InputDeviceEquals)) { | 170 InputDeviceEquals)) { |
171 return; | 171 return; |
172 } | 172 } |
173 touchpad_devices_ = devices; | 173 touchpad_devices_ = devices; |
174 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 174 NotifyObserversTouchpadDeviceConfigurationChanged(); |
175 observers_, | |
176 OnTouchpadDeviceConfigurationChanged()); | |
177 } | 175 } |
178 | 176 |
179 void DeviceDataManager::OnDeviceListsComplete() { | 177 void DeviceDataManager::OnDeviceListsComplete() { |
180 if (!device_lists_complete_) { | 178 if (!device_lists_complete_) { |
181 device_lists_complete_ = true; | 179 device_lists_complete_ = true; |
182 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | 180 NotifyObserversDeviceListsComplete(); |
183 OnDeviceListsComplete()); | |
184 } | 181 } |
185 } | 182 } |
186 | 183 |
| 184 void DeviceDataManager::NotifyObserversTouchscreenDeviceConfigurationChanged() { |
| 185 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, |
| 186 OnTouchscreenDeviceConfigurationChanged()); |
| 187 } |
| 188 |
| 189 void DeviceDataManager::NotifyObserversKeyboardDeviceConfigurationChanged() { |
| 190 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, |
| 191 OnKeyboardDeviceConfigurationChanged()); |
| 192 } |
| 193 |
| 194 void DeviceDataManager::NotifyObserversMouseDeviceConfigurationChanged() { |
| 195 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, |
| 196 OnMouseDeviceConfigurationChanged()); |
| 197 } |
| 198 |
| 199 void DeviceDataManager::NotifyObserversTouchpadDeviceConfigurationChanged() { |
| 200 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, |
| 201 OnTouchpadDeviceConfigurationChanged()); |
| 202 } |
| 203 |
| 204 void DeviceDataManager::NotifyObserversDeviceListsComplete() { |
| 205 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, |
| 206 OnDeviceListsComplete()); |
| 207 } |
| 208 |
187 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 209 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
188 observers_.AddObserver(observer); | 210 observers_.AddObserver(observer); |
189 } | 211 } |
190 | 212 |
191 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 213 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
192 observers_.RemoveObserver(observer); | 214 observers_.RemoveObserver(observer); |
193 } | 215 } |
194 | 216 |
195 } // namespace ui | 217 } // namespace ui |
OLD | NEW |