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..d68625ff50631f7709806440061c8a25dd487e65 100644 |
--- a/chrome/browser/spellchecker/spellcheck_profile.cc |
+++ b/chrome/browser/spellchecker/spellcheck_profile.cc |
@@ -4,11 +4,14 @@ |
#include "chrome/browser/spellchecker/spellcheck_profile.h" |
+#include "base/file_util.h" |
#include "base/lazy_instance.h" |
+#include "base/string_split.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 +19,10 @@ base::LazyInstance<SpellCheckProfile::CustomWordList> g_empty_list( |
base::LINKER_INITIALIZED); |
} // namespace |
-SpellCheckProfile::SpellCheckProfile() |
+SpellCheckProfile::SpellCheckProfile(const FilePath& profile_dir) |
: host_ready_(false) { |
+ custom_dictionary_path_ = |
gmorrita
2011/10/19 05:27:37
Why not use initializer?
shinyak (Google)
2011/10/19 05:55:04
Done.
|
+ profile_dir.Append(chrome::kCustomDictionaryFileName); |
} |
SpellCheckProfile::~SpellCheckProfile() { |
@@ -98,3 +103,31 @@ 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; |
+ CustomWordList list_of_words; |
+ |
+ file_util::ReadFileToString(custom_dictionary_path_, &contents); |
+ base::SplitString(contents, '\n', &list_of_words); |
+ 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. |
+ std::string word_to_add(word + "\n"); |
+ FILE* f = file_util::OpenFile(custom_dictionary_path_, "a+"); |
+ if (f) |
+ fputs(word_to_add.c_str(), f); |
+ file_util::CloseFile(f); |
+} |