Commit 97646c94 authored by wjia@chromium.org's avatar wjia@chromium.org

Add DeviceMonitorLinux in BrowserMainLoop.

The DeviceMonitorLinux detects device change and sends the signal to SystemMonitor.

This patch depends on http://codereview.chromium.org/10836004/

BUG=137799
Review URL: https://chromiumcodereview.appspot.com/10829073

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149266 0039d316-1c4b-4281-b951-d872f2087c98
parent 584b602a
...@@ -66,6 +66,10 @@ ...@@ -66,6 +66,10 @@
#include <glib-object.h> #include <glib-object.h>
#endif #endif
#if defined(OS_LINUX)
#include "content/browser/device_monitor_linux.h"
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#endif #endif
...@@ -615,6 +619,10 @@ void BrowserMainLoop::BrowserThreadsStarted() { ...@@ -615,6 +619,10 @@ void BrowserMainLoop::BrowserThreadsStarted() {
ImageTransportFactory::Initialize(); ImageTransportFactory::Initialize();
#endif #endif
#if defined(OS_LINUX)
device_monitor_linux_.reset(new DeviceMonitorLinux());
#endif
// RDH needs the IO thread to be created. // RDH needs the IO thread to be created.
resource_dispatcher_host_.reset(new ResourceDispatcherHostImpl()); resource_dispatcher_host_.reset(new ResourceDispatcherHostImpl());
......
...@@ -44,9 +44,13 @@ namespace content { ...@@ -44,9 +44,13 @@ namespace content {
class BrowserMainParts; class BrowserMainParts;
class BrowserShutdownImpl; class BrowserShutdownImpl;
class BrowserThreadImpl; class BrowserThreadImpl;
struct MainFunctionParams;
class ResourceDispatcherHostImpl; class ResourceDispatcherHostImpl;
class WebKitThread; class WebKitThread;
struct MainFunctionParams;
#if defined(OS_LINUX)
class DeviceMonitorLinux;
#endif
// Implements the main browser loop stages called from BrowserMainRunner. // Implements the main browser loop stages called from BrowserMainRunner.
// See comments in browser_main_parts.h for additional info. // See comments in browser_main_parts.h for additional info.
...@@ -105,6 +109,8 @@ class BrowserMainLoop { ...@@ -105,6 +109,8 @@ class BrowserMainLoop {
scoped_ptr<BrowserOnlineStateObserver> online_state_observer_; scoped_ptr<BrowserOnlineStateObserver> online_state_observer_;
#if defined(OS_WIN) #if defined(OS_WIN)
scoped_ptr<SystemMessageWindowWin> system_message_window_; scoped_ptr<SystemMessageWindowWin> system_message_window_;
#elif defined(OS_LINUX)
scoped_ptr<DeviceMonitorLinux> device_monitor_linux_;
#endif #endif
// Destroy parts_ before main_message_loop_ (required) and before other // Destroy parts_ before main_message_loop_ (required) and before other
......
// 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;
};
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_|.
MessageLoop::current()->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() {
// 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
// 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.
// This class is used to detect device change and notify base::SystemMonitor
// on Linux.
#ifndef CONTENT_BROWSER_DEVICE_MONITOR_LINUX_H_
#define CONTENT_BROWSER_DEVICE_MONITOR_LINUX_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
extern "C" {
struct udev_device;
}
namespace content {
class UdevLinux;
class DeviceMonitorLinux : public MessageLoop::DestructionObserver {
public:
DeviceMonitorLinux();
virtual ~DeviceMonitorLinux();
private:
// This object is deleted on the UI thread after the IO thread has been
// destroyed. Need to know when IO thread is being destroyed so that
// we can delete udev_.
virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
void Initialize();
void OnDevicesChanged(udev_device* device);
scoped_ptr<UdevLinux> udev_;
DISALLOW_COPY_AND_ASSIGN(DeviceMonitorLinux);
};
} // namespace content
#endif // CONTENT_BROWSER_DEVICE_MONITOR_LINUX_H_
...@@ -268,6 +268,8 @@ ...@@ -268,6 +268,8 @@
'browser/debugger/worker_devtools_manager.h', 'browser/debugger/worker_devtools_manager.h',
'browser/debugger/worker_devtools_message_filter.cc', 'browser/debugger/worker_devtools_message_filter.cc',
'browser/debugger/worker_devtools_message_filter.h', 'browser/debugger/worker_devtools_message_filter.h',
'browser/device_monitor_linux.cc',
'browser/device_monitor_linux.h',
'browser/device_orientation/accelerometer_mac.cc', 'browser/device_orientation/accelerometer_mac.cc',
'browser/device_orientation/accelerometer_mac.h', 'browser/device_orientation/accelerometer_mac.h',
'browser/device_orientation/data_fetcher.h', 'browser/device_orientation/data_fetcher.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment