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

Side by Side Diff: components/input_device_service/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: Clean up/move files. Created 4 years, 7 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/input_device_service/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/device_data_manager.h"
12
13 namespace input_device {
14
15 using ui::DeviceDataManager;
16
17 namespace {
18
19 template <class T>
20 std::vector<ui::InputDevice> ToInputDevices(const std::vector<T>& input) {
21 std::vector<ui::InputDevice> devices;
22 for (const T& device : input) {
23 devices.push_back(ui::InputDevice(device));
24 }
25 return devices;
26 }
27
28 std::vector<ui::InputDevice> GetKeyboardList() {
29 // TODO(kylechar): Change DDM to hold ui::InputDevice instead.
30 return ToInputDevices(DeviceDataManager::GetInstance()->keyboard_devices());
31 }
32
33 std::vector<ui::InputDevice> GetTouchscreenList() {
34 // TODO(kylechar): Change DDM to hold ui::InputDevice instead.
35 return ToInputDevices(
36 DeviceDataManager::GetInstance()->touchscreen_devices());
37 }
38
39 const std::vector<ui::InputDevice>& GetMouseList() {
40 return DeviceDataManager::GetInstance()->mouse_devices();
41 }
42
43 const std::vector<ui::InputDevice>& GetTouchpadList() {
44 return DeviceDataManager::GetInstance()->touchpad_devices();
45 }
46
47 } // namespace
48
49 InputDeviceServer::InputDeviceServer() {}
50
51 InputDeviceServer::~InputDeviceServer() {
52 if (is_observing_ && DeviceDataManager::HasInstance()) {
53 DeviceDataManager::GetInstance()->RemoveObserver(this);
54 }
55 is_observing_ = false;
56 }
57
58 void InputDeviceServer::RegisterAsObserver() {
59 if (!is_observing_) {
60 DeviceDataManager::GetInstance()->AddObserver(this);
sadrul 2016/05/25 20:40:08 What creates this DDM instance?
kylechar 2016/05/27 19:52:22 It's created as part of Ozone initialization or as
61 is_observing_ = true;
62 }
63 }
64
65 void InputDeviceServer::RegisterInterface(shell::Connection* connection) {
66 DCHECK(is_observing_);
67 connection->AddInterface<mojom::InputDeviceService>(this);
68 }
69
70 void InputDeviceServer::Create(shell::Connection* connection,
71 mojom::InputDeviceServiceRequest request) {
72 bindings_.AddBinding(this, std::move(request));
73 }
74
75 void InputDeviceServer::AddObserver(mojom::InputDeviceObserverPtr observer) {
76 observers_.AddPtr(std::move(observer));
77 }
78
79 void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
80 auto devices = GetKeyboardList();
81 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserver* observer) {
82 observer->OnKeyboardDeviceConfigurationChanged(
83 mojo::Array<ui::InputDevice>::From(devices));
84 });
85 }
86
87 void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
88 auto devices = GetTouchscreenList();
89 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserver* observer) {
90 observer->OnTouchscreenDeviceConfigurationChanged(
91 mojo::Array<ui::InputDevice>::From(devices));
92 });
93 }
94
95 void InputDeviceServer::OnMouseDeviceConfigurationChanged() {
96 auto& devices = GetMouseList();
97 LOG(ERROR) << "InputDeviceServer::OnMouseDeviceConfigurationChanged "
98 << devices.size();
99 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserver* observer) {
100 observer->OnMouseDeviceConfigurationChanged(
101 mojo::Array<ui::InputDevice>::From(devices));
102 });
103 }
104
105 void InputDeviceServer::OnTouchpadDeviceConfigurationChanged() {
106 auto& devices = GetTouchpadList();
107 observers_.ForAllPtrs([&devices](mojom::InputDeviceObserver* observer) {
108 observer->OnTouchpadDeviceConfigurationChanged(
109 mojo::Array<ui::InputDevice>::From(devices));
110 });
111 }
112
113 void InputDeviceServer::GetKeyboardDevices(
114 const GetKeyboardDevicesCallback& callback) {
115 callback.Run(mojo::Array<ui::InputDevice>::From(GetKeyboardList()));
116 }
117
118 void InputDeviceServer::GetTouchscreenDevices(
119 const GetTouchscreenDevicesCallback& callback) {
120 callback.Run(mojo::Array<ui::InputDevice>::From(GetTouchscreenList()));
121 }
122
123 void InputDeviceServer::GetMouseDevices(
124 const GetMouseDevicesCallback& callback) {
125 callback.Run(mojo::Array<ui::InputDevice>::From(GetMouseList()));
126 }
127
128 void InputDeviceServer::GetTouchpadDevices(
129 const GetTouchpadDevicesCallback& callback) {
130 callback.Run(mojo::Array<ui::InputDevice>::From(GetTouchpadList()));
131 }
132
133 } // namespace input_device
OLDNEW
« no previous file with comments | « components/input_device_service/input_device_server.h ('k') | components/input_device_service/input_device_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698