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 #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" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 ClearTouchDeviceAssociations(); | 28 ClearTouchDeviceAssociations(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 DeviceDataManager::~DeviceDataManager() { | 31 DeviceDataManager::~DeviceDataManager() { |
| 32 } | 32 } |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 DeviceDataManager* DeviceDataManager::instance() { return instance_; } | 35 DeviceDataManager* DeviceDataManager::instance() { return instance_; } |
| 36 | 36 |
| 37 void DeviceDataManager::set_instance(DeviceDataManager* instance) { | 37 void DeviceDataManager::set_instance(DeviceDataManager* instance) { |
| 38 CHECK(!instance_) << "Can not set multiple instances of DeviceDataManager"; | 38 CHECK(!instance || !instance_) |
|
Alexei Svitkine (slow)
2015/07/07 22:00:59
Nit: I think this should be a DCHECK().
bruthig
2015/07/08 20:29:52
Done.
| |
| 39 << "Can not set multiple instances of DeviceDataManager"; | |
|
sadrul
2015/07/07 22:04:39
Have separate DCHECK()s with the right message ins
bruthig
2015/07/08 20:29:52
Actually the logic is, 'instance' can be null, or
| |
| 39 instance_ = instance; | 40 instance_ = instance; |
| 40 } | 41 } |
| 41 | 42 |
| 42 // static | 43 // static |
| 43 void DeviceDataManager::CreateInstance() { | 44 void DeviceDataManager::CreateInstance() { |
| 44 if (instance()) | 45 if (instance()) |
| 45 return; | 46 return; |
| 46 | 47 |
| 47 set_instance(new DeviceDataManager()); | 48 set_instance(new DeviceDataManager()); |
| 48 | 49 |
| 50 // TODO(bruthig): Replace the DeleteInstance callbacks with explicit calls. | |
| 49 base::AtExitManager::RegisterTask(base::Bind(DeleteInstance)); | 51 base::AtExitManager::RegisterTask(base::Bind(DeleteInstance)); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void DeviceDataManager::DeleteInstance() { | 54 void DeviceDataManager::DeleteInstance() { |
| 53 if (instance_) { | 55 if (instance_) { |
| 54 delete instance_; | 56 delete instance_; |
| 55 instance_ = NULL; | 57 instance_ = NULL; |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 | 60 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 127 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
| 126 const std::vector<TouchscreenDevice>& devices) { | 128 const std::vector<TouchscreenDevice>& devices) { |
| 127 if (devices.size() == touchscreen_devices_.size() && | 129 if (devices.size() == touchscreen_devices_.size() && |
| 128 std::equal(devices.begin(), | 130 std::equal(devices.begin(), |
| 129 devices.end(), | 131 devices.end(), |
| 130 touchscreen_devices_.begin(), | 132 touchscreen_devices_.begin(), |
| 131 InputDeviceEquals)) { | 133 InputDeviceEquals)) { |
| 132 return; | 134 return; |
| 133 } | 135 } |
| 134 touchscreen_devices_ = devices; | 136 touchscreen_devices_ = devices; |
| 135 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 137 NotifyObserversTouchscreenDeviceConfigurationChanged(); |
| 136 observers_, | |
| 137 OnTouchscreenDeviceConfigurationChanged()); | |
| 138 } | 138 } |
| 139 | 139 |
| 140 void DeviceDataManager::OnKeyboardDevicesUpdated( | 140 void DeviceDataManager::OnKeyboardDevicesUpdated( |
| 141 const std::vector<KeyboardDevice>& devices) { | 141 const std::vector<KeyboardDevice>& devices) { |
| 142 if (devices.size() == keyboard_devices_.size() && | 142 if (devices.size() == keyboard_devices_.size() && |
| 143 std::equal(devices.begin(), | 143 std::equal(devices.begin(), |
| 144 devices.end(), | 144 devices.end(), |
| 145 keyboard_devices_.begin(), | 145 keyboard_devices_.begin(), |
| 146 InputDeviceEquals)) { | 146 InputDeviceEquals)) { |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 keyboard_devices_ = devices; | 149 keyboard_devices_ = devices; |
| 150 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 150 NotifyObserversKeyboardDeviceConfigurationChanged(); |
| 151 observers_, | |
| 152 OnKeyboardDeviceConfigurationChanged()); | |
| 153 } | 151 } |
| 154 | 152 |
| 155 void DeviceDataManager::OnMouseDevicesUpdated( | 153 void DeviceDataManager::OnMouseDevicesUpdated( |
| 156 const std::vector<InputDevice>& devices) { | 154 const std::vector<InputDevice>& devices) { |
| 157 if (devices.size() == mouse_devices_.size() && | 155 if (devices.size() == mouse_devices_.size() && |
| 158 std::equal(devices.begin(), | 156 std::equal(devices.begin(), |
| 159 devices.end(), | 157 devices.end(), |
| 160 mouse_devices_.begin(), | 158 mouse_devices_.begin(), |
| 161 InputDeviceEquals)) { | 159 InputDeviceEquals)) { |
| 162 return; | 160 return; |
| 163 } | 161 } |
| 164 mouse_devices_ = devices; | 162 mouse_devices_ = devices; |
| 165 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 163 NotifyObserversMouseDeviceConfigurationChanged(); |
| 166 observers_, | |
| 167 OnMouseDeviceConfigurationChanged()); | |
| 168 } | 164 } |
| 169 | 165 |
| 170 void DeviceDataManager::OnTouchpadDevicesUpdated( | 166 void DeviceDataManager::OnTouchpadDevicesUpdated( |
| 171 const std::vector<InputDevice>& devices) { | 167 const std::vector<InputDevice>& devices) { |
| 172 if (devices.size() == touchpad_devices_.size() && | 168 if (devices.size() == touchpad_devices_.size() && |
| 173 std::equal(devices.begin(), | 169 std::equal(devices.begin(), |
| 174 devices.end(), | 170 devices.end(), |
| 175 touchpad_devices_.begin(), | 171 touchpad_devices_.begin(), |
| 176 InputDeviceEquals)) { | 172 InputDeviceEquals)) { |
| 177 return; | 173 return; |
| 178 } | 174 } |
| 179 touchpad_devices_ = devices; | 175 touchpad_devices_ = devices; |
| 180 FOR_EACH_OBSERVER(InputDeviceEventObserver, | 176 NotifyObserversTouchpadDeviceConfigurationChanged(); |
| 181 observers_, | |
| 182 OnTouchpadDeviceConfigurationChanged()); | |
| 183 } | 177 } |
| 184 | 178 |
| 185 void DeviceDataManager::OnDeviceListsComplete() { | 179 void DeviceDataManager::OnDeviceListsComplete() { |
| 186 if (!device_lists_complete_) { | 180 if (!device_lists_complete_) { |
| 187 device_lists_complete_ = true; | 181 device_lists_complete_ = true; |
| 188 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | 182 NotifyObserversDeviceListsComplete(); |
| 189 OnDeviceListsComplete()); | |
| 190 } | 183 } |
| 191 } | 184 } |
| 192 | 185 |
| 186 void DeviceDataManager::NotifyObserversTouchscreenDeviceConfigurationChanged() { | |
| 187 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | |
| 188 OnTouchscreenDeviceConfigurationChanged()); | |
| 189 } | |
| 190 | |
| 191 void DeviceDataManager::NotifyObserversKeyboardDeviceConfigurationChanged() { | |
| 192 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | |
| 193 OnKeyboardDeviceConfigurationChanged()); | |
| 194 } | |
| 195 | |
| 196 void DeviceDataManager::NotifyObserversMouseDeviceConfigurationChanged() { | |
| 197 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | |
| 198 OnMouseDeviceConfigurationChanged()); | |
| 199 } | |
| 200 | |
| 201 void DeviceDataManager::NotifyObserversTouchpadDeviceConfigurationChanged() { | |
| 202 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | |
| 203 OnTouchpadDeviceConfigurationChanged()); | |
| 204 } | |
| 205 | |
| 206 void DeviceDataManager::NotifyObserversDeviceListsComplete() { | |
| 207 FOR_EACH_OBSERVER(InputDeviceEventObserver, observers_, | |
| 208 OnDeviceListsComplete()); | |
| 209 } | |
| 210 | |
| 193 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 211 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
| 194 observers_.AddObserver(observer); | 212 observers_.AddObserver(observer); |
| 195 } | 213 } |
| 196 | 214 |
| 197 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 215 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
| 198 observers_.RemoveObserver(observer); | 216 observers_.RemoveObserver(observer); |
| 199 } | 217 } |
| 200 | 218 |
| 201 } // namespace ui | 219 } // namespace ui |
| OLD | NEW |