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

Unified Diff: components/mus/input_devices/public/cpp/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: Updated. 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/mus/input_devices/public/cpp/lib/input_device_client.cc
diff --git a/components/mus/input_devices/public/cpp/lib/input_device_client.cc b/components/mus/input_devices/public/cpp/lib/input_device_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0129fc9e0f1b3e273d6e59b2ba45a863589072ea
--- /dev/null
+++ b/components/mus/input_devices/public/cpp/lib/input_device_client.cc
@@ -0,0 +1,125 @@
+// 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/mus/input_devices/public/cpp/input_device_client.h"
+
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+
+namespace input_device {
+
+namespace {
+
+// TODO(kylechar): Debug, remove eventually.
+template <class DeviceType>
+void PrintDevices(std::string title, const DeviceType& devices) {
+ std::vector<std::string> device_strings;
+ device_strings.push_back(base::StringPrintf("%s devices.size()=%zu",
+ title.c_str(), devices.size()));
+ for (const auto& device : devices) {
+ device_strings.push_back(device.ToString());
+ }
+ LOG(ERROR) << base::JoinString(device_strings, ", ");
+}
+
+} // namespace
+
+InputDeviceClient::InputDeviceClient() : binding_(this) {
+ InputDeviceManager::SetInstance(this);
+}
+
+InputDeviceClient::~InputDeviceClient() {
+ InputDeviceManager::ClearInstance();
+}
+
+void InputDeviceClient::Connect(shell::Connector* connector) {
+ mojom::InputDeviceServerPtr service;
+ connector->ConnectToInterface("mojo:mus", &service);
+
+ // Add this class as an observer via Mojo IPC.
+ service->AddObserver(binding_.CreateInterfacePtrAndBind());
+}
+
+void InputDeviceClient::OnKeyboardDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ keyboard_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateKeyboardDevices", keyboard_devices_);
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnKeyboardDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnTouchscreenDeviceConfigurationChanged(
+ mojo::Array<ui::TouchscreenDevice> devices) {
+ touchscreen_devices_ = devices.To<std::vector<ui::TouchscreenDevice>>();
+ PrintDevices("UpdateTouchscreenDevices", touchscreen_devices_);
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnTouchscreenDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnMouseDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ mouse_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateMouseDevices", mouse_devices_);
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnMouseDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnTouchpadDeviceConfigurationChanged(
+ mojo::Array<ui::InputDevice> devices) {
+ touchpad_devices_ = devices.To<std::vector<ui::InputDevice>>();
+ PrintDevices("UpdateTouchpadDevices", touchpad_devices_);
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnTouchpadDeviceConfigurationChanged());
+}
+
+void InputDeviceClient::OnDeviceListsComplete() {
+ if (!device_lists_complete_) {
+ LOG(ERROR) << "InputDeviceClient::OnDeviceListsComplete";
+ device_lists_complete_ = true;
+ FOR_EACH_OBSERVER(ui::InputDeviceEventObserver, observers_,
+ OnDeviceListsComplete());
+ }
+}
+
+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()
+ const {
+ return keyboard_devices_;
+}
+
+const std::vector<ui::TouchscreenDevice>&
+InputDeviceClient::touchscreen_devices() const {
+ return touchscreen_devices_;
+}
+
+const std::vector<ui::InputDevice>& InputDeviceClient::mouse_devices() const {
+ return mouse_devices_;
+}
+
+const std::vector<ui::InputDevice>& InputDeviceClient::touchpad_devices()
+ const {
+ return touchpad_devices_;
+}
+
+bool InputDeviceClient::device_lists_complete() const {
+ return device_lists_complete_;
+}
+
+bool InputDeviceClient::AreTouchscreensEnabled() const {
+ // TODO(kylechar): This obviously isn't right. We either need to pass this
+ // state around or modify the interface.
+ return true;
+}
+
+} // namespace input_device

Powered by Google App Engine
This is Rietveld 408576698