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

Unified Diff: components/keyboard_lock/keyboard_lock_host.cc

Issue 2815023002: [System-Keyboard-Lock] Add KeyboardLockHost and KeyEventInterceptor (Closed)
Patch Set: Created 3 years, 8 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/keyboard_lock_host.cc
diff --git a/components/keyboard_lock/keyboard_lock_host.cc b/components/keyboard_lock/keyboard_lock_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a5404146640e302bd7c2924ef387d9881c76632
--- /dev/null
+++ b/components/keyboard_lock/keyboard_lock_host.cc
@@ -0,0 +1,58 @@
+// 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/keyboard_lock_host.h"
+
+#include <utility>
+
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+
+namespace keyboard_lock {
+
+namespace {
+
+class HostKeyEventInterceptorRetriever : public KeyEventInterceptor::Retriever {
+ public:
+ HostKeyEventInterceptorRetriever() = default;
+ ~HostKeyEventInterceptorRetriever() override = default;
+
+ KeyEventInterceptor* Get() override;
+};
+
+KeyEventInterceptor* HostKeyEventInterceptorRetriever::Get() {
+ return KeyboardLockHost::GetInstance()->interceptor();
+}
+
+} // namespace
+
+KeyboardLockHost::KeyboardLockHost() = default;
+KeyboardLockHost::~KeyboardLockHost() = default;
+
+// static
+KeyboardLockHost* KeyboardLockHost::GetInstance() {
+ return base::Singleton<KeyboardLockHost,
+ base::LeakySingletonTraits<KeyboardLockHost>>::get();
+}
+
+void KeyboardLockHost::SetKeyEventInterceptor(
+ std::unique_ptr<KeyEventInterceptor> interceptor) {
+ base::AutoLock lock(lock_);
dtapuska 2017/04/18 13:43:17 Are there multiple threads running around that you
Hzj_jie 2017/04/19 00:46:26 Multiple threads are required: the interceptor wil
dtapuska 2017/04/21 14:48:33 So ultimately is this just not a construction prob
Hzj_jie 2017/04/21 21:13:09 Sorry, it looks like I do not follow. KeyboardLock
+ DCHECK(!interceptor_);
+ DCHECK(interceptor);
+ interceptor_ = std::move(interceptor);
+}
+
+KeyEventInterceptor* KeyboardLockHost::interceptor() const {
+ base::AutoLock lock(lock_);
+ return interceptor_.get();
+}
+
+std::unique_ptr<KeyEventInterceptor::Retriever>
+KeyboardLockHost::GetInterceptorRetriever() {
+ return std::unique_ptr<KeyEventInterceptor::Retriever>(
+ new HostKeyEventInterceptorRetriever());
+}
+
+} // namespace keyboard_lock

Powered by Google App Engine
This is Rietveld 408576698