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

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

Issue 2827903002: Hide cold mode idle time spellchecker behind a flag (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
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 #include "core/editing/spellcheck/IdleSpellCheckCallback.h" 5 #include "core/editing/spellcheck/IdleSpellCheckCallback.h"
6 6
7 #include "core/dom/IdleRequestOptions.h" 7 #include "core/dom/IdleRequestOptions.h"
8 #include "core/dom/TaskRunnerHelper.h" 8 #include "core/dom/TaskRunnerHelper.h"
9 #include "core/editing/EditingUtilities.h" 9 #include "core/editing/EditingUtilities.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 IdleRequestOptions options; 98 IdleRequestOptions options;
99 options.setTimeout(kHotModeRequestTimeoutMS); 99 options.setTimeout(kHotModeRequestTimeoutMS);
100 idle_callback_handle_ = 100 idle_callback_handle_ =
101 GetFrame().GetDocument()->RequestIdleCallback(this, options); 101 GetFrame().GetDocument()->RequestIdleCallback(this, options);
102 state_ = State::kHotModeRequested; 102 state_ = State::kHotModeRequested;
103 } 103 }
104 104
105 void IdleSpellCheckCallback::SetNeedsColdModeInvocation() { 105 void IdleSpellCheckCallback::SetNeedsColdModeInvocation() {
106 if (!IsSpellCheckingEnabled()) { 106 if (!RuntimeEnabledFeatures::idleTimeColdModeSpellCheckingEnabled() ||
107 !IsSpellCheckingEnabled()) {
107 Deactivate(); 108 Deactivate();
108 return; 109 return;
109 } 110 }
110 111
111 if (state_ != State::kInactive && state_ != State::kInHotModeInvocation && 112 if (state_ != State::kInactive && state_ != State::kInHotModeInvocation &&
112 state_ != State::kInColdModeInvocation) 113 state_ != State::kInColdModeInvocation)
113 return; 114 return;
114 115
115 DCHECK(!cold_mode_timer_.IsActive()); 116 DCHECK(!cold_mode_timer_.IsActive());
116 int interval_ms = state_ == State::kInColdModeInvocation 117 int interval_ms = state_ == State::kInColdModeInvocation
117 ? kConsecutiveColdModeTimerIntervalMS 118 ? kConsecutiveColdModeTimerIntervalMS
118 : kColdModeTimerIntervalMS; 119 : kColdModeTimerIntervalMS;
119 cold_mode_timer_.StartOneShot(interval_ms / 1000.0, BLINK_FROM_HERE); 120 cold_mode_timer_.StartOneShot(interval_ms / 1000.0, BLINK_FROM_HERE);
120 state_ = State::kColdModeTimerStarted; 121 state_ = State::kColdModeTimerStarted;
121 } 122 }
122 123
123 void IdleSpellCheckCallback::ColdModeTimerFired(TimerBase*) { 124 void IdleSpellCheckCallback::ColdModeTimerFired(TimerBase*) {
125 DCHECK(RuntimeEnabledFeatures::idleTimeColdModeSpellCheckingEnabled());
124 DCHECK_EQ(State::kColdModeTimerStarted, state_); 126 DCHECK_EQ(State::kColdModeTimerStarted, state_);
125 127
126 if (!IsSpellCheckingEnabled()) { 128 if (!IsSpellCheckingEnabled()) {
127 Deactivate(); 129 Deactivate();
128 return; 130 return;
129 } 131 }
130 132
131 idle_callback_handle_ = 133 idle_callback_handle_ =
132 GetFrame().GetDocument()->RequestIdleCallback(this, IdleRequestOptions()); 134 GetFrame().GetDocument()->RequestIdleCallback(this, IdleRequestOptions());
133 state_ = State::kColdModeRequested; 135 state_ = State::kColdModeRequested;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if (!IsSpellCheckingEnabled()) { 169 if (!IsSpellCheckingEnabled()) {
168 Deactivate(); 170 Deactivate();
169 return; 171 return;
170 } 172 }
171 173
172 if (state_ == State::kHotModeRequested) { 174 if (state_ == State::kHotModeRequested) {
173 state_ = State::kInHotModeInvocation; 175 state_ = State::kInHotModeInvocation;
174 HotModeInvocation(deadline); 176 HotModeInvocation(deadline);
175 SetNeedsColdModeInvocation(); 177 SetNeedsColdModeInvocation();
176 } else if (state_ == State::kColdModeRequested) { 178 } else if (state_ == State::kColdModeRequested) {
179 DCHECK(RuntimeEnabledFeatures::idleTimeColdModeSpellCheckingEnabled());
177 state_ = State::kInColdModeInvocation; 180 state_ = State::kInColdModeInvocation;
178 cold_mode_requester_->Invoke(deadline); 181 cold_mode_requester_->Invoke(deadline);
179 if (cold_mode_requester_->FullDocumentChecked()) 182 if (cold_mode_requester_->FullDocumentChecked())
180 state_ = State::kInactive; 183 state_ = State::kInactive;
181 else 184 else
182 SetNeedsColdModeInvocation(); 185 SetNeedsColdModeInvocation();
183 } else { 186 } else {
184 NOTREACHED(); 187 NOTREACHED();
185 } 188 }
186 } 189 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 DCHECK(cold_mode_timer_.IsActive()); 228 DCHECK(cold_mode_timer_.IsActive());
226 cold_mode_timer_.Stop(); 229 cold_mode_timer_.Stop();
227 ColdModeTimerFired(&cold_mode_timer_); 230 ColdModeTimerFired(&cold_mode_timer_);
228 } 231 }
229 232
230 void IdleSpellCheckCallback::SetNeedsMoreColdModeInvocationForTesting() { 233 void IdleSpellCheckCallback::SetNeedsMoreColdModeInvocationForTesting() {
231 cold_mode_requester_->SetNeedsMoreInvocationForTesting(); 234 cold_mode_requester_->SetNeedsMoreInvocationForTesting();
232 } 235 }
233 236
234 } // namespace blink 237 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698