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

Unified Diff: ui/events/ozone/device/device_manager_manual.cc

Issue 853073003: Fix assertion starting cast_shell (breaking thread IO restrictions). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Whitespace fixes plus task is not slow Created 5 years, 11 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/device/device_manager_manual.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/ozone/device/device_manager_manual.cc
diff --git a/ui/events/ozone/device/device_manager_manual.cc b/ui/events/ozone/device/device_manager_manual.cc
index c86ffccf62bdae50079e2927d77841a24cefdc7d..f5e1eca3e4e9c3b20060ee93ab12dc57ce30e5e2 100644
--- a/ui/events/ozone/device/device_manager_manual.cc
+++ b/ui/events/ozone/device/device_manager_manual.cc
@@ -4,30 +4,71 @@
#include "ui/events/ozone/device/device_manager_manual.h"
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/files/file_enumerator.h"
+#include "base/location.h"
+#include "base/threading/worker_pool.h"
#include "ui/events/ozone/device/device_event.h"
#include "ui/events/ozone/device/device_event_observer.h"
namespace ui {
-DeviceManagerManual::DeviceManagerManual() {}
+namespace {
-DeviceManagerManual::~DeviceManagerManual() {}
-
-void DeviceManagerManual::ScanDevices(DeviceEventObserver* observer) {
+void ScanDevicesOnWorkerThread(std::vector<base::FilePath>* result) {
base::FileEnumerator file_enum(base::FilePath("/dev/input"),
false,
base::FileEnumerator::FILES,
"event*[0-9]");
for (base::FilePath path = file_enum.Next(); !path.empty();
path = file_enum.Next()) {
- DeviceEvent event(DeviceEvent::INPUT, DeviceEvent::ADD, path);
- observer->OnDeviceEvent(event);
+ result->push_back(path);
+ }
+}
+}
+
+DeviceManagerManual::DeviceManagerManual()
+ : have_scanned_devices_(false), weak_ptr_factory_(this) {
+}
+
+DeviceManagerManual::~DeviceManagerManual() {
+}
+
+void DeviceManagerManual::ScanDevices(DeviceEventObserver* observer) {
+ if (have_scanned_devices_) {
dnicoara 2015/01/22 22:38:57 Drive-by comment: If multiple callers end up scann
spang 2015/01/22 22:42:02 have_scanned_devices_ is set here in this function
dnicoara 2015/01/22 22:43:13 Oh, sorry, didn't notice it. Sorry for the noise.
+ std::vector<base::FilePath>::const_iterator it = devices_.begin();
+ for (; it != devices_.end(); ++it) {
+ DeviceEvent event(DeviceEvent::INPUT, DeviceEvent::ADD, *it);
+ observer->OnDeviceEvent(event);
+ }
+ } else {
+ std::vector<base::FilePath>* result = new std::vector<base::FilePath>();
+ base::WorkerPool::PostTaskAndReply(
+ FROM_HERE, base::Bind(&ScanDevicesOnWorkerThread, result),
+ base::Bind(&DeviceManagerManual::OnDevicesScanned,
+ weak_ptr_factory_.GetWeakPtr(), base::Owned(result)),
+ false /* task_is_slow */);
+ have_scanned_devices_ = true;
}
}
-void DeviceManagerManual::AddObserver(DeviceEventObserver* observer) {}
+void DeviceManagerManual::AddObserver(DeviceEventObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void DeviceManagerManual::RemoveObserver(DeviceEventObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
-void DeviceManagerManual::RemoveObserver(DeviceEventObserver* observer) {}
+void DeviceManagerManual::OnDevicesScanned(
+ std::vector<base::FilePath>* result) {
+ std::vector<base::FilePath>::const_iterator it = result->begin();
+ for (; it != result->end(); ++it) {
+ devices_.push_back(*it);
+ DeviceEvent event(DeviceEvent::INPUT, DeviceEvent::ADD, *it);
+ FOR_EACH_OBSERVER(DeviceEventObserver, observers_, OnDeviceEvent(event));
+ }
+}
} // namespace ui
« no previous file with comments | « ui/events/ozone/device/device_manager_manual.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698