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

Unified Diff: chrome/browser/spellchecker/spellcheck_custom_dictionary.h

Issue 11414282: Improve reliability of custom spelling dictionary file. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments Created 8 years 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
« no previous file with comments | « no previous file | chrome/browser/spellchecker/spellcheck_custom_dictionary.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/spellchecker/spellcheck_custom_dictionary.h
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary.h b/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
index b1d6045f1db0231c841c7e57c7738cf5b490a0c7..cedbb734c2c762df57ad3b030f80f276ea0b8278 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary.h
@@ -11,10 +11,19 @@
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
#include "chrome/browser/spellchecker/spellcheck_dictionary.h"
#include "chrome/common/spellcheck_common.h"
-// Defines a custom dictionary which users can add their own words to.
+// Defines a custom dictionary where users can add their own words. All words
+// must be UTF8, between 1 and 128 bytes long, and without ASCII whitespace.
+// The dictionary contains its own checksum when saved on disk. Example
+// dictionary file contents:
+//
+// bar
+// foo
+// checksum_v1 = ec3df4034567e59e119fcf87f2d9bad4
+//
class SpellcheckCustomDictionary : public SpellcheckDictionary {
public:
class Observer {
@@ -33,8 +42,8 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
const chrome::spellcheck_common::WordList& GetWords() const;
// Populates the |custom_words| with the list of words in the custom
- // dictionary file. Makes sure that the custom dictionary file is sorted and
- // does not have duplicates.
+ // dictionary file. Makes sure that the custom dictionary file is sorted, does
+ // not have duplicates, and contains only valid words.
void LoadDictionaryIntoCustomWordList(
chrome::spellcheck_common::WordList* custom_words);
@@ -42,8 +51,8 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
// member variable. Does not delete the memory at |custom_words|.
void SetCustomWordList(chrome::spellcheck_common::WordList* custom_words);
- // Adds the given word to the custom words list and inform renderer of the
- // update. Returns false for duplicate words.
+ // Adds the given word to the custom words list and informs renderers of the
+ // update. Returns false for duplicate and invalid words.
bool AddWord(const std::string& word);
// Returns false for duplicate words.
@@ -51,8 +60,9 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
void WriteWordToCustomDictionary(const std::string& word);
- // Removes the given word from the custom words list and informs renderer of
- // the update. Returns false for words that are not in the dictionary.
+ // Removes the given word from the custom words list and informs renderers of
+ // the update. Returns false for words that are not in the dictionary and
+ // invalid words.
bool RemoveWord(const std::string& word);
// Returns false for words that are not in the dictionary.
@@ -75,6 +85,18 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
void SetCustomWordListAndDelete(
chrome::spellcheck_common::WordList* custom_words);
+ // Loads the dictionary file into |custom_words|. If the dictionary checksum
+ // is not valid, but backup checksum is valid, then restores the backup and
+ // loads that into |custom_words| instead. If the backup is invalid too, then
+ // clears |custom_words|.
+ void LoadDictionaryFileReliably(
+ chrome::spellcheck_common::WordList* custom_words);
+
+ // Backs up the original dictionary, saves |custom_words| and its checksum
+ // into the dictionary file.
+ void SaveDictionaryFileReliably(
+ const chrome::spellcheck_common::WordList& custom_words);
+
// In-memory cache of the custom words file.
chrome::spellcheck_common::WordList words_;
@@ -83,7 +105,7 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary {
base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_;
- std::vector<Observer*> observers_;
+ ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary);
};
« no previous file with comments | « no previous file | chrome/browser/spellchecker/spellcheck_custom_dictionary.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698