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"; |
sadrul
2015/06/24 19:50:13
This check should be in set_instance above, right?
bruthig
2015/06/24 21:52:59
Done.
| |
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 192 |
187 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 193 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
188 observers_.AddObserver(observer); | 194 observers_.AddObserver(observer); |
189 } | 195 } |
190 | 196 |
191 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 197 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
192 observers_.RemoveObserver(observer); | 198 observers_.RemoveObserver(observer); |
193 } | 199 } |
194 | 200 |
195 } // namespace ui | 201 } // namespace ui |
OLD | NEW |