Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ |
| 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/spellchecker/spellcheck_dictionary.h" | 14 #include "chrome/browser/spellchecker/spellcheck_dictionary.h" |
| 15 #include "chrome/common/spellcheck_common.h" | 15 #include "chrome/common/spellcheck_common.h" |
| 16 | 16 |
| 17 // Defines a custom dictionary which users can add their own words to. | 17 // Defines a custom dictionary which users can add their own words to. |
| 18 class SpellcheckCustomDictionary : public SpellcheckDictionary { | 18 class SpellcheckCustomDictionary : public SpellcheckDictionary { |
| 19 public: | 19 public: |
| 20 class Observer { | |
| 21 public: | |
| 22 virtual void OnCustomDictionaryLoaded() = 0; | |
| 23 virtual void OnCustomDictionaryWordAdded(const std::string& word) = 0; | |
| 24 virtual void OnCustomDictionaryWordRemoved(const std::string& word) = 0; | |
| 25 }; | |
| 26 | |
| 20 explicit SpellcheckCustomDictionary(Profile* profile); | 27 explicit SpellcheckCustomDictionary(Profile* profile); |
| 21 virtual ~SpellcheckCustomDictionary(); | 28 virtual ~SpellcheckCustomDictionary(); |
| 22 | 29 |
| 30 // Overridden from SpellcheckDictionary: | |
| 23 virtual void Load() OVERRIDE; | 31 virtual void Load() OVERRIDE; |
| 24 void WriteWordToCustomDictionary(const std::string& word); | |
| 25 | 32 |
| 26 // Returns true if successful. False otherwise. Takes ownership of | 33 const chrome::spellcheck_common::WordList& GetWords() const; |
| 27 // custom_words and replaces pointer with an empty vector. | 34 |
| 28 bool SetCustomWordList(chrome::spellcheck_common::WordList* custom_words); | 35 // Returns a newly allocated list of words read from custom dictionary file. |
|
rpetterson
2012/11/14 19:47:09
Who owns this new list? Can you add that to the co
please use gerrit instead
2012/11/14 22:54:46
The caller owns this new list. Added to the commen
| |
| 29 const chrome::spellcheck_common::WordList& GetCustomWords() const; | 36 chrome::spellcheck_common::WordList* LoadDictionary(); |
| 30 void CustomWordAddedLocally(const std::string& word); | 37 |
| 31 void LoadDictionaryIntoCustomWordList( | 38 void LoadDictionaryIntoCustomWordList( |
| 32 chrome::spellcheck_common::WordList* custom_words); | 39 chrome::spellcheck_common::WordList* custom_words); |
| 33 | 40 |
| 41 // The reply point for PostTaskAndReplyWithResult. Called when LoadDictionary | |
| 42 // is finished reading words from custom dictionary file. Takes ownership of | |
| 43 // custom_words and replaces pointer with an empty vector. | |
| 44 void SetCustomWordList(chrome::spellcheck_common::WordList* custom_words); | |
| 45 | |
| 34 // Adds the given word to the custom words list and inform renderer of the | 46 // Adds the given word to the custom words list and inform renderer of the |
| 35 // update. | 47 // update. |
| 36 void AddWord(const std::string& word); | 48 void AddWord(const std::string& word); |
| 37 | 49 |
| 50 void CustomWordAddedLocally(const std::string& word); | |
| 51 void WriteWordToCustomDictionary(const std::string& word); | |
| 52 | |
| 38 // The reply point for PostTaskAndReply. Called when AddWord is finished | 53 // The reply point for PostTaskAndReply. Called when AddWord is finished |
| 39 // adding a word in the background. | 54 // adding a word in the background. |
| 40 void AddWordComplete(const std::string& word); | 55 void AddWordComplete(const std::string& word); |
| 41 | 56 |
| 57 // Removes the given word from the custom words list and inform renderer of | |
| 58 // the update. | |
| 59 void RemoveWord(const std::string& word); | |
| 60 | |
| 61 void CustomWordRemovedLocally(const std::string& word); | |
| 62 void EraseWordFromCustomDictionary(const std::string& word); | |
| 63 | |
| 64 // The reply point for PostTaskAndReply. Called when RemoveWord is finished | |
| 65 // removing a word in the background. | |
| 66 void RemoveWordComplete(const std::string& word); | |
| 67 | |
| 68 void AddObserver(Observer* observer); | |
| 69 void RemoveObserver(Observer* observer); | |
| 70 | |
| 42 private: | 71 private: |
| 43 // In-memory cache of the custom words file. | 72 // In-memory cache of the custom words file. |
| 44 chrome::spellcheck_common::WordList custom_words_; | 73 chrome::spellcheck_common::WordList words_; |
| 45 | 74 |
| 46 // A path for custom dictionary per profile. | 75 // A path for custom dictionary per profile. |
| 47 FilePath custom_dictionary_path_; | 76 FilePath custom_dictionary_path_; |
| 48 | 77 |
| 49 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_; | 78 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_; |
| 50 | 79 |
| 80 std::vector<Observer*> observers_; | |
| 81 | |
| 51 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary); | 82 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary); |
| 52 }; | 83 }; |
| 53 | 84 |
| 54 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ | 85 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ |
| OLD | NEW |