| 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.
|
| + KeyEventInterceptor* interceptor();
|
| +
|
| + 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_
|
|
|