Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1394)

Side by Side Diff: components/keyboard_lock/key_hook_thread_wrapper.h

Issue 2879033002: Keyboard Lock Host implementation
Patch Set: Remove useless files Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #ifndef COMPONENTS_KEYBOARD_LOCK_KEY_HOOK_THREAD_WRAPPER_H_
6 #define COMPONENTS_KEYBOARD_LOCK_KEY_HOOK_THREAD_WRAPPER_H_
7
8 #include <memory>
9
10 #include "base/synchronization/lock.h"
11 #include "components/keyboard_lock/key_event_filter.h"
12 #include "components/keyboard_lock/key_hook_activator.h"
13
14 namespace keyboard_lock {
15
16 class KeyHookStateKeeper;
17
18 // An implementation of both KeyHookActivator and KeyEventFilter to ensure all
19 // the public functions are not called parallely from multiple threads.
20 class KeyHookThreadWrapper final
21 : public KeyEventFilter,
22 public KeyHookActivator {
23 public:
24 // Takes ownership of both objects.
25 KeyHookThreadWrapper(std::unique_ptr<KeyEventFilter> filter,
26 std::unique_ptr<KeyHookActivator> key_hook);
27 // A shortcut to create a KeyHookThreadWrapper from a KeyHookStateKeeper,
28 // which is the typical usage of this class.
29 explicit KeyHookThreadWrapper(
30 std::unique_ptr<KeyHookStateKeeper> state_keeper);
31 ~KeyHookThreadWrapper() override;
32
33 // KeyEventFilter implementations.
34 bool OnKeyDown(ui::KeyboardCode code, int flags) override;
35 bool OnKeyUp(ui::KeyboardCode code, int flags) override;
36
37 // KeyHookActivator implementations.
38 void RegisterKey(const std::vector<ui::KeyboardCode>& codes,
39 base::Callback<void(bool)> on_result) override;
40 void UnregisterKey(const std::vector<ui::KeyboardCode>& codes,
41 base::Callback<void(bool)> on_result) override;
42 void Activate(base::Callback<void(bool)> on_result) override;
43 void Deactivate(base::Callback<void(bool)> on_result) override;
44
45 private:
46 const std::unique_ptr<KeyEventFilter> filter_;
47 const std::unique_ptr<KeyHookActivator> key_hook_;
48 base::Lock lock_;
49 };
50
51 } // namespace keyboard_lock
52
53 #endif // COMPONENTS_KEYBOARD_LOCK_KEY_HOOK_THREAD_WRAPPER_H_
OLDNEW
« no previous file with comments | « components/keyboard_lock/key_hook_state_keeper_unittest.cc ('k') | components/keyboard_lock/key_hook_thread_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698