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 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 // Adds |word| in this change. | 38 // Adds |word| in this change. |
39 void AddWord(const std::string& word); | 39 void AddWord(const std::string& word); |
40 | 40 |
41 // Removes |word| in this change. | 41 // Removes |word| in this change. |
42 void RemoveWord(const std::string& word); | 42 void RemoveWord(const std::string& word); |
43 | 43 |
44 // Prepares this change to be applied to |words| by removing duplicate and | 44 // Prepares this change to be applied to |words| by removing duplicate and |
45 // invalid words from words to be added, removing missing words from words | 45 // invalid words from words to be added, removing missing words from words |
46 // to be removed, and sorting both lists of words. Assumes that |words| is | 46 // to be removed, and sorting both lists of words. Assumes that |words| is |
47 // sorted. Returns a bitmap of |ChangeSanitationResult| values. | 47 // sorted. Returns a bitmap of |ChangeSanitationResult| values. |
48 int Sanitize(const chrome::spellcheck_common::WordList& words); | 48 int Sanitize(const chrome::spellcheck_common::WordSet& words); |
49 | 49 |
50 // Returns the words to be added in this change. | 50 // Returns the words to be added in this change. |
51 const chrome::spellcheck_common::WordList& to_add() const; | 51 const chrome::spellcheck_common::WordList& to_add() const; |
52 | 52 |
53 // Returns the words to be removed in this change. | 53 // Returns the words to be removed in this change. |
54 const chrome::spellcheck_common::WordList& to_remove() const; | 54 const chrome::spellcheck_common::WordList& to_remove() const; |
55 | 55 |
56 // Returns true if there are no changes to be made. Otherwise returns false. | 56 // Returns true if there are no changes to be made. Otherwise returns false. |
57 bool empty() const; | 57 bool empty() const; |
58 | 58 |
(...skipping 12 matching lines...) Expand all Loading... |
71 virtual void OnCustomDictionaryLoaded() = 0; | 71 virtual void OnCustomDictionaryLoaded() = 0; |
72 | 72 |
73 // Called when the custom dictionary has been changed. | 73 // Called when the custom dictionary has been changed. |
74 virtual void OnCustomDictionaryChanged(const Change& dictionary_change) = 0; | 74 virtual void OnCustomDictionaryChanged(const Change& dictionary_change) = 0; |
75 }; | 75 }; |
76 | 76 |
77 explicit SpellcheckCustomDictionary(const base::FilePath& path); | 77 explicit SpellcheckCustomDictionary(const base::FilePath& path); |
78 virtual ~SpellcheckCustomDictionary(); | 78 virtual ~SpellcheckCustomDictionary(); |
79 | 79 |
80 // Returns the in-memory cache of words in the custom dictionary. | 80 // Returns the in-memory cache of words in the custom dictionary. |
81 const chrome::spellcheck_common::WordList& GetWords() const; | 81 const chrome::spellcheck_common::WordSet& GetWords() const; |
82 | 82 |
83 // Adds |word| to the dictionary, schedules a write to disk, and notifies | 83 // Adds |word| to the dictionary, schedules a write to disk, and notifies |
84 // observers of the change. Returns true if |word| is valid and not a | 84 // observers of the change. Returns true if |word| is valid and not a |
85 // duplicate. Otherwise returns false. | 85 // duplicate. Otherwise returns false. |
86 bool AddWord(const std::string& word); | 86 bool AddWord(const std::string& word); |
87 | 87 |
88 // Removes |word| from the dictionary, schedules a write to disk, and notifies | 88 // Removes |word| from the dictionary, schedules a write to disk, and notifies |
89 // observers of the change. Returns true if |word| was found. Otherwise | 89 // observers of the change. Returns true if |word| was found. Otherwise |
90 // returns false. | 90 // returns false. |
91 bool RemoveWord(const std::string& word); | 91 bool RemoveWord(const std::string& word); |
92 | 92 |
| 93 // Returns true if the dictionary contains |word|. Otherwise returns false. |
| 94 bool HasWord(const std::string& word); |
| 95 |
93 // Adds |observer| to be notified of dictionary events and changes. | 96 // Adds |observer| to be notified of dictionary events and changes. |
94 void AddObserver(Observer* observer); | 97 void AddObserver(Observer* observer); |
95 | 98 |
96 // Removes |observer| to stop notifications of dictionary events and changes. | 99 // Removes |observer| to stop notifications of dictionary events and changes. |
97 void RemoveObserver(Observer* observer); | 100 void RemoveObserver(Observer* observer); |
98 | 101 |
99 // Returns true if the dictionary has been loaded. Otherwise returns false. | 102 // Returns true if the dictionary has been loaded. Otherwise returns false. |
100 bool IsLoaded(); | 103 bool IsLoaded(); |
101 | 104 |
102 // Returns true if the dictionary is being synced. Otherwise returns false. | 105 // Returns true if the dictionary is being synced. Otherwise returns false. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // Notifies the sync service of the |dictionary_change|. Syncs up to the | 154 // Notifies the sync service of the |dictionary_change|. Syncs up to the |
152 // maximum syncable words on the server. Disables syncing of this dictionary | 155 // maximum syncable words on the server. Disables syncing of this dictionary |
153 // if the server contains the maximum number of syncable words. | 156 // if the server contains the maximum number of syncable words. |
154 syncer::SyncError Sync(const Change& dictionary_change); | 157 syncer::SyncError Sync(const Change& dictionary_change); |
155 | 158 |
156 // Notifies observers of the dictionary change if the dictionary has been | 159 // Notifies observers of the dictionary change if the dictionary has been |
157 // changed. | 160 // changed. |
158 void Notify(const Change& dictionary_change); | 161 void Notify(const Change& dictionary_change); |
159 | 162 |
160 // In-memory cache of the custom words file. | 163 // In-memory cache of the custom words file. |
161 chrome::spellcheck_common::WordList words_; | 164 chrome::spellcheck_common::WordSet words_; |
162 | 165 |
163 // A path for custom dictionary. | 166 // A path for custom dictionary. |
164 base::FilePath custom_dictionary_path_; | 167 base::FilePath custom_dictionary_path_; |
165 | 168 |
166 // Used to create weak pointers for an instance of this class. | 169 // Used to create weak pointers for an instance of this class. |
167 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_; | 170 base::WeakPtrFactory<SpellcheckCustomDictionary> weak_ptr_factory_; |
168 | 171 |
169 // Observers for changes in dictionary load status and content changes. | 172 // Observers for changes in dictionary load status and content changes. |
170 ObserverList<Observer> observers_; | 173 ObserverList<Observer> observers_; |
171 | 174 |
172 // Used to send local changes to the sync infrastructure. | 175 // Used to send local changes to the sync infrastructure. |
173 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 176 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
174 | 177 |
175 // Used to send sync-related errors to the sync infrastructure. | 178 // Used to send sync-related errors to the sync infrastructure. |
176 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_; | 179 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_; |
177 | 180 |
178 // True if the dictionary has been loaded. Otherwise false. | 181 // True if the dictionary has been loaded. Otherwise false. |
179 bool is_loaded_; | 182 bool is_loaded_; |
180 | 183 |
181 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary); | 184 DISALLOW_COPY_AND_ASSIGN(SpellcheckCustomDictionary); |
182 }; | 185 }; |
183 | 186 |
184 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ | 187 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_CUSTOM_DICTIONARY_H_ |
OLD | NEW |