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