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 <utility> |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/logging.h" |
| 10 #include "components/keyboard_lock/key_hook_activator_thread_proxy.h" |
| 11 |
| 12 namespace keyboard_lock { |
| 13 |
| 14 KeyHookActivatorThreadProxy::KeyHookActivatorThreadProxy( |
| 15 KeyHookActivator* const key_hook, |
| 16 scoped_refptr<base::SingleThreadTaskRunner> runner) |
| 17 : key_hook_(key_hook), |
| 18 runner_(std::move(runner)) { |
| 19 DCHECK(key_hook_); |
| 20 DCHECK(runner_); |
| 21 } |
| 22 |
| 23 KeyHookActivatorThreadProxy::~KeyHookActivatorThreadProxy() = default; |
| 24 |
| 25 void KeyHookActivatorThreadProxy::RegisterKey( |
| 26 const std::vector<ui::KeyboardCode>& codes, |
| 27 base::Callback<void(bool)> on_result) { |
| 28 runner_->PostTask(FROM_HERE, |
| 29 base::Bind([](KeyHookActivator* const key_hook, |
| 30 const std::vector<ui::KeyboardCode>& codes, |
| 31 base::Callback<void(bool)> on_result) { |
| 32 key_hook->RegisterKey(codes, std::move(on_result)); |
| 33 }, |
| 34 base::Unretained(key_hook_), |
| 35 codes, |
| 36 std::move(on_result))); |
| 37 } |
| 38 |
| 39 void KeyHookActivatorThreadProxy::UnregisterKey( |
| 40 const std::vector<ui::KeyboardCode>& codes, |
| 41 base::Callback<void(bool)> on_result) { |
| 42 runner_->PostTask(FROM_HERE, |
| 43 base::Bind([](KeyHookActivator* const key_hook, |
| 44 const std::vector<ui::KeyboardCode>& codes, |
| 45 base::Callback<void(bool)> on_result) { |
| 46 key_hook->UnregisterKey(codes, std::move(on_result)); |
| 47 }, |
| 48 base::Unretained(key_hook_), |
| 49 codes, |
| 50 std::move(on_result))); |
| 51 } |
| 52 |
| 53 void KeyHookActivatorThreadProxy::Activate( |
| 54 base::Callback<void(bool)> on_result) { |
| 55 runner_->PostTask(FROM_HERE, |
| 56 base::Bind([](KeyHookActivator* const key_hook, |
| 57 base::Callback<void(bool)> on_result) { |
| 58 key_hook->Activate(std::move(on_result)); |
| 59 }, |
| 60 base::Unretained(key_hook_), |
| 61 std::move(on_result))); |
| 62 } |
| 63 |
| 64 void KeyHookActivatorThreadProxy::Deactivate( |
| 65 base::Callback<void(bool)> on_result) { |
| 66 runner_->PostTask(FROM_HERE, |
| 67 base::Bind([](KeyHookActivator* const key_hook, |
| 68 base::Callback<void(bool)> on_result) { |
| 69 key_hook->Deactivate(std::move(on_result)); |
| 70 }, |
| 71 base::Unretained(key_hook_), |
| 72 std::move(on_result))); |
| 73 } |
| 74 |
| 75 } // namespace keyboard_lock |
OLD | NEW |