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

Side by Side Diff: components/spellcheck/renderer/spellcheck.cc

Issue 2658013002: Remove ScopedVector in components/spellcheck (Closed)
Patch Set: Remove ScopedVector in components/spellcheck 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/spellcheck/renderer/spellcheck.h" 5 #include "components/spellcheck/renderer/spellcheck.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 DocumentMarkersCollector collector; 256 DocumentMarkersCollector collector;
257 content::RenderView::ForEach(&collector); 257 content::RenderView::ForEach(&collector);
258 content::RenderThread::Get()->Send( 258 content::RenderThread::Get()->Send(
259 new SpellCheckHostMsg_RespondDocumentMarkers(collector.markers())); 259 new SpellCheckHostMsg_RespondDocumentMarkers(collector.markers()));
260 } 260 }
261 261
262 // TODO(groby): Make sure we always have a spelling engine, even before 262 // TODO(groby): Make sure we always have a spelling engine, even before
263 // AddSpellcheckLanguage() is called. 263 // AddSpellcheckLanguage() is called.
264 void SpellCheck::AddSpellcheckLanguage(base::File file, 264 void SpellCheck::AddSpellcheckLanguage(base::File file,
265 const std::string& language) { 265 const std::string& language) {
266 languages_.push_back(new SpellcheckLanguage()); 266 languages_.push_back(base::MakeUnique<SpellcheckLanguage>());
267 languages_.back()->Init(std::move(file), language); 267 languages_.back()->Init(std::move(file), language);
268 } 268 }
269 269
270 bool SpellCheck::SpellCheckWord( 270 bool SpellCheck::SpellCheckWord(
271 const base::char16* text_begin, 271 const base::char16* text_begin,
272 int position_in_text, 272 int position_in_text,
273 int text_length, 273 int text_length,
274 int tag, 274 int tag,
275 int* misspelling_start, 275 int* misspelling_start,
276 int* misspelling_len, 276 int* misspelling_len,
(...skipping 23 matching lines...) Expand all
300 // skippable. 300 // skippable.
301 for (; position_in_text <= text_length; 301 for (; position_in_text <= text_length;
302 position_in_text += agreed_skippable_len) { 302 position_in_text += agreed_skippable_len) {
303 // Reseting |agreed_skippable_len| to the worst-case length each time 303 // Reseting |agreed_skippable_len| to the worst-case length each time
304 // prevents some unnecessary iterations. 304 // prevents some unnecessary iterations.
305 agreed_skippable_len = text_length; 305 agreed_skippable_len = text_length;
306 *misspelling_start = 0; 306 *misspelling_start = 0;
307 *misspelling_len = 0; 307 *misspelling_len = 0;
308 suggestions_list.clear(); 308 suggestions_list.clear();
309 309
310 for (ScopedVector<SpellcheckLanguage>::iterator language = 310 for (auto language = languages_.begin(); language != languages_.end();) {
311 languages_.begin();
312 language != languages_.end();) {
313 language_suggestions.clear(); 311 language_suggestions.clear();
314 SpellcheckLanguage::SpellcheckWordResult result = 312 SpellcheckLanguage::SpellcheckWordResult result =
315 (*language)->SpellCheckWord( 313 (*language)->SpellCheckWord(
316 text_begin, position_in_text, text_length, tag, 314 text_begin, position_in_text, text_length, tag,
317 &possible_misspelling_start, &possible_misspelling_len, 315 &possible_misspelling_start, &possible_misspelling_len,
318 optional_suggestions ? &language_suggestions : nullptr); 316 optional_suggestions ? &language_suggestions : nullptr);
319 317
320 switch (result) { 318 switch (result) {
321 case SpellcheckLanguage::SpellcheckWordResult::IS_CORRECT: 319 case SpellcheckLanguage::SpellcheckWordResult::IS_CORRECT:
322 *misspelling_start = 0; 320 *misspelling_start = 0;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 430
433 PostDelayedSpellCheckTask(pending_request_param_.release()); 431 PostDelayedSpellCheckTask(pending_request_param_.release());
434 } 432 }
435 #endif 433 #endif
436 434
437 bool SpellCheck::InitializeIfNeeded() { 435 bool SpellCheck::InitializeIfNeeded() {
438 if (languages_.empty()) 436 if (languages_.empty())
439 return true; 437 return true;
440 438
441 bool initialize_if_needed = false; 439 bool initialize_if_needed = false;
442 for (SpellcheckLanguage* language : languages_) 440 for (auto& language : languages_)
groby-ooo-7-16 2017/01/26 17:40:47 Why make this a reference?
ke.he 2017/01/27 03:15:40 if write as "for (auto language : languages)", com
groby-ooo-7-16 2017/02/02 16:05:44 Ah, my apologies. My mind kept thinking of |langua
443 initialize_if_needed |= language->InitializeIfNeeded(); 441 initialize_if_needed |= language->InitializeIfNeeded();
444 442
445 return initialize_if_needed; 443 return initialize_if_needed;
446 } 444 }
447 445
448 // OSX and Android don't have |pending_request_param_| 446 // OSX and Android don't have |pending_request_param_|
449 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) 447 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
450 void SpellCheck::PostDelayedSpellCheckTask(SpellcheckRequest* request) { 448 void SpellCheck::PostDelayedSpellCheckTask(SpellcheckRequest* request) {
451 if (!request) 449 if (!request)
452 return; 450 return;
453 451
454 base::ThreadTaskRunnerHandle::Get()->PostTask( 452 base::ThreadTaskRunnerHandle::Get()->PostTask(
455 FROM_HERE, base::Bind(&SpellCheck::PerformSpellCheck, AsWeakPtr(), 453 FROM_HERE, base::Bind(&SpellCheck::PerformSpellCheck, AsWeakPtr(),
456 base::Owned(request))); 454 base::Owned(request)));
457 } 455 }
458 #endif 456 #endif
459 457
460 // Mac and Android use their platform engines instead. 458 // Mac and Android use their platform engines instead.
461 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) 459 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
462 void SpellCheck::PerformSpellCheck(SpellcheckRequest* param) { 460 void SpellCheck::PerformSpellCheck(SpellcheckRequest* param) {
463 DCHECK(param); 461 DCHECK(param);
464 462
465 if (languages_.empty() || 463 if (languages_.empty() ||
466 std::find_if(languages_.begin(), languages_.end(), 464 std::find_if(languages_.begin(), languages_.end(),
467 [](SpellcheckLanguage* language) { 465 [](std::unique_ptr<SpellcheckLanguage>& language) {
468 return !language->IsEnabled(); 466 return !language->IsEnabled();
469 }) != languages_.end()) { 467 }) != languages_.end()) {
470 param->completion()->didCancelCheckingText(); 468 param->completion()->didCancelCheckingText();
471 } else { 469 } else {
472 WebVector<blink::WebTextCheckingResult> results; 470 WebVector<blink::WebTextCheckingResult> results;
473 SpellCheckParagraph(param->text(), &results); 471 SpellCheckParagraph(param->text(), &results);
474 param->completion()->didFinishCheckingText(results); 472 param->completion()->didFinishCheckingText(results);
475 } 473 }
476 } 474 }
477 #endif 475 #endif
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 531
534 textcheck_results->assign(results); 532 textcheck_results->assign(results);
535 } 533 }
536 534
537 bool SpellCheck::IsSpellcheckEnabled() { 535 bool SpellCheck::IsSpellcheckEnabled() {
538 #if defined(OS_ANDROID) 536 #if defined(OS_ANDROID)
539 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; 537 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false;
540 #endif 538 #endif
541 return spellcheck_enabled_; 539 return spellcheck_enabled_;
542 } 540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698