| 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..d5c4de485c5593abdc503b55abec6682ce31d9fb 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,45 @@ 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;
|
| + file_util::ReadFileToString(GetCustomDictionaryPath(), &contents);
|
| + if (contents.empty())
|
| + return;
|
| +
|
| + CustomWordList list_of_words;
|
| + 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.
|
| + 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_.get()) {
|
| + custom_dictionary_path_.reset(
|
| + new FilePath(profile_dir_.Append(chrome::kCustomDictionaryFileName)));
|
| + }
|
| +
|
| + return *custom_dictionary_path_;
|
| +}
|
|
|