OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/mus/input_devices/input_device_server.h" | 5 #include "components/mus/input_devices/input_device_server.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "mojo/public/cpp/bindings/array.h" | 10 #include "mojo/public/cpp/bindings/array.h" |
11 #include "ui/events/devices/input_device.h" | 11 #include "ui/events/devices/input_device.h" |
12 #include "ui/events/devices/touchscreen_device.h" | 12 #include "ui/events/devices/touchscreen_device.h" |
13 | 13 |
14 namespace mus { | 14 namespace mus { |
15 | 15 |
16 InputDeviceServer::InputDeviceServer() {} | 16 InputDeviceServer::InputDeviceServer() {} |
17 | 17 |
18 InputDeviceServer::~InputDeviceServer() { | 18 InputDeviceServer::~InputDeviceServer() { |
19 if (manager_ && ui::DeviceDataManager::HasInstance()) { | 19 if (manager_ && ui::DeviceDataManager::HasInstance()) { |
20 manager_->RemoveObserver(this); | 20 manager_->RemoveObserver(this); |
21 manager_ = nullptr; | 21 manager_ = nullptr; |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 void InputDeviceServer::RegisterAsObserver() { | 25 void InputDeviceServer::RegisterAsObserver() { |
26 if (!manager_) { | 26 if (!manager_ && ui::DeviceDataManager::HasInstance()) { |
27 manager_ = ui::DeviceDataManager::GetInstance(); | 27 manager_ = ui::DeviceDataManager::GetInstance(); |
28 manager_->AddObserver(this); | 28 manager_->AddObserver(this); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 void InputDeviceServer::RegisterInterface(shell::Connection* connection) { | 32 bool InputDeviceServer::IsRegisteredAsObserver() const { |
| 33 return manager_ != nullptr; |
| 34 } |
| 35 |
| 36 void InputDeviceServer::AddInterface(shell::Connection* connection) { |
33 DCHECK(manager_); | 37 DCHECK(manager_); |
34 connection->AddInterface<mojom::InputDeviceServer>(this); | 38 connection->AddInterface<mojom::InputDeviceServer>(this); |
35 } | 39 } |
36 | 40 |
37 void InputDeviceServer::AddObserver( | 41 void InputDeviceServer::AddObserver( |
38 mojom::InputDeviceObserverMojoPtr observer) { | 42 mojom::InputDeviceObserverMojoPtr observer) { |
39 // We only want to send this message once, so we need to check to make sure | 43 // We only want to send this message once, so we need to check to make sure |
40 // device lists are actually complete before sending it to a new observer. | 44 // device lists are actually complete before sending it to a new observer. |
41 if (manager_->AreDeviceListsComplete()) | 45 if (manager_->AreDeviceListsComplete()) |
42 SendDeviceListsComplete(observer.get()); | 46 SendDeviceListsComplete(observer.get()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(), | 101 manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(), |
98 manager_->GetMouseDevices(), manager_->GetTouchpadDevices()); | 102 manager_->GetMouseDevices(), manager_->GetTouchpadDevices()); |
99 } | 103 } |
100 | 104 |
101 void InputDeviceServer::Create(shell::Connection* connection, | 105 void InputDeviceServer::Create(shell::Connection* connection, |
102 mojom::InputDeviceServerRequest request) { | 106 mojom::InputDeviceServerRequest request) { |
103 bindings_.AddBinding(this, std::move(request)); | 107 bindings_.AddBinding(this, std::move(request)); |
104 } | 108 } |
105 | 109 |
106 } // namespace mus | 110 } // namespace mus |
OLD | NEW |