Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: components/mus/input_devices/input_device_server.cc

Issue 1992443002: Add Mojo IPC based input-device service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_ddm
Patch Set: Change namespace. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/mus/input_devices/input_device_server.h"
6
7 #include <utility>
8 #include <vector>
9
10 #include "mojo/public/cpp/bindings/array.h"
11 #include "ui/events/devices/input_device.h"
12 #include "ui/events/devices/touchscreen_device.h"
13
14 namespace mus {
15
16 InputDeviceServer::InputDeviceServer() {}
17
18 InputDeviceServer::~InputDeviceServer() {
19 if (manager_ && ui::DeviceDataManager::HasInstance()) {
20 manager_->RemoveObserver(this);
21 manager_ = nullptr;
22 }
23 }
24
25 void InputDeviceServer::RegisterAsObserver() {
26 if (!manager_) {
27 manager_ = ui::DeviceDataManager::GetInstance();
28 manager_->AddObserver(this);
29 }
30 }
31
32 void InputDeviceServer::RegisterInterface(shell::Connection* connection) {
33 DCHECK(manager_);
34 connection->AddInterface<mojom::InputDeviceServer>(this);
35 }
36
37 void InputDeviceServer::AddObserver(
38 mojom::InputDeviceObserverMojoPtr observer) {
39 // 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.
41 if (manager_->AreDeviceListsComplete())
42 SendDeviceListsComplete(observer.get());
43 observers_.AddPtr(std::move(observer));
44 }
45
46 void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
47 if (!manager_->AreDeviceListsComplete())
48 return;
49
50 auto& devices = manager_->GetKeyboardDevices();
51 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
52 observer->OnKeyboardDeviceConfigurationChanged(devices);
53 });
54 }
55
56 void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
57 if (!manager_->AreDeviceListsComplete())
58 return;
59
60 auto& devices = manager_->GetTouchscreenDevices();
61 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
62 observer->OnTouchscreenDeviceConfigurationChanged(devices);
63 });
64 }
65
66 void InputDeviceServer::OnMouseDeviceConfigurationChanged() {
67 if (!manager_->AreDeviceListsComplete())
68 return;
69
70 auto& devices = manager_->GetMouseDevices();
71 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
72 observer->OnMouseDeviceConfigurationChanged(devices);
73 });
74 }
75
76 void InputDeviceServer::OnTouchpadDeviceConfigurationChanged() {
77 if (!manager_->AreDeviceListsComplete())
78 return;
79
80 auto& devices = manager_->GetTouchpadDevices();
81 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
82 observer->OnTouchpadDeviceConfigurationChanged(devices);
83 });
84 }
85
86 void InputDeviceServer::OnDeviceListsComplete() {
87 observers_.ForAllPtrs([this](mojom::InputDeviceObserverMojo* observer) {
88 SendDeviceListsComplete(observer);
89 });
90 }
91
92 void InputDeviceServer::SendDeviceListsComplete(
93 mojom::InputDeviceObserverMojo* observer) {
94 DCHECK(manager_->AreDeviceListsComplete());
95
96 observer->OnDeviceListsComplete(
97 manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(),
98 manager_->GetMouseDevices(), manager_->GetTouchpadDevices());
99 }
100
101 void InputDeviceServer::Create(shell::Connection* connection,
102 mojom::InputDeviceServerRequest request) {
103 bindings_.AddBinding(this, std::move(request));
104 }
105
106 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/input_devices/input_device_server.h ('k') | components/mus/public/cpp/input_devices/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698