Chromium Code Reviews| 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..cd1092d6d86413f1843933955ae656454bd0a59b |
| --- /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. |
|
Wez
2017/04/28 00:22:45
How does a caller install a KeyEventInterceptor? T
Hzj_jie
2017/04/28 20:02:03
We cannot register and unregister over the lifetim
|
| + KeyEventInterceptor* interceptor(); |
| + |
| + std::unique_ptr<KeyEventInterceptor::Retriever> GetInterceptorRetriever(); |
|
Wez
2017/04/28 00:22:45
What does this method do?
Hzj_jie
2017/04/28 20:02:03
To reduce the dependency of the singleton object o
|
| + |
| + private: |
| + // Allows KeyEventInterceptorInstaller to access SetKeyEventInterceptor(). |
| + friend class KeyEventInterceptorInstaller; |
| + |
| + // Allows Singleton to create a instance of KeyboardLockHost. |
|
Wez
2017/04/28 00:22:44
Why do we want to use Singleton rather than creati
Hzj_jie
2017/04/28 20:02:03
Is there a preference? As long as they are leaking
|
| + 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_; |
|
Wez
2017/04/28 00:22:44
You have a simple-getter for |interceptor_|, above
Hzj_jie
2017/04/28 20:02:03
That's the reason setter can only be called once.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(KeyboardLockHost); |
| +}; |
| + |
| +} // namespace keyboard_lock |
| + |
| +#endif // COMPONENTS_KEYBOARD_LOCK_KEYBOARD_LOCK_HOST_H_ |