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

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

Issue 8345034: SpellCheck: the custom dictionary should be per profile. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reflected reviewer's comment. 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_profile.cc
diff --git a/chrome/browser/spellchecker/spellcheck_profile.cc b/chrome/browser/spellchecker/spellcheck_profile.cc
index dd79b96df26c7b3bc7693640c05221f625564f34..b0f050690c07331cb82ed4f5fea9d4e930159a04 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()
- : host_ready_(false) {
+SpellCheckProfile::SpellCheckProfile(const FilePath& profile_dir)
+ : host_ready_(false),
+ custom_dictionary_path_(
+ profile_dir.Append(chrome::kCustomDictionaryFileName)) {
Hironori Bono 2011/10/20 02:20:36 Even though file_util::Append() does not usually t
shinyak (Google) 2011/10/20 04:08:43 Done.
}
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.
Hironori Bono 2011/10/20 02:20:36 nit: it would be good to add 'DCHECK(IsStringUTF8(
shinyak (Google) 2011/10/20 04:08:43 Done.
+ 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);
Hironori Bono 2011/10/20 02:20:36 nit: it may be better to call file_util::CloseFile
shinyak (Google) 2011/10/20 04:08:43 Done.
+}

Powered by Google App Engine
This is Rietveld 408576698