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

Unified Diff: content/browser/device_monitor_linux.cc

Issue 10829073: Add DeviceMonitorLinux in BrowserMainLoop. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 8 years, 5 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 | « content/browser/device_monitor_linux.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,91 @@
+// 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>
Lei Zhang 2012/07/31 00:04:58 nit: Chromium style separates C headers from C++ h
wjia(left Chromium) 2012/07/31 01:20:01 Done.
+#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";
Lei Zhang 2012/07/31 00:04:58 nit: you don't need static inside an anonymous nam
wjia(left Chromium) 2012/07/31 01:20:01 Done.
+static const char kVideoSubsystem[] = "video4linux";
+
+// Add more subsystems here for monitoring.
+static const SubsystemMap kSubsystemMap[] = {
+ { base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL },
+ { base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL },
+};
+
+} // 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_.
Lei Zhang 2012/07/31 00:04:58 nit, |udev_|.
wjia(left Chromium) 2012/07/31 01:20:01 Done.
+ io_loop_ = MessageLoop::current();
+ io_loop_->AddDestructionObserver(this);
+
+ std::vector<UdevLinux::UdevMonitorFilter> filters;
+ for (size_t i = 0; i < arraysize(kSubsystemMap); ++i) {
+ filters.push_back(content::UdevLinux::UdevMonitorFilter(
+ kSubsystemMap[i].subsystem, kSubsystemMap[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) {
Lei Zhang 2012/07/31 00:04:58 |device| should never be NULL. You can put a DCHEC
wjia(left Chromium) 2012/07/31 01:20:01 Done.
+ base::SystemMonitor::DeviceType device_type =
+ base::SystemMonitor::DEVTYPE_UNKNOWN;
+ std::string subsystem(udev_device_get_subsystem(device));
+ for (size_t i = 0; i < arraysize(kSubsystemMap); ++i) {
+ if (subsystem.compare(kSubsystemMap[i].subsystem) == 0) {
Lei Zhang 2012/07/31 00:04:58 nit: you can just write if (subsystem == kSubsyste
wjia(left Chromium) 2012/07/31 01:20:01 Done.
+ device_type = kSubsystemMap[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
« no previous file with comments | « content/browser/device_monitor_linux.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698