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

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: Rebase/update. 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 input_device {
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::Create(shell::Connection* connection,
38 mojom::InputDeviceServerRequest request) {
39 bindings_.AddBinding(this, std::move(request));
40 }
41
42 void InputDeviceServer::AddObserver(
43 mojom::InputDeviceObserverMojoPtr observer) {
44 SendInputDeviceState(observer.get());
45 observers_.AddPtr(std::move(observer));
46 }
47
48 void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
49 auto& devices = manager_->GetKeyboardDevices();
50 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
51 observer->OnKeyboardDeviceConfigurationChanged(
52 mojo::Array<ui::InputDevice>::From(devices));
53 });
54 }
55
56 void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
57 auto& devices = manager_->GetTouchscreenDevices();
58 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
59 observer->OnTouchscreenDeviceConfigurationChanged(
60 mojo::Array<ui::TouchscreenDevice>::From(devices));
61 });
62 }
63
64 void InputDeviceServer::OnMouseDeviceConfigurationChanged() {
65 auto& devices = manager_->GetMouseDevices();
66 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
67 observer->OnMouseDeviceConfigurationChanged(
68 mojo::Array<ui::InputDevice>::From(devices));
69 });
70 }
71
72 void InputDeviceServer::OnTouchpadDeviceConfigurationChanged() {
73 auto& devices = manager_->GetTouchpadDevices();
74 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
75 observer->OnTouchpadDeviceConfigurationChanged(
76 mojo::Array<ui::InputDevice>::From(devices));
77 });
78 }
79
80 void InputDeviceServer::OnDeviceListsComplete() {
81 observers_.ForAllPtrs([](mojom::InputDeviceObserverMojo* observer) {
82 observer->OnDeviceListsComplete();
83 });
84 }
85
86 void InputDeviceServer::SendInputDeviceState(
87 mojom::InputDeviceObserverMojo* observer) {
88 auto& keyboard_devices = manager_->GetKeyboardDevices();
89 if (!keyboard_devices.empty()) {
90 observer->OnKeyboardDeviceConfigurationChanged(
91 mojo::Array<ui::InputDevice>::From(keyboard_devices));
92 }
93
94 auto& touchscreen_devices = manager_->GetTouchscreenDevices();
95 if (!touchscreen_devices.empty()) {
96 observer->OnTouchscreenDeviceConfigurationChanged(
97 mojo::Array<ui::TouchscreenDevice>::From(touchscreen_devices));
98 }
99
100 auto& mouse_devices = manager_->GetMouseDevices();
101 if (!mouse_devices.empty()) {
102 observer->OnMouseDeviceConfigurationChanged(
103 mojo::Array<ui::InputDevice>::From(mouse_devices));
104 }
105
106 auto& touchpad_devices = manager_->GetTouchpadDevices();
107 if (!touchpad_devices.empty()) {
108 observer->OnTouchpadDeviceConfigurationChanged(
109 mojo::Array<ui::InputDevice>::From(touchpad_devices));
110 }
111
112 // We only want to send this message once, so we need to check to make sure
113 // device lists are actually complete before sending it to a new observer.
114 if (manager_->AreDeviceListsComplete()) {
115 observer->OnDeviceListsComplete();
116 }
117 }
118
119 } // namespace input_device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698