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

Unified Diff: media/base/user_input_monitor_win.cc

Issue 2577573002: Removes mouse listeners from UserInputMonitor. (Closed)
Patch Set: Fix win by removing std::move. Created 3 years, 11 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 | « media/base/user_input_monitor_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/user_input_monitor_win.cc
diff --git a/media/base/user_input_monitor_win.cc b/media/base/user_input_monitor_win.cc
index 12446013f74d3a344e6a65237beb14c1095b5ca7..5278e94584dc80fd3351529bfa93d4a683e0b564 100644
--- a/media/base/user_input_monitor_win.cc
+++ b/media/base/user_input_monitor_win.cc
@@ -26,9 +26,17 @@ namespace {
// From the HID Usage Tables specification.
const USHORT kGenericDesktopPage = 1;
-const USHORT kMouseUsage = 2;
const USHORT kKeyboardUsage = 6;
+std::unique_ptr<RAWINPUTDEVICE> GetRawInputDevices(HWND hwnd, DWORD flags) {
+ std::unique_ptr<RAWINPUTDEVICE> device(new RAWINPUTDEVICE());
+ device->dwFlags = flags;
+ device->usUsagePage = kGenericDesktopPage;
+ device->usUsage = kKeyboardUsage;
+ device->hwndTarget = hwnd;
+ return device;
+}
+
// This is the actual implementation of event monitoring. It's separated from
// UserInputMonitorWin since it needs to be deleted on the UI thread.
class UserInputMonitorWinCore
@@ -41,17 +49,15 @@ class UserInputMonitorWinCore
};
explicit UserInputMonitorWinCore(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
- const scoped_refptr<UserInputMonitor::MouseListenerList>&
- mouse_listeners);
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
~UserInputMonitorWinCore() override;
// DestructionObserver overrides.
void WillDestroyCurrentMessageLoop() override;
size_t GetKeyPressCount() const;
- void StartMonitor(EventBitMask type);
- void StopMonitor(EventBitMask type);
+ void StartMonitor();
+ void StopMonitor();
private:
// Handles WM_INPUT messages.
@@ -61,16 +67,12 @@ class UserInputMonitorWinCore
WPARAM wparam,
LPARAM lparam,
LRESULT* result);
- RAWINPUTDEVICE* GetRawInputDevices(EventBitMask event, DWORD flags);
// Task runner on which |window_| is created.
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
- scoped_refptr<base::ObserverListThreadSafe<
- UserInputMonitor::MouseEventListener>> mouse_listeners_;
// These members are only accessed on the UI thread.
std::unique_ptr<base::win::MessageWindow> window_;
- uint8_t events_monitored_;
KeyboardEventCounter counter_;
DISALLOW_COPY_AND_ASSIGN(UserInputMonitorWinCore);
@@ -89,8 +91,6 @@ class UserInputMonitorWin : public UserInputMonitor {
// Private UserInputMonitor overrides.
void StartKeyboardMonitoring() override;
void StopKeyboardMonitoring() override;
- void StartMouseMonitoring() override;
- void StopMouseMonitoring() override;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
UserInputMonitorWinCore* core_;
@@ -99,85 +99,68 @@ class UserInputMonitorWin : public UserInputMonitor {
};
UserInputMonitorWinCore::UserInputMonitorWinCore(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
- const scoped_refptr<UserInputMonitor::MouseListenerList>& mouse_listeners)
- : ui_task_runner_(ui_task_runner),
- mouse_listeners_(mouse_listeners),
- events_monitored_(0) {}
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
+ : ui_task_runner_(ui_task_runner) {}
UserInputMonitorWinCore::~UserInputMonitorWinCore() {
DCHECK(!window_);
- DCHECK(!events_monitored_);
}
void UserInputMonitorWinCore::WillDestroyCurrentMessageLoop() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- StopMonitor(MOUSE_EVENT_MASK);
- StopMonitor(KEYBOARD_EVENT_MASK);
+ StopMonitor();
}
size_t UserInputMonitorWinCore::GetKeyPressCount() const {
return counter_.GetKeyPressCount();
}
-void UserInputMonitorWinCore::StartMonitor(EventBitMask type) {
+void UserInputMonitorWinCore::StartMonitor() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- if (events_monitored_ & type)
+ if (window_)
return;
- if (type == KEYBOARD_EVENT_MASK)
- counter_.Reset();
-
- if (!window_) {
- window_.reset(new base::win::MessageWindow());
- if (!window_->Create(base::Bind(&UserInputMonitorWinCore::HandleMessage,
- base::Unretained(this)))) {
- PLOG(ERROR) << "Failed to create the raw input window";
- window_.reset();
- return;
- }
+ std::unique_ptr<base::win::MessageWindow> window =
+ base::MakeUnique<base::win::MessageWindow>();
+ if (!window->Create(base::Bind(&UserInputMonitorWinCore::HandleMessage,
+ base::Unretained(this)))) {
+ PLOG(ERROR) << "Failed to create the raw input window";
+ return;
}
- // Register to receive raw mouse and/or keyboard input.
+ // Register to receive raw keyboard input.
std::unique_ptr<RAWINPUTDEVICE> device(
- GetRawInputDevices(type, RIDEV_INPUTSINK));
+ GetRawInputDevices(window->hwnd(), RIDEV_INPUTSINK));
if (!RegisterRawInputDevices(device.get(), 1, sizeof(*device))) {
PLOG(ERROR) << "RegisterRawInputDevices() failed for RIDEV_INPUTSINK";
- window_.reset();
return;
}
+ window_ = std::move(window);
// Start observing message loop destruction if we start monitoring the first
// event.
- if (!events_monitored_)
- base::MessageLoop::current()->AddDestructionObserver(this);
-
- events_monitored_ |= type;
+ base::MessageLoop::current()->AddDestructionObserver(this);
}
-void UserInputMonitorWinCore::StopMonitor(EventBitMask type) {
+void UserInputMonitorWinCore::StopMonitor() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- if (!(events_monitored_ & type))
+ if (!window_)
return;
// Stop receiving raw input.
- DCHECK(window_);
std::unique_ptr<RAWINPUTDEVICE> device(
- GetRawInputDevices(type, RIDEV_REMOVE));
+ GetRawInputDevices(window_->hwnd(), RIDEV_REMOVE));
if (!RegisterRawInputDevices(device.get(), 1, sizeof(*device))) {
PLOG(INFO) << "RegisterRawInputDevices() failed for RIDEV_REMOVE";
}
- events_monitored_ &= ~type;
- if (events_monitored_ == 0) {
- window_.reset();
+ window_ = nullptr;
- // Stop observing message loop destruction if no event is being monitored.
- base::MessageLoop::current()->RemoveDestructionObserver(this);
- }
+ // Stop observing message loop destruction if no event is being monitored.
+ base::MessageLoop::current()->RemoveDestructionObserver(this);
}
LRESULT UserInputMonitorWinCore::OnInput(HRAWINPUT input_handle) {
@@ -205,17 +188,8 @@ LRESULT UserInputMonitorWinCore::OnInput(HRAWINPUT input_handle) {
DCHECK_EQ(size, result);
// Notify the observer about events generated locally.
- if (input->header.dwType == RIM_TYPEMOUSE && input->header.hDevice != NULL) {
- POINT position;
- if (!GetCursorPos(&position)) {
- position.x = 0;
- position.y = 0;
- }
- mouse_listeners_->Notify(
- FROM_HERE, &UserInputMonitor::MouseEventListener::OnMouseMoved,
- SkIPoint::Make(position.x, position.y));
- } else if (input->header.dwType == RIM_TYPEKEYBOARD &&
- input->header.hDevice != NULL) {
+ if (input->header.dwType == RIM_TYPEKEYBOARD &&
+ input->header.hDevice != NULL) {
ui::EventType event = (input->data.keyboard.Flags & RI_KEY_BREAK)
? ui::ET_KEY_RELEASED
: ui::ET_KEY_PRESSED;
@@ -243,26 +217,6 @@ bool UserInputMonitorWinCore::HandleMessage(UINT message,
}
}
-RAWINPUTDEVICE* UserInputMonitorWinCore::GetRawInputDevices(EventBitMask event,
- DWORD flags) {
- DCHECK(ui_task_runner_->BelongsToCurrentThread());
-
- std::unique_ptr<RAWINPUTDEVICE> device(new RAWINPUTDEVICE());
- if (event == MOUSE_EVENT_MASK) {
- device->dwFlags = flags;
- device->usUsagePage = kGenericDesktopPage;
- device->usUsage = kMouseUsage;
- device->hwndTarget = window_->hwnd();
- } else {
- DCHECK_EQ(KEYBOARD_EVENT_MASK, event);
- device->dwFlags = flags;
- device->usUsagePage = kGenericDesktopPage;
- device->usUsage = kKeyboardUsage;
- device->hwndTarget = window_->hwnd();
- }
- return device.release();
-}
-
//
// Implementation of UserInputMonitorWin.
//
@@ -270,7 +224,7 @@ RAWINPUTDEVICE* UserInputMonitorWinCore::GetRawInputDevices(EventBitMask event,
UserInputMonitorWin::UserInputMonitorWin(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
: ui_task_runner_(ui_task_runner),
- core_(new UserInputMonitorWinCore(ui_task_runner, mouse_listeners())) {}
+ core_(new UserInputMonitorWinCore(ui_task_runner)) {}
UserInputMonitorWin::~UserInputMonitorWin() {
if (!ui_task_runner_->DeleteSoon(FROM_HERE, core_))
@@ -284,33 +238,13 @@ size_t UserInputMonitorWin::GetKeyPressCount() const {
void UserInputMonitorWin::StartKeyboardMonitoring() {
ui_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StartMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::KEYBOARD_EVENT_MASK));
+ base::Bind(&UserInputMonitorWinCore::StartMonitor, core_->AsWeakPtr()));
}
void UserInputMonitorWin::StopKeyboardMonitoring() {
ui_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StopMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::KEYBOARD_EVENT_MASK));
-}
-
-void UserInputMonitorWin::StartMouseMonitoring() {
- ui_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StartMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::MOUSE_EVENT_MASK));
-}
-
-void UserInputMonitorWin::StopMouseMonitoring() {
- ui_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StopMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::MOUSE_EVENT_MASK));
+ base::Bind(&UserInputMonitorWinCore::StopMonitor, core_->AsWeakPtr()));
}
} // namespace
@@ -318,7 +252,7 @@ void UserInputMonitorWin::StopMouseMonitoring() {
std::unique_ptr<UserInputMonitor> UserInputMonitor::Create(
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) {
- return base::WrapUnique(new UserInputMonitorWin(ui_task_runner));
+ return base::MakeUnique<UserInputMonitorWin>(ui_task_runner);
}
} // namespace media
« no previous file with comments | « media/base/user_input_monitor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698