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

Side by Side Diff: content/browser/device_monitor_linux.cc

Issue 10829073: Add DeviceMonitorLinux in BrowserMainLoop. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: more code review 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/device_monitor_linux.h"
8
9 #include <libudev.h>
10
11 #include <string>
12
13 #include "base/system_monitor/system_monitor.h"
14 #include "content/browser/udev_linux.h"
15 #include "content/public/browser/browser_thread.h"
16
17 namespace {
18
19 struct SubsystemMap {
20 base::SystemMonitor::DeviceType device_type;
21 const char* subsystem;
22 const char* devtype;
23 };
24
25 const char kAudioSubsystem[] = "sound";
26 const char kVideoSubsystem[] = "video4linux";
27
28 // Add more subsystems here for monitoring.
29 const SubsystemMap kSubsystemMap[] = {
30 { base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL },
31 { base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL },
32 };
33
34 } // namespace
35
36 namespace content {
37
38 DeviceMonitorLinux::DeviceMonitorLinux()
39 : io_loop_(NULL) {
jam 2012/07/31 15:46:05 we don't store MessageLoop pointers as a rule, sin
wjia(left Chromium) 2012/07/31 18:19:08 Done.
40 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
41 BrowserThread::PostTask(BrowserThread::IO,
42 FROM_HERE,
43 base::Bind(&DeviceMonitorLinux::Initialize, base::Unretained(this)));
44 }
45
46 DeviceMonitorLinux::~DeviceMonitorLinux() {
47 DCHECK(!io_loop_);
48 }
49
50 void DeviceMonitorLinux::Initialize() {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
52
53 // We want to be notified of IO message loop destruction to delete |udev_|.
54 io_loop_ = MessageLoop::current();
55 io_loop_->AddDestructionObserver(this);
56
57 std::vector<UdevLinux::UdevMonitorFilter> filters;
58 for (size_t i = 0; i < arraysize(kSubsystemMap); ++i) {
59 filters.push_back(content::UdevLinux::UdevMonitorFilter(
60 kSubsystemMap[i].subsystem, kSubsystemMap[i].devtype));
61 }
62 udev_.reset(new UdevLinux(filters,
63 base::Bind(&DeviceMonitorLinux::OnDevicesChanged,
64 base::Unretained(this))));
65 }
66
67 void DeviceMonitorLinux::WillDestroyCurrentMessageLoop() {
68 DCHECK_EQ(MessageLoop::current(), io_loop_);
69
70 udev_.reset();
71 io_loop_ = NULL;
72 }
73
74 void DeviceMonitorLinux::OnDevicesChanged(udev_device* device) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
76 DCHECK(device);
77
78 base::SystemMonitor::DeviceType device_type =
79 base::SystemMonitor::DEVTYPE_UNKNOWN;
80 std::string subsystem(udev_device_get_subsystem(device));
81 for (size_t i = 0; i < arraysize(kSubsystemMap); ++i) {
82 if (subsystem == kSubsystemMap[i].subsystem) {
83 device_type = kSubsystemMap[i].device_type;
84 break;
85 }
86 }
87 DCHECK_NE(device_type, base::SystemMonitor::DEVTYPE_UNKNOWN);
88
89 base::SystemMonitor::Get()->ProcessDevicesChanged(device_type);
90 }
91
92 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698