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

Side by Side Diff: content/browser/devices_monitor/devices_monitor_linux.cc

Issue 10829073: Add DeviceMonitorLinux in BrowserMainLoop. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // libudev is used for monitoring device changes.
6
7 #include "content/browser/devices_monitor/devices_monitor_linux.h"
8
9 #include <libudev.h>
10 #include <string>
11
12 #include "content/browser/udev_linux.h"
13 #include "content/public/browser/browser_thread.h"
14
15 namespace {
16
17 struct SubsystemMap {
18 base::SystemMonitor::DeviceType device_type;
19 const char* subsystem;
20 const char* devtype;
21 };
22
23 static const char kAudioSubsystem[] = "sound";
24 static const char kVideoSubsystem[] = "video4linux";
25
26 // Add more subsystems here for monitoring.
27 static const SubsystemMap subsystem_map[] = {
tommi (sloooow) - chröme 2012/07/30 11:07:04 kSubsystemMap
28 {base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL},
tommi (sloooow) - chröme 2012/07/30 11:07:04 space after { and before }
29 {base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL},
30 };
31
32 static const int subsystem_map_size =
tommi (sloooow) - chröme 2012/07/30 11:07:04 kSubsystemMapSize
33 sizeof(subsystem_map) / sizeof(subsystem_map[0]);
34
35 } // namespace
36
37 namespace content {
38
39 // static
40 DevicesMonitor* DevicesMonitor::Create() {
41 return new DevicesMonitorLinux();
tommi (sloooow) - chröme 2012/07/30 11:07:04 Here, we could (should?) post a task to the IO thr
42 }
43
44 DevicesMonitorLinux::DevicesMonitorLinux() {}
45
46 DevicesMonitorLinux::~DevicesMonitorLinux() {}
47
48 void DevicesMonitorLinux::Start(
49 base::SystemMonitor::DevicesChangedObserver* observer) {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51
52 if (observers_.find(observer) != observers_.end())
53 return; // Monitoring for this client has been started.
54
55 if (observers_.empty()) {
56 // First observer. Need start monitoring.
57 std::vector<UdevLinux::UdevMonitorFilter> filters;
58 for (int i = 0; i < subsystem_map_size; ++i) {
59 filters.push_back(content::UdevLinux::UdevMonitorFilter(
60 subsystem_map[i].subsystem, subsystem_map[i].devtype));
61 }
62 udev_.reset(new UdevLinux(filters,
63 base::Bind(&DevicesMonitorLinux::OnDevicesChanged,
64 base::Unretained(this))));
65 }
66
67 observers_.insert(observer);
68 }
69
70 void DevicesMonitorLinux::Stop(
71 base::SystemMonitor::DevicesChangedObserver* observer) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
73
74 if (observers_.find(observer) != observers_.end()) {
75 observers_.erase(observer);
76 if (observers_.empty())
77 udev_.reset();
78 }
79 }
80
81 void DevicesMonitorLinux::OnDevicesChanged(udev_device* device) {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
83
84 if (device) {
85 base::SystemMonitor::DeviceType device_type =
86 base::SystemMonitor::DEVTYPE_UNKNOWN;
87 std::string subsystem(udev_device_get_subsystem(device));
88 for (int i = 0; i < subsystem_map_size; ++i) {
89 if (subsystem.compare(subsystem_map[i].subsystem) == 0) {
90 device_type = subsystem_map[i].device_type;
91 break;
92 }
93 }
94
95 base::SystemMonitor::Get()->ProcessDevicesChanged(device_type);
tommi (sloooow) - chröme 2012/07/30 11:07:04 I see we don't use the observer map here and I don
96 }
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698