| 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..48a457a5b07fc710e351f6a551dc16b3321486bf
|
| --- /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_);
|
| + DCHECK(!interceptor_);
|
| + DCHECK(interceptor);
|
| + interceptor_ = std::move(interceptor);
|
| +}
|
| +
|
| +KeyEventInterceptor* KeyboardLockHost::interceptor() {
|
| + 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
|
|
|