summaryrefslogtreecommitdiff
path: root/chromium/content/browser/device_monitor_udev.cc
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2014-03-18 13:16:26 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-20 15:55:39 +0100
commit3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch)
tree92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/content/browser/device_monitor_udev.cc
parente90d7c4b152c56919d963987e2503f9909a666d2 (diff)
downloadqtwebengine-chromium-3f0f86b0caed75241fa71c95a5d73bc0164348c5.tar.gz
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies needed on Windows. Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42 Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu> Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/content/browser/device_monitor_udev.cc')
-rw-r--r--chromium/content/browser/device_monitor_udev.cc87
1 files changed, 87 insertions, 0 deletions
diff --git a/chromium/content/browser/device_monitor_udev.cc b/chromium/content/browser/device_monitor_udev.cc
new file mode 100644
index 00000000000..ddfe053eae2
--- /dev/null
+++ b/chromium/content/browser/device_monitor_udev.cc
@@ -0,0 +1,87 @@
+// Copyright 2013 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_udev.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;
+};
+
+const char kAudioSubsystem[] = "sound";
+const char kVideoSubsystem[] = "video4linux";
+
+// Add more subsystems here for monitoring.
+const SubsystemMap kSubsystemMap[] = {
+ { base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE, kAudioSubsystem, NULL },
+ { base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE, kVideoSubsystem, NULL },
+};
+
+} // namespace
+
+namespace content {
+
+DeviceMonitorLinux::DeviceMonitorLinux() {
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
+ BrowserThread::PostTask(BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&DeviceMonitorLinux::Initialize, base::Unretained(this)));
+}
+
+DeviceMonitorLinux::~DeviceMonitorLinux() {
+}
+
+void DeviceMonitorLinux::Initialize() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ // We want to be notified of IO message loop destruction to delete |udev_|.
+ base::MessageLoop::current()->AddDestructionObserver(this);
+
+ std::vector<UdevLinux::UdevMonitorFilter> filters;
+ for (size_t i = 0; i < arraysize(kSubsystemMap); ++i) {
+ filters.push_back(UdevLinux::UdevMonitorFilter(
+ kSubsystemMap[i].subsystem, kSubsystemMap[i].devtype));
+ }
+ udev_.reset(new UdevLinux(filters,
+ base::Bind(&DeviceMonitorLinux::OnDevicesChanged,
+ base::Unretained(this))));
+}
+
+void DeviceMonitorLinux::WillDestroyCurrentMessageLoop() {
+ // Called on IO thread.
+ udev_.reset();
+}
+
+void DeviceMonitorLinux::OnDevicesChanged(udev_device* device) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(device);
+
+ 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 == kSubsystemMap[i].subsystem) {
+ device_type = kSubsystemMap[i].device_type;
+ break;
+ }
+ }
+ DCHECK_NE(device_type, base::SystemMonitor::DEVTYPE_UNKNOWN);
+
+ base::SystemMonitor::Get()->ProcessDevicesChanged(device_type);
+}
+
+} // namespace content