Chromium Code Reviews| Index: chrome/browser/spellchecker/spellcheck_profile.cc |
| diff --git a/chrome/browser/spellchecker/spellcheck_profile.cc b/chrome/browser/spellchecker/spellcheck_profile.cc |
| index dd79b96df26c7b3bc7693640c05221f625564f34..9d2b7603cadf7aabf5c33cbf9c8bddaa839bec4d 100644 |
| --- a/chrome/browser/spellchecker/spellcheck_profile.cc |
| +++ b/chrome/browser/spellchecker/spellcheck_profile.cc |
| @@ -4,11 +4,15 @@ |
| #include "chrome/browser/spellchecker/spellcheck_profile.h" |
| +#include "base/file_util.h" |
| #include "base/lazy_instance.h" |
| +#include "base/string_split.h" |
| +#include "base/string_util.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/spellchecker/spellcheck_host.h" |
| #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| +#include "chrome/common/chrome_constants.h" |
| #include "chrome/common/pref_names.h" |
| namespace { |
| @@ -16,8 +20,9 @@ base::LazyInstance<SpellCheckProfile::CustomWordList> g_empty_list( |
| base::LINKER_INITIALIZED); |
| } // namespace |
| -SpellCheckProfile::SpellCheckProfile() |
| - : host_ready_(false) { |
| +SpellCheckProfile::SpellCheckProfile(const FilePath& profile_dir) |
| + : host_ready_(false), |
| + profile_dir_(profile_dir) { |
| } |
| SpellCheckProfile::~SpellCheckProfile() { |
| @@ -98,3 +103,42 @@ void SpellCheckProfile::CustomWordAddedLocally(const std::string& word) { |
| if (metrics_.get()) |
| metrics_->RecordCustomWordCountStats(custom_words_->size()); |
| } |
| + |
| +void SpellCheckProfile::LoadCustomDictionary(CustomWordList* custom_words) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) || IsTesting()); |
| + |
| + if (!custom_words) |
| + return; |
| + |
| + std::string contents; |
|
Hironori Bono
2011/10/20 04:48:50
nit: move this declaration above Line 116.
shinyak (Google)
2011/10/20 12:04:52
Done.
|
| + CustomWordList list_of_words; |
| + |
| + file_util::ReadFileToString(GetCustomDictionaryPath(), &contents); |
| + base::SplitString(contents, '\n', &list_of_words); |
|
Hironori Bono
2011/10/20 04:48:50
nit: need 'if (!contents.empty()) {' to avoid call
shinyak (Google)
2011/10/20 12:04:52
Done.
|
| + for (size_t i = 0; i < list_of_words.size(); ++i) { |
| + if (list_of_words[i] != "") |
| + custom_words->push_back(list_of_words[i]); |
| + } |
| +} |
| + |
| +void SpellCheckProfile::WriteWordToCustomDictionary(const std::string& word) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE) || IsTesting()); |
| + |
| + // Stored in UTF-8. |
| + DCHECK(IsStringUTF8(word)); |
| + |
| + std::string word_to_add(word + "\n"); |
| + FILE* f = file_util::OpenFile(GetCustomDictionaryPath(), "a+"); |
| + if (f) { |
| + fputs(word_to_add.c_str(), f); |
| + file_util::CloseFile(f); |
| + } |
| +} |
| + |
| +const FilePath& SpellCheckProfile::GetCustomDictionaryPath() { |
| + if (custom_dictionary_path_.empty()) |
| + custom_dictionary_path_ = profile_dir_.Append( |
| + chrome::kCustomDictionaryFileName); |
|
Hironori Bono
2011/10/20 04:48:50
nit: I prefer wrapping this line before 'profile_d
shinyak (Google)
2011/10/20 12:04:52
Done.
|
| + |
| + return custom_dictionary_path_; |
| +} |