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

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

Issue 2815023002: [System-Keyboard-Lock] Add KeyboardLockHost and KeyEventInterceptor (Closed)
Patch Set: Created 3 years, 8 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_KEYBOARD_LOCK_HOST_H_
6 #define COMPONENTS_KEYBOARD_LOCK_KEYBOARD_LOCK_HOST_H_
7
8 #include <memory>
9
10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
13 #include "components/keyboard_lock/key_event_interceptor.h"
14
15 namespace base {
16 template <typename T>
17 struct DefaultSingletonTraits;
18 } // namespace base
19
20 namespace keyboard_lock {
21
22 class KeyEventInterceptorInstaller;
23
24 FORWARD_DECLARE_TEST(KeyboardLockHostTest, KeyEventInterceptorInstallationTest);
25
26 class KeyboardLockHost final {
27 public:
28 static KeyboardLockHost* GetInstance();
29
30 ~KeyboardLockHost();
31
32 // May return nullptr if not interceptor has been installed. This function
33 // never returns a destroyed object: only one KeyEventInterceptor installation
34 // is allowed during the lifetime of the process.
35 KeyEventInterceptor* interceptor() const;
dtapuska 2017/04/18 13:43:17 Returning a non-const ptr from a const object is w
Hzj_jie 2017/04/19 00:46:26 Done.
36
37 std::unique_ptr<KeyEventInterceptor::Retriever> GetInterceptorRetriever();
38
39 private:
40 // Allows KeyEventInterceptorInstaller to access SetKeyEventInterceptor().
41 friend class KeyEventInterceptorInstaller;
42
43 // Allows Singleton to create a instance of KeyboardLockHost.
44 friend struct base::DefaultSingletonTraits<KeyboardLockHost>;
45
46 // Allows test cases to create a new instance of KeyboardLockHost.
47 FRIEND_TEST_ALL_PREFIXES(KeyboardLockHostTest,
48 KeyEventInterceptorInstallationTest);
49
50 KeyboardLockHost();
51
52 void SetKeyEventInterceptor(std::unique_ptr<KeyEventInterceptor> interceptor);
53
54 // GUARDED_BY(lock_)
55 std::unique_ptr<KeyEventInterceptor> interceptor_;
56
57 // This lock only guards |interceptor_|, other function calls should be
58 // forwarded to UI thread.
59 mutable base::Lock lock_;
60
61 DISALLOW_COPY_AND_ASSIGN(KeyboardLockHost);
62 };
63
64 } // namespace keyboard_lock
65
66 #endif // COMPONENTS_KEYBOARD_LOCK_KEYBOARD_LOCK_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698