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

Unified Diff: components/input_device_service/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: 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 side-by-side diff with in-line comments
Download patch
Index: components/input_device_service/input_device_client.cc
diff --git a/components/input_device_service/input_device_client.cc b/components/input_device_service/input_device_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6f1663fbba58a79554a95f71ceeec2e5ef1b7661
--- /dev/null
+++ b/components/input_device_service/input_device_client.cc
@@ -0,0 +1,136 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/input_device_service/input_device_client.h"
+
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+
+namespace input_device {
+
+namespace {
+
+// TODO(kylechar): Debug, remove eventually.
+template <class DeviceType>
+void PrintDevices(std::string title, const DeviceType& devices) {
+ LOG(ERROR) << title << " devices.size()=" << devices.size();
+ for (const auto& device : devices) {
+ LOG(ERROR) << device.ToString();
+ }
+}
+
+} // namespace
+
+InputDeviceClient::InputDeviceClient() : binding_(this) {}
+
+InputDeviceClient::~InputDeviceClient() {
+ InputDeviceService::ClearInstance();
+}
+
+void InputDeviceClient::Initialize(shell::Connector* connector) {
+ connector->ConnectToInterface("mojo:mus", &service_);
+
+ // Add this class as an observer via Mojo IPC.
+ service_->AddObserver(binding_.CreateInterfacePtrAndBind());
+
+ // TODO(kylechar): Can we somehow check for a successful connection here?
+ RequestDeviceUpdates();
+
+ // Install this as the InputDeviceService.
+ InputDeviceService::SetInstance(this);
+}
+
+void InputDeviceClient::OnKeyboardDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ UpdateKeyboardDevices(std::move(devices));
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnKeyboardDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ UpdateTouchscreenDevices(std::move(devices));
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnTouchscreenDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnMouseDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ UpdateMouseDevices(std::move(devices));
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnMouseDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnTouchpadDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ UpdateTouchpadDevices(std::move(devices));
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnTouchpadDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::AddObserver(ui::InputDeviceEventObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void InputDeviceClient::RemoveObserver(ui::InputDeviceEventObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+const std::vector<ui::InputDevice>& InputDeviceClient::keyboard_devices() {
+ return keyboard_devices_;
+}
+
+const std::vector<ui::InputDevice>& InputDeviceClient::touchscreen_devices() {
+ return touchscreen_devices_;
+}
+
+const std::vector<ui::InputDevice>& InputDeviceClient::mouse_devices() {
+ return mouse_devices_;
+}
+
+const std::vector<ui::InputDevice>& InputDeviceClient::touchpad_devices() {
+ return touchpad_devices_;
+}
+
+void InputDeviceClient::RequestDeviceUpdates() {
+ // TODO(kylechar): Maybe this should use a weakptr_factory?
+ service_->GetKeyboardDevices(base::Bind(
+ &InputDeviceClient::UpdateKeyboardDevices, base::Unretained(this)));
+
+ service_->GetTouchscreenDevices(base::Bind(
+ &InputDeviceClient::UpdateTouchscreenDevices, base::Unretained(this)));
+
+ service_->GetMouseDevices(base::Bind(&InputDeviceClient::UpdateMouseDevices,
+ base::Unretained(this)));
+
+ service_->GetTouchpadDevices(base::Bind(
+ &InputDeviceClient::UpdateTouchpadDevices, base::Unretained(this)));
+}
+
+void InputDeviceClient::UpdateKeyboardDevices(
+ mojo::Array<ui::InputDevice> devices) {
+ keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateKeyboardDevices", keyboard_devices_);
+}
+
+void InputDeviceClient::UpdateTouchscreenDevices(
+ mojo::Array<ui::InputDevice> devices) {
+ touchscreen_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateTouchscreenDevices", touchscreen_devices_);
+}
+
+void InputDeviceClient::UpdateMouseDevices(
+ mojo::Array<ui::InputDevice> devices) {
+ mouse_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateMouseDevices", mouse_devices_);
+}
+
+void InputDeviceClient::UpdateTouchpadDevices(
+ mojo::Array<ui::InputDevice> devices) {
+ touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateTouchpadDevices", touchpad_devices_);
+}
+
+} // namespace input_device

Powered by Google App Engine
This is Rietveld 408576698