Skip to content

Commit

Permalink
move from content/browser: UDevLinux -> device/udev; DeviceMonitorUde…
Browse files Browse the repository at this point in the history
…v -> media/capture

BrowserMainLoop uses DeviceMonitorUdev to monitor for
audio/video device changes. This CL moves that monitor
to media/capture so it can be used from other sources
(concretely components/video_capture).

DeviceMonitorUdev uses content/browser/UDevLinux,
which is also used by GamepadPlatformDataFetcherLinux:
This CL also moves this UDevLinux to device/udev_linux.
to join its peers in

Note that this CL doesn't really add any dependencies that
were not there to start with.

Also rewritten two fors in DeviceMonitorLinux as range-fors,
and passing a ref to |io_task_runner| for thread checking.
For the rest, no new code.

** note that use_udev implies os==linux [1]

BUG=584817

[1] https://code.google.com/p/chromium/codesearch#chromium/src/build/common.gypi&l=758

Review URL: https://codereview.chromium.org/1674353003

Cr-Commit-Position: refs/heads/master@{#375014}
  • Loading branch information
yell0wd0g authored and Commit bot committed Feb 11, 2016
1 parent 80acd86 commit 9d20636
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 143 deletions.
17 changes: 5 additions & 12 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,13 @@ source_set("browser") {
}

if (use_udev) {
deps += [ "//device/udev_linux" ]
} else {
# Remove udev-specific sources.
sources -= [
"device_monitor_udev.cc",
"device_monitor_udev.h",
deps += [
"//device/udev_linux",
"//media/",
]
} else {
if (is_linux) {
# Already filtered out on non-Linux.
sources -= [
"gamepad/gamepad_platform_data_fetcher_linux.cc",
"udev_linux.cc",
"udev_linux.h",
]
sources -= [ "gamepad/gamepad_platform_data_fetcher_linux.cc" ]
}
}

Expand Down
2 changes: 1 addition & 1 deletion content/browser/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ include_rules = [
"+media/media_features.h",
"+media/audio", # For audio input for speech input feature.
"+media/base", # For Android JNI registration.
"+media/capture", # For Device Monitoring
"+media/filters", # For reporting GPU decoding UMA.
"+media/midi", # For Web MIDI API
"+media/mojo", # For mojo media services.
"+media/capture/video", # For Video Device monitoring in Mac.
"+mojo",
"+sql",
"+ui/aura_extra",
Expand Down
5 changes: 3 additions & 2 deletions content/browser/browser_main_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
#endif

#if defined(OS_LINUX) && defined(USE_UDEV)
#include "content/browser/device_monitor_udev.h"
#include "media/capture/device_monitor_udev.h"
#elif defined(OS_MACOSX) && !defined(OS_IOS)
#include "content/browser/device_monitor_mac.h"
#endif
Expand Down Expand Up @@ -1245,7 +1245,8 @@ int BrowserMainLoop::BrowserThreadsStarted() {
}

#if defined(OS_LINUX) && defined(USE_UDEV)
device_monitor_linux_.reset(new DeviceMonitorLinux());
device_monitor_linux_.reset(
new media::DeviceMonitorLinux(io_thread_->task_runner()));
#elif defined(OS_MACOSX)
device_monitor_mac_.reset(new DeviceMonitorMac());
#endif
Expand Down
9 changes: 5 additions & 4 deletions content/browser/browser_main_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class ScopedIPCSupport;

namespace media {
class AudioManager;
#if defined(OS_LINUX) && defined(USE_UDEV)
class DeviceMonitorLinux;
#endif
class UserInputMonitor;
namespace midi {
class MidiManager;
Expand Down Expand Up @@ -63,8 +66,6 @@ struct MainFunctionParams;

#if defined(OS_ANDROID)
class ScreenOrientationDelegate;
#elif defined(OS_LINUX)
class DeviceMonitorLinux;
#elif defined(OS_MACOSX)
class DeviceMonitorMac;
#elif defined(OS_WIN)
Expand Down Expand Up @@ -249,8 +250,8 @@ class CONTENT_EXPORT BrowserMainLoop {

scoped_ptr<media::midi::MidiManager> midi_manager_;

#if defined(USE_UDEV)
scoped_ptr<DeviceMonitorLinux> device_monitor_linux_;
#if defined(OS_LINUX) && defined(USE_UDEV)
scoped_ptr<media::DeviceMonitorLinux> device_monitor_linux_;
#elif defined(OS_MACOSX) && !defined(OS_IOS)
scoped_ptr<DeviceMonitorMac> device_monitor_mac_;
#endif
Expand Down
44 changes: 0 additions & 44 deletions content/browser/device_monitor_udev.h

This file was deleted.

14 changes: 7 additions & 7 deletions content/browser/gamepad/gamepad_platform_data_fetcher_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "content/browser/udev_linux.h"
#include "device/udev_linux/scoped_udev.h"
#include "device/udev_linux/udev_linux.h"

namespace {

Expand Down Expand Up @@ -77,12 +77,12 @@ GamepadPlatformDataFetcherLinux::GamepadPlatformDataFetcherLinux() {
pad_state_[i].button_mask = 0;
}

std::vector<UdevLinux::UdevMonitorFilter> filters;
filters.push_back(UdevLinux::UdevMonitorFilter(kInputSubsystem, NULL));
udev_.reset(
new UdevLinux(filters,
base::Bind(&GamepadPlatformDataFetcherLinux::RefreshDevice,
base::Unretained(this))));
std::vector<device::UdevLinux::UdevMonitorFilter> filters;
filters.push_back(
device::UdevLinux::UdevMonitorFilter(kInputSubsystem, NULL));
udev_.reset(new device::UdevLinux(
filters, base::Bind(&GamepadPlatformDataFetcherLinux::RefreshDevice,
base::Unretained(this))));

EnumerateDevices();
}
Expand Down
8 changes: 5 additions & 3 deletions content/browser/gamepad/gamepad_platform_data_fetcher_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ extern "C" {
struct udev_device;
}

namespace content {

namespace device {
class UdevLinux;
}

namespace content {

class GamepadPlatformDataFetcherLinux : public GamepadDataFetcher {
public:
Expand All @@ -39,7 +41,7 @@ class GamepadPlatformDataFetcherLinux : public GamepadDataFetcher {
// File descriptor for the /dev/input/js* devices. -1 if not in use.
int device_fd_[blink::WebGamepads::itemsLengthCap];

scoped_ptr<UdevLinux> udev_;
scoped_ptr<device::UdevLinux> udev_;

DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherLinux);
};
Expand Down
20 changes: 6 additions & 14 deletions content/content_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@
'browser/android/devtools_auth.cc',
'browser/android/in_process_surface_texture_manager.cc',
'browser/android/in_process_surface_texture_manager.h',
'public/browser/android/download_controller_android.h',
'browser/android/url_request_content_job.cc',
'browser/android/url_request_content_job.h',
'browser/appcache/appcache.cc',
Expand Down Expand Up @@ -508,8 +507,6 @@
'browser/cocoa/system_hotkey_map.mm',
'browser/device_monitor_mac.h',
'browser/device_monitor_mac.mm',
'browser/device_monitor_udev.cc',
'browser/device_monitor_udev.h',
'browser/device_sensors/ambient_light_mac.cc',
'browser/device_sensors/ambient_light_mac.h',
'browser/device_sensors/data_fetcher_shared_memory.h',
Expand Down Expand Up @@ -555,9 +552,9 @@
'browser/devtools/forwarding_agent_host.h',
'browser/devtools/protocol/color_picker.cc',
'browser/devtools/protocol/color_picker.h',
'browser/devtools/protocol/devtools_protocol_delegate.h',
'browser/devtools/protocol/devtools_protocol_client.cc',
'browser/devtools/protocol/devtools_protocol_client.h',
'browser/devtools/protocol/devtools_protocol_delegate.h',
'browser/devtools/protocol/dom_handler.cc',
'browser/devtools/protocol/dom_handler.h',
'browser/devtools/protocol/emulation_handler.cc',
Expand Down Expand Up @@ -750,8 +747,8 @@
'browser/frame_host/render_widget_host_view_guest.cc',
'browser/frame_host/render_widget_host_view_guest.h',
'browser/gamepad/gamepad_consumer.h',
'browser/gamepad/gamepad_data_fetcher.h',
'browser/gamepad/gamepad_data_fetcher.cc',
'browser/gamepad/gamepad_data_fetcher.h',
'browser/gamepad/gamepad_platform_data_fetcher.h',
'browser/gamepad/gamepad_platform_data_fetcher_android.cc',
'browser/gamepad/gamepad_platform_data_fetcher_android.h',
Expand Down Expand Up @@ -1197,12 +1194,12 @@
'browser/renderer_host/input/synthetic_smooth_scroll_gesture.h',
'browser/renderer_host/input/synthetic_tap_gesture.cc',
'browser/renderer_host/input/synthetic_tap_gesture.h',
'browser/renderer_host/input/synthetic_touch_pointer.cc',
'browser/renderer_host/input/synthetic_touch_pointer.h',
'browser/renderer_host/input/synthetic_touchpad_pinch_gesture.cc',
'browser/renderer_host/input/synthetic_touchpad_pinch_gesture.h',
'browser/renderer_host/input/synthetic_touchscreen_pinch_gesture.cc',
'browser/renderer_host/input/synthetic_touchscreen_pinch_gesture.h',
'browser/renderer_host/input/synthetic_touch_pointer.cc',
'browser/renderer_host/input/synthetic_touch_pointer.h',
'browser/renderer_host/input/tap_suppression_controller.cc',
'browser/renderer_host/input/tap_suppression_controller.h',
'browser/renderer_host/input/tap_suppression_controller_client.h',
Expand Down Expand Up @@ -1522,8 +1519,6 @@
'browser/tracing/tracing_controller_impl_data_sinks.cc',
'browser/tracing/tracing_ui.cc',
'browser/tracing/tracing_ui.h',
'browser/udev_linux.cc',
'browser/udev_linux.h',
'browser/user_metrics.cc',
'browser/utility_process_host_impl.cc',
'browser/utility_process_host_impl.h',
Expand Down Expand Up @@ -1575,8 +1570,8 @@
'browser/webui/web_ui_impl.cc',
'browser/webui/web_ui_impl.h',
'browser/webui/web_ui_message_handler.cc',
'browser/zygote_host/zygote_communication_linux.h',
'browser/zygote_host/zygote_communication_linux.cc',
'browser/zygote_host/zygote_communication_linux.h',
'browser/zygote_host/zygote_handle_linux.cc',
'browser/zygote_host/zygote_host_impl_linux.cc',
'browser/zygote_host/zygote_host_impl_linux.h',
Expand Down Expand Up @@ -2026,14 +2021,11 @@
['use_udev == 1', {
'dependencies': [
'../device/udev_linux/udev.gyp:udev_linux',
'../media/media.gyp:media',
],
}, {
'sources!': [
'browser/device_monitor_udev.cc',
'browser/device_monitor_udev.h',
'browser/gamepad/gamepad_platform_data_fetcher_linux.cc',
'browser/udev_linux.cc',
'browser/udev_linux.h',
],
}],
['OS=="linux" and use_aura==1', {
Expand Down
2 changes: 2 additions & 0 deletions device/udev_linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if (use_udev) {
"udev0_loader.h",
"udev1_loader.cc",
"udev1_loader.h",
"udev_linux.cc",
"udev_linux.h",
"udev_loader.cc",
"udev_loader.h",
]
Expand Down
2 changes: 2 additions & 0 deletions device/udev_linux/udev.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
'udev0_loader.h',
'udev1_loader.cc',
'udev1_loader.h',
'udev_linux.cc',
'udev_linux.h',
'udev_loader.cc',
'udev_loader.h',
],
Expand Down
32 changes: 14 additions & 18 deletions content/browser/udev_linux.cc → device/udev_linux/udev_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/udev_linux.h"
#include "device/udev_linux/udev_linux.h"

#include <stddef.h>

#include "base/message_loop/message_loop.h"

namespace content {
namespace device {

UdevLinux::UdevLinux(const std::vector<UdevMonitorFilter>& filters,
const UdevNotificationCallback& callback)
: udev_(device::udev_new()),
monitor_(device::udev_monitor_new_from_netlink(udev_.get(), "udev")),
: udev_(udev_new()),
monitor_(udev_monitor_new_from_netlink(udev_.get(), "udev")),
monitor_fd_(-1),
callback_(callback) {
CHECK(udev_);
CHECK(monitor_);
CHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type());

for (size_t i = 0; i < filters.size(); ++i) {
int ret = device::udev_monitor_filter_add_match_subsystem_devtype(
monitor_.get(), filters[i].subsystem, filters[i].devtype);
for (const UdevMonitorFilter& filter : filters) {
const int ret = udev_monitor_filter_add_match_subsystem_devtype(
monitor_.get(), filter.subsystem, filter.devtype);
CHECK_EQ(0, ret);
}

int ret = device::udev_monitor_enable_receiving(monitor_.get());
const int ret = udev_monitor_enable_receiving(monitor_.get());
CHECK_EQ(0, ret);
monitor_fd_ = device::udev_monitor_get_fd(monitor_.get());
monitor_fd_ = udev_monitor_get_fd(monitor_.get());
CHECK_GE(monitor_fd_, 0);

bool success = base::MessageLoopForIO::current()->WatchFileDescriptor(
monitor_fd_,
true,
base::MessageLoopForIO::WATCH_READ,
&monitor_watcher_,
monitor_fd_, true, base::MessageLoopForIO::WATCH_READ, &monitor_watcher_,
this);
CHECK(success);
}
Expand All @@ -52,15 +50,13 @@ void UdevLinux::OnFileCanReadWithoutBlocking(int fd) {
// change state. udev_monitor_receive_device() will return a device object
// representing the device which changed and what type of change occured.
DCHECK_EQ(monitor_fd_, fd);
device::ScopedUdevDevicePtr dev(
device::udev_monitor_receive_device(monitor_.get()));
ScopedUdevDevicePtr dev(udev_monitor_receive_device(monitor_.get()));
if (!dev)
return;

callback_.Run(dev.get());
}

void UdevLinux::OnFileCanWriteWithoutBlocking(int fd) {
}
void UdevLinux::OnFileCanWriteWithoutBlocking(int fd) {}

} // namespace content
} // namespace device
Loading

0 comments on commit 9d20636

Please sign in to comment.