Index: content/browser/device_monitor_linux.cc |
=================================================================== |
--- content/browser/device_monitor_linux.cc (revision 0) |
+++ content/browser/device_monitor_linux.cc (revision 0) |
@@ -0,0 +1,94 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// libudev is used for monitoring device changes. |
+ |
+#include "content/browser/device_monitor_linux.h" |
+ |
+#include <libudev.h> |
+#include <string> |
+ |
+#include "base/system_monitor/system_monitor.h" |
+#include "content/browser/udev_linux.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+namespace { |
+ |
+struct SubsystemMap { |
+ base::SystemMonitor::DeviceType device_type; |
+ const char* subsystem; |
+ const char* devtype; |
+}; |
+ |
+static const char kAudioSubsystem[] = "sound"; |
+static const char kVideoSubsystem[] = "video4linux"; |
+ |
+// Add more subsystems here for monitoring. |
+static const SubsystemMap subsystem_map[] = { |
tommi (sloooow) - chröme
2012/07/30 19:45:11
kSubsystemMap
wjia(left Chromium)
2012/07/30 21:00:13
Done.
|
+ {base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL}, |
tommi (sloooow) - chröme
2012/07/30 19:45:11
space after { and before }
wjia(left Chromium)
2012/07/30 21:00:13
Done.
|
+ {base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL}, |
+}; |
+ |
+static const int subsystem_map_size = |
tommi (sloooow) - chröme
2012/07/30 19:45:11
You don't need this variable. Just use arraysize(k
wjia(left Chromium)
2012/07/30 21:00:13
Done.
|
+ sizeof(subsystem_map) / sizeof(subsystem_map[0]); |
+ |
+} // namespace |
+ |
+namespace content { |
+ |
+DeviceMonitorLinux::DeviceMonitorLinux() |
+ : io_loop_(NULL) { |
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); |
+ BrowserThread::PostTask(BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&DeviceMonitorLinux::Initialize, base::Unretained(this))); |
+} |
+ |
+DeviceMonitorLinux::~DeviceMonitorLinux() { |
+ DCHECK(!io_loop_); |
+} |
+ |
+void DeviceMonitorLinux::Initialize() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+ // We want to be notified of IO message loop destruction to delete udev_. |
+ io_loop_ = MessageLoop::current(); |
+ io_loop_->AddDestructionObserver(this); |
+ |
+ std::vector<UdevLinux::UdevMonitorFilter> filters; |
+ for (int i = 0; i < subsystem_map_size; ++i) { |
tommi (sloooow) - chröme
2012/07/30 19:45:11
arraysize(kSubsystemMap)
wjia(left Chromium)
2012/07/30 21:00:13
Done.
|
+ filters.push_back(content::UdevLinux::UdevMonitorFilter( |
+ subsystem_map[i].subsystem, subsystem_map[i].devtype)); |
+ } |
+ udev_.reset(new UdevLinux(filters, |
+ base::Bind(&DeviceMonitorLinux::OnDevicesChanged, |
+ base::Unretained(this)))); |
+} |
+ |
+void DeviceMonitorLinux::WillDestroyCurrentMessageLoop() { |
+ DCHECK_EQ(MessageLoop::current(), io_loop_); |
+ |
+ udev_.reset(); |
+ io_loop_ = NULL; |
+} |
+ |
+void DeviceMonitorLinux::OnDevicesChanged(udev_device* device) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+ if (device) { |
+ base::SystemMonitor::DeviceType device_type = |
+ base::SystemMonitor::DEVTYPE_UNKNOWN; |
+ std::string subsystem(udev_device_get_subsystem(device)); |
+ for (int i = 0; i < subsystem_map_size; ++i) { |
tommi (sloooow) - chröme
2012/07/30 19:45:11
arraysize(kSubsystemMap)
wjia(left Chromium)
2012/07/30 21:00:13
Done.
|
+ if (subsystem.compare(subsystem_map[i].subsystem) == 0) { |
+ device_type = subsystem_map[i].device_type; |
+ break; |
+ } |
+ } |
+ |
+ base::SystemMonitor::Get()->ProcessDevicesChanged(device_type); |
+ } |
+} |
+ |
+} // namespace content |
Property changes on: content/browser/device_monitor_linux.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |