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

Side by Side Diff: components/mus/public/cpp/input_devices/lib/input_device_client.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/move. 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.
Ben Goodger (Google) 2016/06/02 19:35:18 we're going to get rid of lib subdirs... so just p
kylechar 2016/06/03 14:35:57 Done. Will upload a new patch after rebasing later
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/public/cpp/input_devices/input_device_client.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h"
12
13 namespace input_device {
14
15 namespace {
16
17 // TODO(kylechar): Debug, remove eventually.
18 template <class DeviceType>
19 void PrintDevices(std::string title, const DeviceType& devices) {
20 std::vector<std::string> device_strings;
21 device_strings.push_back(base::StringPrintf("%s devices.size()=%zu",
22 title.c_str(), devices.size()));
23 for (const auto& device : devices) {
24 device_strings.push_back(device.ToString());
25 }
26 LOG(ERROR) << base::JoinString(device_strings, ", ");
27 }
28
29 } // namespace
30
31 InputDeviceClient::InputDeviceClient() : binding_(this) {
32 InputDeviceManager::SetInstance(this);
33 }
34
35 InputDeviceClient::~InputDeviceClient() {
36 InputDeviceManager::ClearInstance();
37 }
38
39 void InputDeviceClient::Connect(shell::Connector* connector) {
Ben Goodger (Google) 2016/06/02 19:35:18 rather than passing in a connector, can you requir
kylechar 2016/06/03 14:35:57 Yeah, that's absolutely possible. I'm just getting
40 mojom::InputDeviceServerPtr service;
41 connector->ConnectToInterface("mojo:mus", &service);
42
43 // Add this class as an observer via Mojo IPC.
44 service->AddObserver(binding_.CreateInterfacePtrAndBind());
45 binding_.set_connection_error_handler([]() {
46 LOG(ERROR) << "InputDeviceClient failed to bind observer pipe.";
47 });
48 }
49
50 void InputDeviceClient::OnKeyboardDeviceConfigurationChanged(
51 mojo::Array<ui::InputDevice> devices) {
52 keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>();
53 PrintDevices("UpdateKeyboardDevices", keyboard_devices_);
54 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
55 OnKeyboardDeviceConfigurationChanged());
56 }
57
58 void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged(
59 mojo::Array<ui::TouchscreenDevice> devices) {
60 touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>();
61 PrintDevices("UpdateTouchscreenDevices", touchscreen_devices_);
62 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
63 OnTouchscreenDeviceConfigurationChanged());
64 }
65
66 void InputDeviceClient::OnMouseDeviceConfigurationChanged(
67 mojo::Array<ui::InputDevice> devices) {
68 mouse_devices_ = devices.To<std::vector<ui::InputDevice>>();
69 PrintDevices("UpdateMouseDevices", mouse_devices_);
70 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
71 OnMouseDeviceConfigurationChanged());
72 }
73
74 void InputDeviceClient::OnTouchpadDeviceConfigurationChanged(
75 mojo::Array<ui::InputDevice> devices) {
76 touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>();
77 PrintDevices("UpdateTouchpadDevices", touchpad_devices_);
78 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
79 OnTouchpadDeviceConfigurationChanged());
80 }
81
82 void InputDeviceClient::OnDeviceListsComplete() {
83 if (!device_lists_complete_) {
84 LOG(ERROR) << "InputDeviceClient::OnDeviceListsComplete";
85 device_lists_complete_ = true;
86 FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
87 OnDeviceListsComplete());
88 }
89 }
90
91 void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) {
92 observers_.AddObserver(observer);
93 }
94
95 void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) {
96 observers_.RemoveObserver(observer);
97 }
98
99 const std::vector<ui::InputDevice>& InputDeviceClient::GetKeyboardDevices()
100 const {
101 return keyboard_devices_;
102 }
103
104 const std::vector<ui::TouchscreenDevice>&
105 InputDeviceClient::GetTouchscreenDevices() const {
106 return touchscreen_devices_;
107 }
108
109 const std::vector<ui::InputDevice>& InputDeviceClient::GetMouseDevices() const {
110 return mouse_devices_;
111 }
112
113 const std::vector<ui::InputDevice>& InputDeviceClient::GetTouchpadDevices()
114 const {
115 return touchpad_devices_;
116 }
117
118 bool InputDeviceClient::AreDeviceListsComplete() const {
119 return device_lists_complete_;
120 }
121
122 bool InputDeviceClient::AreTouchscreensEnabled() const {
123 // TODO(kylechar): This obviously isn't right. We either need to pass this
124 // state around or modify the interface.
125 return true;
126 }
127
128 } // namespace input_device
OLDNEW
« no previous file with comments | « components/mus/public/cpp/input_devices/input_device_client.h ('k') | components/mus/public/interfaces/input_devices/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698