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

Unified Diff: components/keyboard_lock/key_event_filter_thread_proxy.cc

Issue 2879033002: Keyboard Lock Host implementation
Patch Set: Remove useless files Created 3 years, 4 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 | « components/keyboard_lock/key_event_filter_thread_proxy.h ('k') | components/keyboard_lock/key_hook.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/keyboard_lock/key_event_filter_thread_proxy.cc
diff --git a/components/keyboard_lock/key_event_filter_thread_proxy.cc b/components/keyboard_lock/key_event_filter_thread_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b1152422241aa9939577c8dc2c61576b0181db22
--- /dev/null
+++ b/components/keyboard_lock/key_event_filter_thread_proxy.cc
@@ -0,0 +1,52 @@
+// Copyright 2017 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.
+
+#include "components/keyboard_lock/key_event_filter_thread_proxy.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/single_thread_task_runner.h"
+
+namespace keyboard_lock {
+
+KeyEventFilterThreadProxy::KeyEventFilterThreadProxy(
+ scoped_refptr<base::SingleThreadTaskRunner> runner,
+ std::unique_ptr<KeyEventFilter> filter)
+ : runner_(std::move(runner)),
+ filter_(std::move(filter)) {
+ DCHECK(runner_);
+ DCHECK(filter_);
+}
+
+KeyEventFilterThreadProxy::~KeyEventFilterThreadProxy() {
+ runner_->DeleteSoon(FROM_HERE,
+ (*const_cast<std::unique_ptr<KeyEventFilter>*>(&filter_)).release());
+}
+
+bool KeyEventFilterThreadProxy::OnKeyDown(ui::KeyboardCode code, int flags) {
+ runner_->PostTask(FROM_HERE, base::Bind(
+ [](KeyEventFilter* filter, ui::KeyboardCode code, int flags) {
+ filter->OnKeyDown(code, flags);
+ },
+ base::Unretained(filter_.get()),
+ code,
+ flags));
+ return true;
+}
+
+bool KeyEventFilterThreadProxy::OnKeyUp(ui::KeyboardCode code, int flags) {
+ runner_->PostTask(FROM_HERE, base::Bind(
+ [](KeyEventFilter* filter, ui::KeyboardCode code, int flags) {
+ filter->OnKeyUp(code, flags);
+ },
+ base::Unretained(filter_.get()),
+ code,
+ flags));
+ return true;
+}
+
+} // namespace keyboard_lock
« no previous file with comments | « components/keyboard_lock/key_event_filter_thread_proxy.h ('k') | components/keyboard_lock/key_hook.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698