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

Side by Side Diff: chrome/browser/spellchecker.cc

Issue 342090: Use ChromeThread::DeleteOnIOThread in a few places where an object must be de... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/spellchecker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "chrome/browser/spellchecker.h" 5 #include "chrome/browser/spellchecker.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/histogram.h" 11 #include "base/histogram.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/stats_counters.h" 14 #include "base/stats_counters.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/browser/net/url_fetcher.h" 16 #include "chrome/browser/net/url_fetcher.h"
18 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
19 #include "chrome/browser/spellchecker_common.h" 18 #include "chrome/browser/spellchecker_common.h"
20 #include "chrome/browser/spellchecker_platform_engine.h" 19 #include "chrome/browser/spellchecker_platform_engine.h"
21 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
22 #include "chrome/common/chrome_counters.h" 21 #include "chrome/common/chrome_counters.h"
23 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
25 #include "chrome/common/pref_service.h" 24 #include "chrome/common/pref_service.h"
26 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 213 }
215 214
216 Finish(true); 215 Finish(true);
217 } 216 }
218 217
219 private: 218 private:
220 void Finish(bool file_existed) { 219 void Finish(bool file_existed) {
221 ChromeThread::PostTask( 220 ChromeThread::PostTask(
222 ChromeThread::IO, FROM_HERE, 221 ChromeThread::IO, FROM_HERE,
223 NewRunnableMethod( 222 NewRunnableMethod(
224 spellchecker_, &SpellChecker::HunspellInited, hunspell_, 223 spellchecker_.get(), &SpellChecker::HunspellInited, hunspell_,
225 bdict_file_, file_existed)); 224 bdict_file_, file_existed));
226 } 225 }
227 226
228 // The SpellChecker we are working for. We are guaranteed to be outlived 227 // The SpellChecker we are working for.
229 // by this object because it AddRefs() itself before calling us. 228 scoped_refptr<SpellChecker> spellchecker_;
230 // Accessing it is not necessarily thread safe, but are careful to only access
231 // it in ways that are.
232 SpellChecker* spellchecker_;
233 Hunspell* hunspell_; 229 Hunspell* hunspell_;
234 file_util::MemoryMappedFile* bdict_file_; 230 file_util::MemoryMappedFile* bdict_file_;
235 231
236 FilePath custom_dictionary_file_name_; 232 FilePath custom_dictionary_file_name_;
237 FilePath dict_file_name_app_; 233 FilePath dict_file_name_app_;
238 FilePath dict_file_name_usr_; 234 FilePath dict_file_name_usr_;
239 235
240 DISALLOW_COPY_AND_ASSIGN(ReadDictionaryTask); 236 DISALLOW_COPY_AND_ASSIGN(ReadDictionaryTask);
241 }; 237 };
242 238
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // File name for downloading in DIR_APP_DICTIONARIES. 526 // File name for downloading in DIR_APP_DICTIONARIES.
531 FilePath dictionary_file_name_app = GetVersionedFileName(language_, 527 FilePath dictionary_file_name_app = GetVersionedFileName(language_,
532 given_dictionary_directory_); 528 given_dictionary_directory_);
533 529
534 // Filename for downloading in the fallback dictionary download directory, 530 // Filename for downloading in the fallback dictionary download directory,
535 // DIR_USER_DATA. 531 // DIR_USER_DATA.
536 FilePath dict_dir_userdata = GetFallbackDictionaryDownloadDirectory(); 532 FilePath dict_dir_userdata = GetFallbackDictionaryDownloadDirectory();
537 FilePath dictionary_file_name_usr = GetVersionedFileName(language_, 533 FilePath dictionary_file_name_usr = GetVersionedFileName(language_,
538 dict_dir_userdata); 534 dict_dir_userdata);
539 535
540 // Balances Release() in HunspellInited().
541 AddRef();
542 ChromeThread::PostTask( 536 ChromeThread::PostTask(
543 ChromeThread::FILE, FROM_HERE, 537 ChromeThread::FILE, FROM_HERE,
544 new ReadDictionaryTask( 538 new ReadDictionaryTask(
545 this, dictionary_file_name_app, dictionary_file_name_usr)); 539 this, dictionary_file_name_app, dictionary_file_name_usr));
546 540
547 return hunspell_.get() != NULL; 541 return hunspell_.get() != NULL;
548 } 542 }
549 543
550 void SpellChecker::HunspellInited(Hunspell* hunspell, 544 void SpellChecker::HunspellInited(Hunspell* hunspell,
551 file_util::MemoryMappedFile* bdict_file, 545 file_util::MemoryMappedFile* bdict_file,
552 bool file_existed) { 546 bool file_existed) {
553 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 547 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
554 548
555 if (file_existed) 549 if (file_existed)
556 tried_to_init_ = true; 550 tried_to_init_ = true;
557 551
558 if (!hunspell) { 552 if (!hunspell) {
559 if (!file_existed) { 553 if (!file_existed) {
560 // File didn't exist. We need to download a dictionary. 554 // File didn't exist. We need to download a dictionary.
561 DoDictionaryDownload(); 555 DoDictionaryDownload();
562 } 556 }
563
564 // Balances AddRef() in Initialize().
565 Release();
566 return; 557 return;
567 } 558 }
568 559
569 560
570 bdict_file_.reset(bdict_file); 561 bdict_file_.reset(bdict_file);
571 hunspell_.reset(hunspell); 562 hunspell_.reset(hunspell);
572 // Add all the custom words we've gotten while Hunspell was loading. 563 // Add all the custom words we've gotten while Hunspell was loading.
573 while (!custom_words_.empty()) { 564 while (!custom_words_.empty()) {
574 hunspell_->add(custom_words_.front().c_str()); 565 hunspell_->add(custom_words_.front().c_str());
575 custom_words_.pop(); 566 custom_words_.pop();
576 } 567 }
577
578 // Balances AddRef() in Initialize().
579 Release();
580 } 568 }
581 569
582 void SpellChecker::DoDictionaryDownload() { 570 void SpellChecker::DoDictionaryDownload() {
583 // Download the dictionary file. 571 // Download the dictionary file.
584 if (request_context_getter_) { 572 if (request_context_getter_) {
585 if (!tried_to_download_dictionary_file_) { 573 if (!tried_to_download_dictionary_file_) {
586 FilePath dictionary_file_name_app = GetVersionedFileName(language_, 574 FilePath dictionary_file_name_app = GetVersionedFileName(language_,
587 given_dictionary_directory_); 575 given_dictionary_directory_);
588 StartDictionaryDownload(dictionary_file_name_app); 576 StartDictionaryDownload(dictionary_file_name_app);
589 tried_to_download_dictionary_file_ = true; 577 tried_to_download_dictionary_file_ = true;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 804
817 // Populate the vector of WideStrings. 805 // Populate the vector of WideStrings.
818 for (int i = 0; i < number_of_suggestions; i++) { 806 for (int i = 0; i < number_of_suggestions; i++) {
819 if (i < kMaxSuggestions) 807 if (i < kMaxSuggestions)
820 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i])); 808 optional_suggestions->push_back(UTF8ToUTF16(suggestions[i]));
821 free(suggestions[i]); 809 free(suggestions[i]);
822 } 810 }
823 if (suggestions != NULL) 811 if (suggestions != NULL)
824 free(suggestions); 812 free(suggestions);
825 } 813 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698