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

Unified Diff: chrome/browser/spellchecker/spellcheck_host_impl.cc

Issue 8233040: SpellCheck refactoring: Moved user custom dictionary for spell check to SpellCheckProfile. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Mentioned lifecycle of word_list Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker/spellcheck_host_impl.cc
diff --git a/chrome/browser/spellchecker/spellcheck_host_impl.cc b/chrome/browser/spellchecker/spellcheck_host_impl.cc
index c49af7e260b7dfd3e2acf8c6dadd95c67706e4a6..ba6698354cf8869841bff7fa2c925d62bb66be09 100644
--- a/chrome/browser/spellchecker/spellcheck_host_impl.cc
+++ b/chrome/browser/spellchecker/spellcheck_host_impl.cc
@@ -94,11 +94,6 @@ SpellCheckHostImpl::SpellCheckHostImpl(
DCHECK(profile_);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- FilePath personal_file_directory;
- PathService::Get(chrome::DIR_USER_DATA, &personal_file_directory);
- custom_dictionary_file_ =
- personal_file_directory.Append(chrome::kCustomDictionaryFileName);
-
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
NotificationService::AllSources());
}
@@ -126,6 +121,8 @@ void SpellCheckHostImpl::Initialize() {
RecordSpellCheckStats(false, language_);
#endif
+ if (profile_)
+ profile_->LoadCustomDictionary();
Hironori Bono 2011/10/13 09:29:59 It seems this code start loading a custom-dictiona
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(this,
&SpellCheckHostImpl::InitializeDictionaryLocation));
@@ -173,9 +170,7 @@ void SpellCheckHostImpl::AddWord(const std::string& word) {
if (profile_)
profile_->CustomWordAddedLocally(word);
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(this,
- &SpellCheckHostImpl::WriteWordToCustomDictionary, word));
+
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word));
@@ -236,22 +231,10 @@ void SpellCheckHostImpl::InitializeInternal() {
request_context_getter_ = NULL;
- scoped_ptr<CustomWordList> custom_words(new CustomWordList());
- if (file_ != base::kInvalidPlatformFileValue) {
- // Load custom dictionary.
- std::string contents;
- file_util::ReadFileToString(custom_dictionary_file_, &contents);
- CustomWordList list_of_words;
- base::SplitString(contents, '\n', &list_of_words);
- for (size_t i = 0; i < list_of_words.size(); ++i)
- custom_words->push_back(list_of_words[i]);
- }
-
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(
this,
- &SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords,
- custom_words.release()));
+ &SpellCheckHostImpl::InformProfileOfInitialization));
}
void SpellCheckHostImpl::InitializeOnFileThread() {
@@ -262,18 +245,10 @@ void SpellCheckHostImpl::InitializeOnFileThread() {
}
void SpellCheckHostImpl::InformProfileOfInitialization() {
- InformProfileOfInitializationWithCustomWords(NULL);
-}
-
-void SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords(
- CustomWordList* custom_words) {
- // Non-null |custom_words| should be given only if the profile is available
- // for simplifying the life-cycle management of the word list.
- DCHECK(profile_ || !custom_words);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (profile_)
- profile_->SpellCheckHostInitialized(custom_words);
+ profile_->SpellCheckHostInitialized();
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
@@ -308,17 +283,6 @@ void SpellCheckHostImpl::DownloadDictionary() {
request_context_getter_ = NULL;
}
-void SpellCheckHostImpl::WriteWordToCustomDictionary(const std::string& word) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
- // Stored in UTF-8.
- std::string word_to_add(word + "\n");
- FILE* f = file_util::OpenFile(custom_dictionary_file_, "a+");
- if (f)
- fputs(word_to_add.c_str(), f);
- file_util::CloseFile(f);
-}
-
void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source,
const GURL& url,
const net::URLRequestStatus& status,
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_host_impl.h ('k') | chrome/browser/spellchecker/spellcheck_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698