| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IdleSpellCheckCallback_h | 5 #ifndef IdleSpellCheckCallback_h |
| 6 #define IdleSpellCheckCallback_h | 6 #define IdleSpellCheckCallback_h |
| 7 | 7 |
| 8 #include "core/dom/IdleRequestCallback.h" | 8 #include "core/dom/IdleRequestCallback.h" |
| 9 #include "core/frame/LocalFrame.h" | |
| 10 #include "platform/Timer.h" | 9 #include "platform/Timer.h" |
| 11 | 10 |
| 12 namespace blink { | 11 namespace blink { |
| 13 | 12 |
| 13 class LocalFrame; |
| 14 class SpellCheckRequester; |
| 15 |
| 14 // Main class for the implementation of idle time spell checker. | 16 // Main class for the implementation of idle time spell checker. |
| 15 class IdleSpellCheckCallback final : public IdleRequestCallback { | 17 class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback { |
| 16 public: | 18 public: |
| 17 static IdleSpellCheckCallback* create(LocalFrame&); | 19 static IdleSpellCheckCallback* create(LocalFrame&); |
| 18 ~IdleSpellCheckCallback() override; | 20 ~IdleSpellCheckCallback() override; |
| 19 | 21 |
| 20 // Transit to HotModeRequested, if possible. Called by operations that need | 22 // Transit to HotModeRequested, if possible. Called by operations that need |
| 21 // spell checker to follow up. | 23 // spell checker to follow up. |
| 22 // TODO(xiaochengh): Add proper call sites. | 24 // TODO(xiaochengh): Add proper call sites. |
| 23 void setNeedsHotModeInvocation(); | 25 void setNeedsHotModeInvocation(); |
| 24 | 26 |
| 25 // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests | 27 // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests |
| 26 // cold mode invocation if no critical operation occurs before timer firing. | 28 // cold mode invocation if no critical operation occurs before timer firing. |
| 27 // TODO(xiaochengh): Add proper call sites. | 29 // TODO(xiaochengh): Add proper call sites. |
| 28 void setNeedsColdModeInvocation(); | 30 void setNeedsColdModeInvocation(); |
| 29 | 31 |
| 30 // Cleans everything up and makes the callback inactive. Should be called when | 32 // Cleans everything up and makes the callback inactive. Should be called when |
| 31 // document is detached or spellchecking is globally disabled. | 33 // document is detached or spellchecking is globally disabled. |
| 32 // TODO(xiaochengh): Add proper call sites. | 34 // TODO(xiaochengh): Add proper call sites. |
| 33 void deactivate(); | 35 void deactivate(); |
| 34 | 36 |
| 37 // Exposed for testing only. |
| 38 SpellCheckRequester& spellCheckRequester() const; |
| 39 |
| 40 // The leak detector will report leaks should queued requests be posted |
| 41 // while it GCs repeatedly, as the requests keep their associated element |
| 42 // alive. |
| 43 // |
| 44 // Hence allow the leak detector to effectively stop the spell checker to |
| 45 // ensure leak reporting stability. |
| 46 void prepareForLeakDetection(); |
| 47 |
| 35 DECLARE_VIRTUAL_TRACE(); | 48 DECLARE_VIRTUAL_TRACE(); |
| 36 | 49 |
| 37 private: | 50 private: |
| 38 explicit IdleSpellCheckCallback(LocalFrame&); | 51 explicit IdleSpellCheckCallback(LocalFrame&); |
| 39 void handleEvent(IdleDeadline*) override; | 52 void handleEvent(IdleDeadline*) override; |
| 40 | 53 |
| 41 LocalFrame& frame() const { return *m_frame; } | 54 LocalFrame& frame() const { return *m_frame; } |
| 42 | 55 |
| 43 enum class State { | 56 enum class State { |
| 44 kInactive, | 57 kInactive, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 State m_state; | 79 State m_state; |
| 67 const Member<LocalFrame> m_frame; | 80 const Member<LocalFrame> m_frame; |
| 68 | 81 |
| 69 // TODO(xiaochengh): assign the timer to some proper task runner. | 82 // TODO(xiaochengh): assign the timer to some proper task runner. |
| 70 Timer<IdleSpellCheckCallback> m_coldModeTimer; | 83 Timer<IdleSpellCheckCallback> m_coldModeTimer; |
| 71 }; | 84 }; |
| 72 | 85 |
| 73 } // namespace blink | 86 } // namespace blink |
| 74 | 87 |
| 75 #endif // IdleSpellCheckCallback_h | 88 #endif // IdleSpellCheckCallback_h |
| OLD | NEW |