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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/events/ozone/device/device_manager_manual.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/ozone/device/device_manager_manual.h" 5 #include "ui/events/ozone/device/device_manager_manual.h"
6 6
7 #include "base/bind.h"
8 #include "base/callback.h"
7 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/location.h"
11 #include "base/threading/worker_pool.h"
8 #include "ui/events/ozone/device/device_event.h" 12 #include "ui/events/ozone/device/device_event.h"
9 #include "ui/events/ozone/device/device_event_observer.h" 13 #include "ui/events/ozone/device/device_event_observer.h"
10 14
11 namespace ui { 15 namespace ui {
12 16
13 DeviceManagerManual::DeviceManagerManual() {} 17 namespace {
14 18
15 DeviceManagerManual::~DeviceManagerManual() {} 19 void ScanDevicesOnWorkerThread(std::vector<base::FilePath>* result) {
16
17 void DeviceManagerManual::ScanDevices(DeviceEventObserver* observer) {
18 base::FileEnumerator file_enum(base::FilePath("/dev/input"), 20 base::FileEnumerator file_enum(base::FilePath("/dev/input"),
19 false, 21 false,
20 base::FileEnumerator::FILES, 22 base::FileEnumerator::FILES,
21 "event*[0-9]"); 23 "event*[0-9]");
22 for (base::FilePath path = file_enum.Next(); !path.empty(); 24 for (base::FilePath path = file_enum.Next(); !path.empty();
23 path = file_enum.Next()) { 25 path = file_enum.Next()) {
24 DeviceEvent event(DeviceEvent::INPUT, DeviceEvent::ADD, path); 26 result->push_back(path);
25 observer->OnDeviceEvent(event); 27 }
28 }
29 }
30
31 DeviceManagerManual::DeviceManagerManual()
32 : have_scanned_devices_(false), weak_ptr_factory_(this) {
33 }
34
35 DeviceManagerManual::~DeviceManagerManual() {
36 }
37
38 void DeviceManagerManual::ScanDevices(DeviceEventObserver* observer) {
39 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.
40 std::vector<base::FilePath>::const_iterator it = devices_.begin();
41 for (; it != devices_.end(); ++it) {
42 DeviceEvent event(DeviceEvent::INPUT, DeviceEvent::ADD, *it);
43 observer->OnDeviceEvent(event);
44 }
45 } else {
46 std::vector<base::FilePath>* result = new std::vector<base::FilePath>();
47 base::WorkerPool::PostTaskAndReply(
48 FROM_HERE, base::Bind(&ScanDevicesOnWorkerThread, result),
49 base::Bind(&DeviceManagerManual::OnDevicesScanned,
50 weak_ptr_factory_.GetWeakPtr(), base::Owned(result)),
51 false /* task_is_slow */);
52 have_scanned_devices_ = true;
26 } 53 }
27 } 54 }
28 55
29 void DeviceManagerManual::AddObserver(DeviceEventObserver* observer) {} 56 void DeviceManagerManual::AddObserver(DeviceEventObserver* observer) {
57 observers_.AddObserver(observer);
58 }
30 59
31 void DeviceManagerManual::RemoveObserver(DeviceEventObserver* observer) {} 60 void DeviceManagerManual::RemoveObserver(DeviceEventObserver* observer) {
61 observers_.RemoveObserver(observer);
62 }
63
64 void DeviceManagerManual::OnDevicesScanned(
65 std::vector<base::FilePath>* result) {
66 std::vector<base::FilePath>::const_iterator it = result->begin();
67 for (; it != result->end(); ++it) {
68 devices_.push_back(*it);
69 DeviceEvent event(DeviceEvent::INPUT, DeviceEvent::ADD, *it);
70 FOR_EACH_OBSERVER(DeviceEventObserver, observers_, OnDeviceEvent(event));
71 }
72 }
32 73
33 } // namespace ui 74 } // namespace ui
OLDNEW
« 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