Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/keyboard_lock/keyboard_lock_host.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/singleton.h" | |
| 11 | |
| 12 namespace keyboard_lock { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 class HostKeyEventInterceptorRetriever : public KeyEventInterceptor::Retriever { | |
| 17 public: | |
| 18 HostKeyEventInterceptorRetriever() = default; | |
| 19 ~HostKeyEventInterceptorRetriever() override = default; | |
| 20 | |
| 21 KeyEventInterceptor* Get() override; | |
| 22 }; | |
| 23 | |
| 24 KeyEventInterceptor* HostKeyEventInterceptorRetriever::Get() { | |
| 25 return KeyboardLockHost::GetInstance()->interceptor(); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 KeyboardLockHost::KeyboardLockHost() = default; | |
| 31 KeyboardLockHost::~KeyboardLockHost() = default; | |
| 32 | |
| 33 // static | |
| 34 KeyboardLockHost* KeyboardLockHost::GetInstance() { | |
| 35 return base::Singleton<KeyboardLockHost, | |
| 36 base::LeakySingletonTraits<KeyboardLockHost>>::get(); | |
| 37 } | |
| 38 | |
| 39 void KeyboardLockHost::SetKeyEventInterceptor( | |
| 40 std::unique_ptr<KeyEventInterceptor> interceptor) { | |
| 41 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
| |
| 42 DCHECK(!interceptor_); | |
| 43 DCHECK(interceptor); | |
| 44 interceptor_ = std::move(interceptor); | |
| 45 } | |
| 46 | |
| 47 KeyEventInterceptor* KeyboardLockHost::interceptor() const { | |
| 48 base::AutoLock lock(lock_); | |
| 49 return interceptor_.get(); | |
| 50 } | |
| 51 | |
| 52 std::unique_ptr<KeyEventInterceptor::Retriever> | |
| 53 KeyboardLockHost::GetInterceptorRetriever() { | |
| 54 return std::unique_ptr<KeyEventInterceptor::Retriever>( | |
| 55 new HostKeyEventInterceptorRetriever()); | |
| 56 } | |
| 57 | |
| 58 } // namespace keyboard_lock | |
| OLD | NEW |