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

Unified 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: Change namespace. 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 side-by-side diff with in-line comments
Download patch
Index: components/mus/input_devices/input_device_server.cc
diff --git a/components/mus/input_devices/input_device_server.cc b/components/mus/input_devices/input_device_server.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df0fd6c123428df2dda0f3fca9170f34b25b056e
--- /dev/null
+++ b/components/mus/input_devices/input_device_server.cc
@@ -0,0 +1,106 @@
+// 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/input_device_server.h"
+
+#include <utility>
+#include <vector>
+
+#include "mojo/public/cpp/bindings/array.h"
+#include "ui/events/devices/input_device.h"
+#include "ui/events/devices/touchscreen_device.h"
+
+namespace mus {
+
+InputDeviceServer::InputDeviceServer() {}
+
+InputDeviceServer::~InputDeviceServer() {
+ if (manager_ && ui::DeviceDataManager::HasInstance()) {
+ manager_->RemoveObserver(this);
+ manager_ = nullptr;
+ }
+}
+
+void InputDeviceServer::RegisterAsObserver() {
+ if (!manager_) {
+ manager_ = ui::DeviceDataManager::GetInstance();
+ manager_->AddObserver(this);
+ }
+}
+
+void InputDeviceServer::RegisterInterface(shell::Connection* connection) {
+ DCHECK(manager_);
+ connection->AddInterface<mojom::InputDeviceServer>(this);
+}
+
+void InputDeviceServer::AddObserver(
+ mojom::InputDeviceObserverMojoPtr observer) {
+ // We only want to send this message once, so we need to check to make sure
+ // device lists are actually complete before sending it to a new observer.
+ if (manager_->AreDeviceListsComplete())
+ SendDeviceListsComplete(observer.get());
+ observers_.AddPtr(std::move(observer));
+}
+
+void InputDeviceServer::OnKeyboardDeviceConfigurationChanged() {
+ if (!manager_->AreDeviceListsComplete())
+ return;
+
+ auto& devices = manager_->GetKeyboardDevices();
+ observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
+ observer->OnKeyboardDeviceConfigurationChanged(devices);
+ });
+}
+
+void InputDeviceServer::OnTouchscreenDeviceConfigurationChanged() {
+ if (!manager_->AreDeviceListsComplete())
+ return;
+
+ auto& devices = manager_->GetTouchscreenDevices();
+ observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
+ observer->OnTouchscreenDeviceConfigurationChanged(devices);
+ });
+}
+
+void InputDeviceServer::OnMouseDeviceConfigurationChanged() {
+ if (!manager_->AreDeviceListsComplete())
+ return;
+
+ auto& devices = manager_->GetMouseDevices();
+ observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
+ observer->OnMouseDeviceConfigurationChanged(devices);
+ });
+}
+
+void InputDeviceServer::OnTouchpadDeviceConfigurationChanged() {
+ if (!manager_->AreDeviceListsComplete())
+ return;
+
+ auto& devices = manager_->GetTouchpadDevices();
+ observers_.ForAllPtrs([&devices](mojom::InputDeviceObserverMojo* observer) {
+ observer->OnTouchpadDeviceConfigurationChanged(devices);
+ });
+}
+
+void InputDeviceServer::OnDeviceListsComplete() {
+ observers_.ForAllPtrs([this](mojom::InputDeviceObserverMojo* observer) {
+ SendDeviceListsComplete(observer);
+ });
+}
+
+void InputDeviceServer::SendDeviceListsComplete(
+ mojom::InputDeviceObserverMojo* observer) {
+ DCHECK(manager_->AreDeviceListsComplete());
+
+ observer->OnDeviceListsComplete(
+ manager_->GetKeyboardDevices(), manager_->GetTouchscreenDevices(),
+ manager_->GetMouseDevices(), manager_->GetTouchpadDevices());
+}
+
+void InputDeviceServer::Create(shell::Connection* connection,
+ mojom::InputDeviceServerRequest request) {
+ bindings_.AddBinding(this, std::move(request));
+}
+
+} // namespace mus
« no previous file with comments | « components/mus/input_devices/input_device_server.h ('k') | components/mus/public/cpp/input_devices/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698