Index: components/keyboard_lock/active_key_event_filter_tracker.h |
diff --git a/components/keyboard_lock/active_key_event_filter_tracker.h b/components/keyboard_lock/active_key_event_filter_tracker.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..edc167bce7577fffc9a83cb0647b87411b07d1fc |
--- /dev/null |
+++ b/components/keyboard_lock/active_key_event_filter_tracker.h |
@@ -0,0 +1,35 @@ |
+// 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. |
+ |
+#ifndef COMPONENTS_KEYBOARD_LOCK_ACTIVE_KEY_EVENT_FILTER_TRACKER_H_ |
+#define COMPONENTS_KEYBOARD_LOCK_ACTIVE_KEY_EVENT_FILTER_TRACKER_H_ |
+ |
+#include "base/threading/thread_checker.h" |
+ |
+namespace keyboard_lock { |
+ |
+class KeyEventFilter; |
+ |
+// Tracks the active KeyEventFilter. |
+// All public functions must be executed in one thread. |
+class ActiveKeyEventFilterTracker final { |
+ public: |
+ ActiveKeyEventFilterTracker(); |
+ ~ActiveKeyEventFilterTracker(); |
+ |
+ void set(KeyEventFilter* filter); |
+ // If |filter| == |filter_|, set |filter_| to nullptr. It ensures no matter |
+ // whether LostFocus or GotFocus is fired first, we can always get the latest |
+ // active filter. |
+ void erase(const KeyEventFilter* filter); |
+ KeyEventFilter* get() const; |
+ |
+ private: |
+ KeyEventFilter* filter_ = nullptr; |
+ base::ThreadChecker thread_checker_; |
+}; |
+ |
+} // namespace keyboard_lock |
+ |
+#endif // COMPONENTS_KEYBOARD_LOCK_ACTIVE_KEY_EVENT_FILTER_TRACKER_H_ |