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

Unified Diff: components/keyboard_lock/active_key_event_filter_registrar.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
Index: components/keyboard_lock/active_key_event_filter_registrar.cc
diff --git a/components/keyboard_lock/active_key_event_filter_registrar.cc b/components/keyboard_lock/active_key_event_filter_registrar.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45a981d3760825ecfffa87de2912e68e2473366a
--- /dev/null
+++ b/components/keyboard_lock/active_key_event_filter_registrar.cc
@@ -0,0 +1,53 @@
+// 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/active_key_event_filter_registrar.h"
+
+#include <utility>
+
+#include "components/keyboard_lock/active_key_event_filter_tracker.h"
+
+namespace keyboard_lock {
+
+ActiveKeyEventFilterRegistrar::ActiveKeyEventFilterRegistrar(
+ ActiveKeyEventFilterTracker* tracker,
+ std::unique_ptr<KeyHookActivator> key_hook,
+ KeyEventFilter* filter)
+ : tracker_(tracker),
+ key_hook_(std::move(key_hook)),
+ filter_(filter) {
+ DCHECK(tracker_);
+ DCHECK(key_hook_);
+ DCHECK(filter_);
+}
+
+ActiveKeyEventFilterRegistrar::~ActiveKeyEventFilterRegistrar() {
+ tracker_->erase(filter_);
+}
+
+void ActiveKeyEventFilterRegistrar::RegisterKey(
+ const std::vector<ui::KeyboardCode>& codes,
+ base::Callback<void(bool)> on_result) {
+ key_hook_->RegisterKey(codes, std::move(on_result));
+}
+
+void ActiveKeyEventFilterRegistrar::UnregisterKey(
+ const std::vector<ui::KeyboardCode>& codes,
+ base::Callback<void(bool)> on_result) {
+ key_hook_->RegisterKey(codes, std::move(on_result));
+}
+
+void ActiveKeyEventFilterRegistrar::Activate(
+ base::Callback<void(bool)> on_result) {
+ key_hook_->Activate(std::move(on_result));
+ tracker_->set(filter_);
+}
+
+void ActiveKeyEventFilterRegistrar::Deactivate(
+ base::Callback<void(bool)> on_result) {
+ key_hook_->Deactivate(std::move(on_result));
+ tracker_->erase(filter_);
+}
+
+} // namespace keyboard_lock

Powered by Google App Engine
This is Rietveld 408576698