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

Unified Diff: ui/events/ozone/evdev/event_factory_evdev.cc

Issue 250793005: Refactor Udev device support in Ozone and add a DRM hotplug monitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 8 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
« no previous file with comments | « ui/events/ozone/evdev/event_factory_evdev.h ('k') | ui/events/ozone/evdev/scoped_udev.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/ozone/evdev/event_factory_evdev.cc
diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/event_factory_evdev.cc
index a36d9e7118708cad33828dbb680adeababbc7a04..47b46b4d3d67e9f66128f8fc771ec84206eaa08b 100644
--- a/ui/events/ozone/evdev/event_factory_evdev.cc
+++ b/ui/events/ozone/evdev/event_factory_evdev.cc
@@ -10,16 +10,13 @@
#include "base/debug/trace_event.h"
#include "base/stl_util.h"
#include "base/task_runner.h"
+#include "ui/events/ozone/device/device_event.h"
+#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
-#include "ui/events/ozone/evdev/device_manager_evdev.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/key_event_converter_evdev.h"
#include "ui/events/ozone/evdev/touch_event_converter_evdev.h"
-#if defined(USE_UDEV)
-#include "ui/events/ozone/evdev/device_manager_udev.h"
-#endif
-
#if defined(USE_EVDEV_GESTURES)
#include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h"
#include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h"
@@ -133,7 +130,9 @@ void CloseInputDevice(const base::FilePath& path,
} // namespace
EventFactoryEvdev::EventFactoryEvdev()
- : ui_task_runner_(base::MessageLoopProxy::current()),
+ : device_manager_(NULL),
+ has_started_processing_events_(false),
+ ui_task_runner_(base::MessageLoopProxy::current()),
file_task_runner_(base::MessageLoopProxy::current()),
cursor_(NULL),
dispatch_callback_(
@@ -141,8 +140,12 @@ EventFactoryEvdev::EventFactoryEvdev()
base::Unretained(this))),
weak_ptr_factory_(this) {}
-EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor)
- : ui_task_runner_(base::MessageLoopProxy::current()),
+EventFactoryEvdev::EventFactoryEvdev(
+ CursorDelegateEvdev* cursor,
+ DeviceManager* device_manager)
+ : device_manager_(device_manager),
+ has_started_processing_events_(false),
+ ui_task_runner_(base::MessageLoopProxy::current()),
file_task_runner_(base::MessageLoopProxy::current()),
cursor_(cursor),
dispatch_callback_(
@@ -172,21 +175,35 @@ void EventFactoryEvdev::AttachInputDevice(
converters_[path]->Start();
}
-void EventFactoryEvdev::OnDeviceAdded(const base::FilePath& path) {
- TRACE_EVENT1("ozone", "OnDeviceAdded", "path", path.value());
-
- // Dispatch task to open on FILE thread, since open may block.
- file_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&OpenInputDevice,
- path,
- &modifiers_,
- cursor_,
- ui_task_runner_,
- dispatch_callback_,
- base::Bind(&EventFactoryEvdev::AttachInputDevice,
- weak_ptr_factory_.GetWeakPtr(),
- path)));
+void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
+ if (event.device_type() != DeviceEvent::INPUT)
+ return;
+
+ switch (event.action_type()) {
+ case DeviceEvent::ADD:
+ case DeviceEvent::CHANGE: {
+ TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value());
+
+ // Dispatch task to open on FILE thread, since open may block.
+ file_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&OpenInputDevice,
+ event.path(),
+ &modifiers_,
+ cursor_,
+ ui_task_runner_,
+ dispatch_callback_,
+ base::Bind(&EventFactoryEvdev::AttachInputDevice,
+ weak_ptr_factory_.GetWeakPtr(),
+ event.path())));
+ }
+ break;
+ case DeviceEvent::REMOVE: {
+ TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value());
+ DetachInputDevice(event.path());
+ }
+ break;
+ }
}
void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) {
@@ -209,26 +226,15 @@ void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) {
}
}
-void EventFactoryEvdev::OnDeviceRemoved(const base::FilePath& path) {
- TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", path.value());
- DetachInputDevice(path);
-}
-
void EventFactoryEvdev::StartProcessingEvents() {
CHECK(ui_task_runner_->RunsTasksOnCurrentThread());
-#if defined(USE_UDEV)
- // Scan for input devices using udev.
- device_manager_ = CreateDeviceManagerUdev();
-#else
- // No udev support. Scan devices manually in /dev/input.
- device_manager_ = CreateDeviceManagerManual();
-#endif
-
- // Scan & monitor devices.
- device_manager_->ScanAndStartMonitoring(
- base::Bind(&EventFactoryEvdev::OnDeviceAdded, base::Unretained(this)),
- base::Bind(&EventFactoryEvdev::OnDeviceRemoved, base::Unretained(this)));
+ if (device_manager_ && !has_started_processing_events_) {
+ has_started_processing_events_ = true;
+ // Scan & monitor devices.
+ device_manager_->AddObserver(this);
+ device_manager_->ScanDevices(this);
+ }
}
void EventFactoryEvdev::SetFileTaskRunner(
« no previous file with comments | « ui/events/ozone/evdev/event_factory_evdev.h ('k') | ui/events/ozone/evdev/scoped_udev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698