diff options
Diffstat (limited to 'ui/events/devices')
-rw-r--r-- | ui/events/devices/device_data_manager.cc | 24 | ||||
-rw-r--r-- | ui/events/devices/device_data_manager.h | 3 | ||||
-rw-r--r-- | ui/events/devices/x11/device_data_manager_x11.cc | 8 |
3 files changed, 25 insertions, 10 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 diff --git a/ui/events/devices/device_data_manager.h b/ui/events/devices/device_data_manager.h index d8ede81..2975b9fe 100644 --- a/ui/events/devices/device_data_manager.h +++ b/ui/events/devices/device_data_manager.h @@ -30,6 +30,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager ~DeviceDataManager() override; static void CreateInstance(); + static void DeleteInstance(); static DeviceDataManager* GetInstance(); static bool HasInstance(); @@ -63,6 +64,8 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager static DeviceDataManager* instance(); + static void set_instance(DeviceDataManager* instance); + // DeviceHotplugEventObserver: void OnTouchscreenDevicesUpdated( const std::vector<TouchscreenDevice>& devices) override; diff --git a/ui/events/devices/x11/device_data_manager_x11.cc b/ui/events/devices/x11/device_data_manager_x11.cc index 230b7fa..0f62b33 100644 --- a/ui/events/devices/x11/device_data_manager_x11.cc +++ b/ui/events/devices/x11/device_data_manager_x11.cc @@ -10,6 +10,8 @@ #include <utility> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/logging.h" #include "base/memory/singleton.h" #include "base/sys_info.h" @@ -130,7 +132,11 @@ void DeviceDataManagerX11::CreateInstance() { if (instance()) return; - new DeviceDataManagerX11(); + DeviceDataManagerX11* device_data_manager = new DeviceDataManagerX11(); + base::AtExitManager::RegisterTask( + base::Bind(&base::DeletePointer<DeviceDataManager>, device_data_manager)); + + set_instance(device_data_manager); } // static |