diff options
author | bruthig <bruthig@chromium.org> | 2015-06-29 07:52:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-29 14:53:03 +0000 |
commit | 51ba4dd85063d575866a5003c2502c7fe88a10f8 (patch) | |
tree | ce0b9afa7eea02b101dde1462faa48549a50c586 /ui/events/devices/device_data_manager.cc | |
parent | c53da80809bb2eaa991abd6bf90790012662c3aa (diff) | |
download | chromium_src-51ba4dd85063d575866a5003c2502c7fe88a10f8.zip chromium_src-51ba4dd85063d575866a5003c2502c7fe88a10f8.tar.gz chromium_src-51ba4dd85063d575866a5003c2502c7fe88a10f8.tar.bz2 |
Changed DeviceDataManager to be able to create multiple instances for the purposes of test.
The DeviceDataManager was implemented as a singleton and it was impossible
to create two different instances in tests. This change makes it possible
for future test framework to create multiple instances.
BUG=499476
Review URL: https://codereview.chromium.org/1202383002
Cr-Commit-Position: refs/heads/master@{#336558}
Diffstat (limited to 'ui/events/devices/device_data_manager.cc')
-rw-r--r-- | ui/events/devices/device_data_manager.cc | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/ui/events/devices/device_data_manager.cc b/ui/events/devices/device_data_manager.cc index 44ca1fa..e725736 100644 --- a/ui/events/devices/device_data_manager.cc +++ b/ui/events/devices/device_data_manager.cc @@ -25,29 +25,35 @@ bool InputDeviceEquals(const ui::InputDevice& a, const ui::InputDevice& b) { DeviceDataManager* DeviceDataManager::instance_ = NULL; DeviceDataManager::DeviceDataManager() { - CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; - instance_ = this; - - base::AtExitManager::RegisterTask( - base::Bind(&base::DeletePointer<DeviceDataManager>, this)); - ClearTouchDeviceAssociations(); } DeviceDataManager::~DeviceDataManager() { - CHECK_EQ(this, instance_); - instance_ = NULL; } // static DeviceDataManager* DeviceDataManager::instance() { return instance_; } +void DeviceDataManager::set_instance(DeviceDataManager* instance) { + CHECK(!instance_) << "Can not set multiple instances of DeviceDataManager"; + instance_ = instance; +} + // static void DeviceDataManager::CreateInstance() { if (instance()) return; - new DeviceDataManager(); + set_instance(new DeviceDataManager()); + + base::AtExitManager::RegisterTask(base::Bind(DeleteInstance)); +} + +void DeviceDataManager::DeleteInstance() { + if (instance_) { + delete instance_; + instance_ = NULL; + } } // static |