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

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

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Output info for some DCHECKs, add TODOs. Created 4 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const Vector<uint32_t>& documentMarkersInRange, 44 const Vector<uint32_t>& documentMarkersInRange,
45 const Vector<unsigned>& documentMarkerOffsets, 45 const Vector<unsigned>& documentMarkerOffsets,
46 int requestNumber) 46 int requestNumber)
47 : m_requester(nullptr) 47 : m_requester(nullptr)
48 , m_checkingRange(checkingRange) 48 , m_checkingRange(checkingRange)
49 , m_paragraphRange(paragraphRange) 49 , m_paragraphRange(paragraphRange)
50 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt()) 50 , m_rootEditableElement(m_checkingRange->startContainer()->rootEditableEleme nt())
51 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets) 51 , m_requestData(unrequestedTextCheckingSequence, text, mask, processType, do cumentMarkersInRange, documentMarkerOffsets)
52 , m_requestNumber(requestNumber) 52 , m_requestNumber(requestNumber)
53 { 53 {
54 ASSERT(m_checkingRange); 54 DCHECK(m_checkingRange);
55 ASSERT(m_checkingRange->inShadowIncludingDocument()); 55 DCHECK(m_checkingRange->inShadowIncludingDocument());
56 ASSERT(m_paragraphRange); 56 DCHECK(m_paragraphRange);
57 ASSERT(m_paragraphRange->inShadowIncludingDocument()); 57 DCHECK(m_paragraphRange->inShadowIncludingDocument());
58 ASSERT(m_rootEditableElement); 58 DCHECK(m_rootEditableElement);
59 } 59 }
60 60
61 SpellCheckRequest::~SpellCheckRequest() 61 SpellCheckRequest::~SpellCheckRequest()
62 { 62 {
63 } 63 }
64 64
65 DEFINE_TRACE(SpellCheckRequest) 65 DEFINE_TRACE(SpellCheckRequest)
66 { 66 {
67 visitor->trace(m_requester); 67 visitor->trace(m_requester);
68 visitor->trace(m_checkingRange); 68 visitor->trace(m_checkingRange);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 if (!m_requester) 134 if (!m_requester)
135 return; 135 return;
136 SpellCheckRequester* requester = m_requester; 136 SpellCheckRequester* requester = m_requester;
137 m_requester = nullptr; 137 m_requester = nullptr;
138 requester->didCheckCancel(m_requestData.sequence()); 138 requester->didCheckCancel(m_requestData.sequence());
139 } 139 }
140 140
141 void SpellCheckRequest::setCheckerAndSequence(SpellCheckRequester* requester, in t sequence) 141 void SpellCheckRequest::setCheckerAndSequence(SpellCheckRequester* requester, in t sequence)
142 { 142 {
143 ASSERT(!m_requester); 143 DCHECK(!m_requester);
144 ASSERT(m_requestData.sequence() == unrequestedTextCheckingSequence); 144 DCHECK_EQ(m_requestData.sequence(), unrequestedTextCheckingSequence);
145 m_requester = requester; 145 m_requester = requester;
146 m_requestData.m_sequence = sequence; 146 m_requestData.m_sequence = sequence;
147 } 147 }
148 148
149 SpellCheckRequester::SpellCheckRequester(LocalFrame& frame) 149 SpellCheckRequester::SpellCheckRequester(LocalFrame& frame)
150 : m_frame(&frame) 150 : m_frame(&frame)
151 , m_lastRequestSequence(0) 151 , m_lastRequestSequence(0)
152 , m_lastProcessedSequence(0) 152 , m_lastProcessedSequence(0)
153 , m_timerToProcessQueuedRequest(this, &SpellCheckRequester::timerFiredToProc essQueuedRequest) 153 , m_timerToProcessQueuedRequest(this, &SpellCheckRequester::timerFiredToProc essQueuedRequest)
154 { 154 {
155 } 155 }
156 156
157 SpellCheckRequester::~SpellCheckRequester() 157 SpellCheckRequester::~SpellCheckRequester()
158 { 158 {
159 } 159 }
160 160
161 TextCheckerClient& SpellCheckRequester::client() const 161 TextCheckerClient& SpellCheckRequester::client() const
162 { 162 {
163 return frame().spellChecker().textChecker(); 163 return frame().spellChecker().textChecker();
164 } 164 }
165 165
166 void SpellCheckRequester::timerFiredToProcessQueuedRequest(Timer<SpellCheckReque ster>*) 166 void SpellCheckRequester::timerFiredToProcessQueuedRequest(Timer<SpellCheckReque ster>*)
167 { 167 {
168 ASSERT(!m_requestQueue.isEmpty()); 168 DCHECK(!m_requestQueue.isEmpty());
169 if (m_requestQueue.isEmpty()) 169 if (m_requestQueue.isEmpty())
170 return; 170 return;
171 171
172 invokeRequest(m_requestQueue.takeFirst()); 172 invokeRequest(m_requestQueue.takeFirst());
173 } 173 }
174 174
175 bool SpellCheckRequester::canCheckAsynchronously(Range* range) const 175 bool SpellCheckRequester::canCheckAsynchronously(Range* range) const
176 { 176 {
177 return isCheckable(range); 177 return isCheckable(range);
178 } 178 }
179 179
180 bool SpellCheckRequester::isCheckable(Range* range) const 180 bool SpellCheckRequester::isCheckable(Range* range) const
181 { 181 {
182 if (!range || !range->firstNode() || !range->firstNode()->layoutObject()) 182 if (!range || !range->firstNode() || !range->firstNode()->layoutObject())
183 return false; 183 return false;
184 const Node* node = range->startContainer(); 184 const Node* node = range->startContainer();
185 if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnable d()) 185 if (node && node->isElementNode() && !toElement(node)->isSpellCheckingEnable d())
186 return false; 186 return false;
187 return true; 187 return true;
188 } 188 }
189 189
190 void SpellCheckRequester::requestCheckingFor(SpellCheckRequest* request) 190 void SpellCheckRequester::requestCheckingFor(SpellCheckRequest* request)
191 { 191 {
192 if (!request || !canCheckAsynchronously(request->paragraphRange())) 192 if (!request || !canCheckAsynchronously(request->paragraphRange()))
193 return; 193 return;
194 194
195 ASSERT(request->data().sequence() == unrequestedTextCheckingSequence); 195 DCHECK_EQ(request->data().sequence(), unrequestedTextCheckingSequence);
196 int sequence = ++m_lastRequestSequence; 196 int sequence = ++m_lastRequestSequence;
197 if (sequence == unrequestedTextCheckingSequence) 197 if (sequence == unrequestedTextCheckingSequence)
198 sequence = ++m_lastRequestSequence; 198 sequence = ++m_lastRequestSequence;
199 199
200 request->setCheckerAndSequence(this, sequence); 200 request->setCheckerAndSequence(this, sequence);
201 201
202 if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) { 202 if (m_timerToProcessQueuedRequest.isActive() || m_processingRequest) {
203 enqueueRequest(request); 203 enqueueRequest(request);
204 return; 204 return;
205 } 205 }
(...skipping 15 matching lines...) Expand all
221 // leaks, just async work items waiting to be processed. 221 // leaks, just async work items waiting to be processed.
222 // 222 //
223 // Rather than somehow wait for this async queue to drain before running 223 // Rather than somehow wait for this async queue to drain before running
224 // the leak detector, they're all cancelled to prevent flaky leaks being 224 // the leak detector, they're all cancelled to prevent flaky leaks being
225 // reported. 225 // reported.
226 m_requestQueue.clear(); 226 m_requestQueue.clear();
227 } 227 }
228 228
229 void SpellCheckRequester::invokeRequest(SpellCheckRequest* request) 229 void SpellCheckRequester::invokeRequest(SpellCheckRequest* request)
230 { 230 {
231 ASSERT(!m_processingRequest); 231 DCHECK(!m_processingRequest);
232 m_processingRequest = request; 232 m_processingRequest = request;
233 client().requestCheckingOfString(m_processingRequest); 233 client().requestCheckingOfString(m_processingRequest);
234 } 234 }
235 235
236 void SpellCheckRequester::clearProcessingRequest() 236 void SpellCheckRequester::clearProcessingRequest()
237 { 237 {
238 if (!m_processingRequest) 238 if (!m_processingRequest)
239 return; 239 return;
240 240
241 m_processingRequest->dispose(); 241 m_processingRequest->dispose();
242 m_processingRequest.clear(); 242 m_processingRequest.clear();
243 } 243 }
244 244
245 void SpellCheckRequester::enqueueRequest(SpellCheckRequest* request) 245 void SpellCheckRequester::enqueueRequest(SpellCheckRequest* request)
246 { 246 {
247 ASSERT(request); 247 DCHECK(request);
248 bool continuation = false; 248 bool continuation = false;
249 if (!m_requestQueue.isEmpty()) { 249 if (!m_requestQueue.isEmpty()) {
250 SpellCheckRequest* lastRequest = m_requestQueue.last(); 250 SpellCheckRequest* lastRequest = m_requestQueue.last();
251 // It's a continuation if the number of the last request got incremented in the new one and 251 // It's a continuation if the number of the last request got incremented in the new one and
252 // both apply to the same editable. 252 // both apply to the same editable.
253 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement() 253 continuation = request->rootEditableElement() == lastRequest->rootEditab leElement()
254 && request->requestNumber() == lastRequest->requestNumber() + 1; 254 && request->requestNumber() == lastRequest->requestNumber() + 1;
255 } 255 }
256 256
257 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other. 257 // Spellcheck requests for chunks of text in the same element should not ove rwrite each other.
258 if (!continuation) { 258 if (!continuation) {
259 for (auto& requestQueue : m_requestQueue) { 259 for (auto& requestQueue : m_requestQueue) {
260 if (request->rootEditableElement() != requestQueue->rootEditableElem ent()) 260 if (request->rootEditableElement() != requestQueue->rootEditableElem ent())
261 continue; 261 continue;
262 262
263 requestQueue = request; 263 requestQueue = request;
264 return; 264 return;
265 } 265 }
266 } 266 }
267 267
268 m_requestQueue.append(request); 268 m_requestQueue.append(request);
269 } 269 }
270 270
271 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results) 271 void SpellCheckRequester::didCheck(int sequence, const Vector<TextCheckingResult >& results)
272 { 272 {
273 ASSERT(m_processingRequest); 273 DCHECK(m_processingRequest);
274 ASSERT(m_processingRequest->data().sequence() == sequence); 274 DCHECK_EQ(m_processingRequest->data().sequence(), sequence);
275 if (m_processingRequest->data().sequence() != sequence) { 275 if (m_processingRequest->data().sequence() != sequence) {
276 m_requestQueue.clear(); 276 m_requestQueue.clear();
277 return; 277 return;
278 } 278 }
279 279
280 frame().spellChecker().markAndReplaceFor(m_processingRequest, results); 280 frame().spellChecker().markAndReplaceFor(m_processingRequest, results);
281 281
282 if (m_lastProcessedSequence < sequence) 282 if (m_lastProcessedSequence < sequence)
283 m_lastProcessedSequence = sequence; 283 m_lastProcessedSequence = sequence;
284 284
(...skipping 26 matching lines...) Expand all
311 } 311 }
312 312
313 DEFINE_TRACE(SpellCheckRequester) 313 DEFINE_TRACE(SpellCheckRequester)
314 { 314 {
315 visitor->trace(m_frame); 315 visitor->trace(m_frame);
316 visitor->trace(m_processingRequest); 316 visitor->trace(m_processingRequest);
317 visitor->trace(m_requestQueue); 317 visitor->trace(m_requestQueue);
318 } 318 }
319 319
320 } // namespace blink 320 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698