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

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h

Issue 2701983002: Implement complete lifecycle transition for IdleSpellCheckCallback (Closed)
Patch Set: Add lifecycle transition unit tests Created 3 years, 10 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
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/dom/SynchronousMutationObserver.h"
9 #include "platform/Timer.h" 10 #include "platform/Timer.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 class LocalFrame; 14 class LocalFrame;
14 class SpellCheckRequester; 15 class SpellCheckRequester;
15 16
16 // Main class for the implementation of idle time spell checker. 17 // Main class for the implementation of idle time spell checker.
17 class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback { 18 class CORE_EXPORT IdleSpellCheckCallback final
19 : public IdleRequestCallback,
20 public SynchronousMutationObserver {
21 DISALLOW_COPY_AND_ASSIGN(IdleSpellCheckCallback);
22 USING_GARBAGE_COLLECTED_MIXIN(IdleSpellCheckCallback);
23
18 public: 24 public:
19 static IdleSpellCheckCallback* create(LocalFrame&); 25 static IdleSpellCheckCallback* create(LocalFrame&);
20 ~IdleSpellCheckCallback() override; 26 ~IdleSpellCheckCallback() override;
21 27
28 enum class State {
29 kInactive,
30 kHotModeRequested,
31 kInHotModeInvocation,
32 kColdModeTimerStarted,
33 kColdModeRequested,
34 kInColdModeInvocation
35 };
36
37 State state() const { return m_state; }
38
22 // Transit to HotModeRequested, if possible. Called by operations that need 39 // Transit to HotModeRequested, if possible. Called by operations that need
23 // spell checker to follow up. 40 // spell checker to follow up.
24 // TODO(xiaochengh): Add proper call sites. 41 void setNeedsInvocation();
25 void setNeedsHotModeInvocation();
26
27 // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests
28 // cold mode invocation if no critical operation occurs before timer firing.
29 // TODO(xiaochengh): Add proper call sites.
30 void setNeedsColdModeInvocation();
31 42
32 // Cleans everything up and makes the callback inactive. Should be called when 43 // Cleans everything up and makes the callback inactive. Should be called when
33 // document is detached or spellchecking is globally disabled. 44 // document is detached or spellchecking is globally disabled.
34 // TODO(xiaochengh): Add proper call sites.
35 void deactivate(); 45 void deactivate();
36 46
47 void documentAttached(Document*);
48
37 // Exposed for testing only. 49 // Exposed for testing only.
38 SpellCheckRequester& spellCheckRequester() const; 50 SpellCheckRequester& spellCheckRequester() const;
51 void forceInvocationForTesting();
52 void setNeedsMoreColdModeInvocationForTesting() {
53 m_needsMoreColdModeInvocationForTesting = true;
54 }
55 void skipColdModeTimerForTesting();
56 int idleCallbackHandle() const { return m_idleCallbackHandle; }
39 57
40 // The leak detector will report leaks should queued requests be posted 58 // The leak detector will report leaks should queued requests be posted
41 // while it GCs repeatedly, as the requests keep their associated element 59 // while it GCs repeatedly, as the requests keep their associated element
42 // alive. 60 // alive.
43 // 61 //
44 // Hence allow the leak detector to effectively stop the spell checker to 62 // Hence allow the leak detector to effectively stop the spell checker to
45 // ensure leak reporting stability. 63 // ensure leak reporting stability.
46 void prepareForLeakDetection(); 64 void prepareForLeakDetection();
47 65
48 DECLARE_VIRTUAL_TRACE(); 66 DECLARE_VIRTUAL_TRACE();
49 67
50 private: 68 private:
51 explicit IdleSpellCheckCallback(LocalFrame&); 69 explicit IdleSpellCheckCallback(LocalFrame&);
52 void handleEvent(IdleDeadline*) override; 70 void handleEvent(IdleDeadline*) override;
53 71
54 LocalFrame& frame() const { return *m_frame; } 72 LocalFrame& frame() const { return *m_frame; }
55 73
56 enum class State {
57 kInactive,
58 kHotModeRequested,
59 kInHotModeInvocation,
60 kColdModeTimerStarted,
61 kColdModeRequested,
62 kInColdModeInvocation
63 };
64
65 // Returns whether spell checking is globally enabled. 74 // Returns whether spell checking is globally enabled.
66 bool isSpellCheckingEnabled() const; 75 bool isSpellCheckingEnabled() const;
67 76
68 // Calls requestIdleCallback with this IdleSpellCheckCallback. 77 // Calls requestIdleCallback with this IdleSpellCheckCallback.
69 void requestInvocation(); 78 void requestInvocation();
70 79
71 // Functions for hot mode. 80 // Functions for hot mode.
72 void hotModeInvocation(IdleDeadline*); 81 void hotModeInvocation(IdleDeadline*);
73 82
83 // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests
84 // cold mode invocation if no critical operation occurs before timer firing.
85 void setNeedsColdModeInvocation();
86
74 // Functions for cold mode. 87 // Functions for cold mode.
75 void coldModeTimerFired(TimerBase*); 88 void coldModeTimerFired(TimerBase*);
76 void coldModeInvocation(IdleDeadline*); 89 void coldModeInvocation(IdleDeadline*);
77 bool coldModeFinishesFullDocument() const; 90 bool coldModeFinishesFullDocument() const;
78 91
92 // Implements |SynchronousMutationObserver|.
93 void contextDestroyed(Document*) final;
94
79 State m_state; 95 State m_state;
96 int m_idleCallbackHandle;
97 mutable bool m_needsMoreColdModeInvocationForTesting;
80 const Member<LocalFrame> m_frame; 98 const Member<LocalFrame> m_frame;
81 99
82 TaskRunnerTimer<IdleSpellCheckCallback> m_coldModeTimer; 100 TaskRunnerTimer<IdleSpellCheckCallback> m_coldModeTimer;
83 }; 101 };
84 102
85 } // namespace blink 103 } // namespace blink
86 104
87 #endif // IdleSpellCheckCallback_h 105 #endif // IdleSpellCheckCallback_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698