OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_H_ |
6 #define CHROME_BROWSER_SPELLCHECKER_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/net/url_fetcher.h" | 17 #include "chrome/browser/net/url_fetcher.h" |
18 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/profile.h" |
19 #include "chrome/browser/spellcheck_worditerator.h" | 19 #include "chrome/browser/spellcheck_worditerator.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/pref_member.h" | 21 #include "chrome/common/pref_member.h" |
22 #include "unicode/uscript.h" | 22 #include "unicode/uscript.h" |
23 | 23 |
24 class FilePath; | 24 class FilePath; |
25 class Hunspell; | 25 class Hunspell; |
26 class PrefService; | 26 class PrefService; |
27 class Profile; | 27 class Profile; |
28 class MessageLoop; | |
29 class URLFetcher; | 28 class URLFetcher; |
30 class URLRequestContextGetter; | 29 class URLRequestContextGetter; |
31 | 30 |
32 namespace file_util { | 31 namespace file_util { |
33 class MemoryMappedFile; | 32 class MemoryMappedFile; |
34 } | 33 } |
35 | 34 |
36 // The Browser's Spell Checker. It checks and suggests corrections. | 35 // The Browser's Spell Checker. It checks and suggests corrections. |
37 // | 36 // |
38 // This object is not threadsafe. In normal usage (not unit tests) it lives on | 37 // This object is not threadsafe. In normal usage (not unit tests) it lives on |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // spell check language. For example, for hi, it returns hi-IN. | 108 // spell check language. For example, for hi, it returns hi-IN. |
110 static std::string GetSpellCheckLanguageRegion(std::string input_language); | 109 static std::string GetSpellCheckLanguageRegion(std::string input_language); |
111 | 110 |
112 // This function returns ll (language code) from ll-RR where 'RR' (region | 111 // This function returns ll (language code) from ll-RR where 'RR' (region |
113 // code) is redundant. However, if the region code matters, it's preserved. | 112 // code) is redundant. However, if the region code matters, it's preserved. |
114 // That is, it returns 'hi' and 'en-GB' for 'hi-IN' and 'en-GB' respectively. | 113 // That is, it returns 'hi' and 'en-GB' for 'hi-IN' and 'en-GB' respectively. |
115 static std::string GetLanguageFromLanguageRegion(std::string input_language); | 114 static std::string GetLanguageFromLanguageRegion(std::string input_language); |
116 | 115 |
117 private: | 116 private: |
118 friend class ReadDictionaryTask; | 117 friend class ReadDictionaryTask; |
| 118 FRIEND_TEST(SpellCheckTest, SpellCheckStrings_EN_US); |
| 119 FRIEND_TEST(SpellCheckTest, SpellCheckSuggestions_EN_US); |
| 120 FRIEND_TEST(SpellCheckTest, SpellCheckText); |
| 121 FRIEND_TEST(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US); |
| 122 FRIEND_TEST(SpellCheckTest, |
| 123 DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US); |
| 124 FRIEND_TEST(SpellCheckTest, GetAutoCorrectionWord_EN_US); |
| 125 FRIEND_TEST(SpellCheckTest, IgnoreWords_EN_US); |
119 | 126 |
120 // URLFetcher::Delegate implementation. Called when we finish downloading the | 127 // URLFetcher::Delegate implementation. Called when we finish downloading the |
121 // spellcheck dictionary; saves the dictionary to disk. | 128 // spellcheck dictionary; saves the dictionary to disk. |
122 virtual void OnURLFetchComplete(const URLFetcher* source, | 129 virtual void OnURLFetchComplete(const URLFetcher* source, |
123 const GURL& url, | 130 const GURL& url, |
124 const URLRequestStatus& status, | 131 const URLRequestStatus& status, |
125 int response_code, | 132 int response_code, |
126 const ResponseCookies& cookies, | 133 const ResponseCookies& cookies, |
127 const std::string& data); | 134 const std::string& data); |
128 | 135 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // created on the UI thread. This checks calls to SpellCheckWord and the | 206 // created on the UI thread. This checks calls to SpellCheckWord and the |
200 // destructor to make sure we're only ever running on the same thread. | 207 // destructor to make sure we're only ever running on the same thread. |
201 // | 208 // |
202 // This will be NULL if it is not initialized yet (not initialized in the | 209 // This will be NULL if it is not initialized yet (not initialized in the |
203 // constructor since that's on a different thread). | 210 // constructor since that's on a different thread). |
204 MessageLoop* worker_loop_; | 211 MessageLoop* worker_loop_; |
205 | 212 |
206 // Flag indicating whether we tried to download the dictionary file. | 213 // Flag indicating whether we tried to download the dictionary file. |
207 bool tried_to_download_dictionary_file_; | 214 bool tried_to_download_dictionary_file_; |
208 | 215 |
209 // File Thread Message Loop. | |
210 MessageLoop* file_loop_; | |
211 | |
212 // Used for requests. MAY BE NULL which means don't try to download. | 216 // Used for requests. MAY BE NULL which means don't try to download. |
213 URLRequestContextGetter* request_context_getter_; | 217 URLRequestContextGetter* request_context_getter_; |
214 | 218 |
215 // True when we're downloading or saving a dictionary. | 219 // True when we're downloading or saving a dictionary. |
216 bool obtaining_dictionary_; | 220 bool obtaining_dictionary_; |
217 | 221 |
218 // Remember state for auto spell correct. | 222 // Remember state for auto spell correct. |
219 bool auto_spell_correct_turned_on_; | 223 bool auto_spell_correct_turned_on_; |
220 | 224 |
221 // True if a platform-specific spellchecking engine is being used, | 225 // True if a platform-specific spellchecking engine is being used, |
222 // and False if hunspell is being used. | 226 // and False if hunspell is being used. |
223 bool is_using_platform_spelling_engine_; | 227 bool is_using_platform_spelling_engine_; |
224 | 228 |
225 // URLFetcher to download a file in memory. | 229 // URLFetcher to download a file in memory. |
226 scoped_ptr<URLFetcher> fetcher_; | 230 scoped_ptr<URLFetcher> fetcher_; |
227 | 231 |
228 // While Hunspell is loading, we add any new custom words to this queue. | 232 // While Hunspell is loading, we add any new custom words to this queue. |
229 // We will add them to |hunspell_| when it is done loading. | 233 // We will add them to |hunspell_| when it is done loading. |
230 std::queue<std::string> custom_words_; | 234 std::queue<std::string> custom_words_; |
231 | 235 |
232 // Used for generating callbacks to spellchecker, since spellchecker is a | 236 // Used for generating callbacks to spellchecker, since spellchecker is a |
233 // non-reference counted object. | 237 // non-reference counted object. |
234 ScopedRunnableMethodFactory<SpellChecker> method_factory_; | 238 ScopedRunnableMethodFactory<SpellChecker> method_factory_; |
235 | 239 |
236 DISALLOW_COPY_AND_ASSIGN(SpellChecker); | 240 DISALLOW_COPY_AND_ASSIGN(SpellChecker); |
237 }; | 241 }; |
238 | 242 |
239 #endif // CHROME_BROWSER_SPELLCHECKER_H_ | 243 #endif // CHROME_BROWSER_SPELLCHECKER_H_ |
OLD | NEW |