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

Unified Diff: components/keyboard_lock/keyboard_lock_host.h

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.h
diff --git a/components/keyboard_lock/keyboard_lock_host.h b/components/keyboard_lock/keyboard_lock_host.h
new file mode 100644
index 0000000000000000000000000000000000000000..4026da1006762858c168d2a1bef1ea32c7a8cae7
--- /dev/null
+++ b/components/keyboard_lock/keyboard_lock_host.h
@@ -0,0 +1,66 @@
+// 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.
+
+#ifndef COMPONENTS_KEYBOARD_LOCK_KEYBOARD_LOCK_HOST_H_
+#define COMPONENTS_KEYBOARD_LOCK_KEYBOARD_LOCK_HOST_H_
+
+#include <memory>
+
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/synchronization/lock.h"
+#include "components/keyboard_lock/key_event_interceptor.h"
+
+namespace base {
+template <typename T>
+struct DefaultSingletonTraits;
+} // namespace base
+
+namespace keyboard_lock {
+
+class KeyEventInterceptorInstaller;
+
+FORWARD_DECLARE_TEST(KeyboardLockHostTest, KeyEventInterceptorInstallationTest);
+
+class KeyboardLockHost final {
+ public:
+ static KeyboardLockHost* GetInstance();
+
+ ~KeyboardLockHost();
+
+ // May return nullptr if not interceptor has been installed. This function
+ // never returns a destroyed object: only one KeyEventInterceptor installation
+ // is allowed during the lifetime of the process.
+ KeyEventInterceptor* interceptor() const;
dtapuska 2017/04/18 13:43:17 Returning a non-const ptr from a const object is w
Hzj_jie 2017/04/19 00:46:26 Done.
+
+ std::unique_ptr<KeyEventInterceptor::Retriever> GetInterceptorRetriever();
+
+ private:
+ // Allows KeyEventInterceptorInstaller to access SetKeyEventInterceptor().
+ friend class KeyEventInterceptorInstaller;
+
+ // Allows Singleton to create a instance of KeyboardLockHost.
+ friend struct base::DefaultSingletonTraits<KeyboardLockHost>;
+
+ // Allows test cases to create a new instance of KeyboardLockHost.
+ FRIEND_TEST_ALL_PREFIXES(KeyboardLockHostTest,
+ KeyEventInterceptorInstallationTest);
+
+ KeyboardLockHost();
+
+ void SetKeyEventInterceptor(std::unique_ptr<KeyEventInterceptor> interceptor);
+
+ // GUARDED_BY(lock_)
+ std::unique_ptr<KeyEventInterceptor> interceptor_;
+
+ // This lock only guards |interceptor_|, other function calls should be
+ // forwarded to UI thread.
+ mutable base::Lock lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeyboardLockHost);
+};
+
+} // namespace keyboard_lock
+
+#endif // COMPONENTS_KEYBOARD_LOCK_KEYBOARD_LOCK_HOST_H_

Powered by Google App Engine
This is Rietveld 408576698