| 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; | 28 class MessageLoop; |
| 29 class URLRequestContext; | |
| 30 class URLFetcher; | 29 class URLFetcher; |
| 30 class URLRequestContextGetter; |
| 31 | 31 |
| 32 namespace file_util { | 32 namespace file_util { |
| 33 class MemoryMappedFile; | 33 class MemoryMappedFile; |
| 34 } | 34 } |
| 35 | 35 |
| 36 // The Browser's Spell Checker. It checks and suggests corrections. | 36 // The Browser's Spell Checker. It checks and suggests corrections. |
| 37 // | 37 // |
| 38 // This object is not threadsafe. In normal usage (not unit tests) it lives on | 38 // This object is not threadsafe. In normal usage (not unit tests) it lives on |
| 39 // the I/O thread of the browser. It is threadsafe refcounted so that I/O thread | 39 // the I/O thread of the browser. It is threadsafe refcounted so that I/O thread |
| 40 // and the profile on the main thread (which gives out references to it) can | 40 // and the profile on the main thread (which gives out references to it) can |
| 41 // keep it. However, all usage of this must be on the I/O thread. | 41 // keep it. However, all usage of this must be on the I/O thread. |
| 42 // | 42 // |
| 43 // This object should also be deleted on the I/O thread only. It owns a | 43 // This object should also be deleted on the I/O thread only. It owns a |
| 44 // reference to URLRequestContext which in turn owns the cache, etc. and must be | 44 // reference to URLRequestContext which in turn owns the cache, etc. and must be |
| 45 // deleted on the I/O thread itself. | 45 // deleted on the I/O thread itself. |
| 46 class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>, | 46 class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>, |
| 47 public URLFetcher::Delegate { | 47 public URLFetcher::Delegate { |
| 48 public: | 48 public: |
| 49 // Creates the spellchecker by reading dictionaries from the given directory, | 49 // Creates the spellchecker by reading dictionaries from the given directory, |
| 50 // and defaulting to the given language. Both strings must be provided. | 50 // and defaulting to the given language. Both strings must be provided. |
| 51 // | 51 // |
| 52 // The request context is used to download dictionaries if they do not exist. | 52 // The request context is used to download dictionaries if they do not exist. |
| 53 // This can be NULL if you don't want this (like in tests). | 53 // This can be NULL if you don't want this (like in tests). |
| 54 // The |custom_dictionary_file_name| should be left blank so that Spellchecker | 54 // The |custom_dictionary_file_name| should be left blank so that Spellchecker |
| 55 // can figure out the custom dictionary file. It is non empty only for unit | 55 // can figure out the custom dictionary file. It is non empty only for unit |
| 56 // testing. | 56 // testing. |
| 57 SpellChecker(const FilePath& dict_dir, | 57 SpellChecker(const FilePath& dict_dir, |
| 58 const std::string& language, | 58 const std::string& language, |
| 59 URLRequestContext* request_context, | 59 URLRequestContextGetter* request_context_getter, |
| 60 const FilePath& custom_dictionary_file_name); | 60 const FilePath& custom_dictionary_file_name); |
| 61 | 61 |
| 62 // Only delete on the I/O thread (see above). | 62 // Only delete on the I/O thread (see above). |
| 63 ~SpellChecker(); | 63 ~SpellChecker(); |
| 64 | 64 |
| 65 // SpellCheck a word. | 65 // SpellCheck a word. |
| 66 // Returns true if spelled correctly, false otherwise. | 66 // Returns true if spelled correctly, false otherwise. |
| 67 // If the spellchecker failed to initialize, always returns true. | 67 // If the spellchecker failed to initialize, always returns true. |
| 68 // The |tag| parameter should either be a unique identifier for the document | 68 // The |tag| parameter should either be a unique identifier for the document |
| 69 // that the word came from (if the current platform requires it), or 0. | 69 // that the word came from (if the current platform requires it), or 0. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // constructor since that's on a different thread). | 203 // constructor since that's on a different thread). |
| 204 MessageLoop* worker_loop_; | 204 MessageLoop* worker_loop_; |
| 205 | 205 |
| 206 // Flag indicating whether we tried to download the dictionary file. | 206 // Flag indicating whether we tried to download the dictionary file. |
| 207 bool tried_to_download_dictionary_file_; | 207 bool tried_to_download_dictionary_file_; |
| 208 | 208 |
| 209 // File Thread Message Loop. | 209 // File Thread Message Loop. |
| 210 MessageLoop* file_loop_; | 210 MessageLoop* file_loop_; |
| 211 | 211 |
| 212 // Used for requests. MAY BE NULL which means don't try to download. | 212 // Used for requests. MAY BE NULL which means don't try to download. |
| 213 URLRequestContext* url_request_context_; | 213 URLRequestContextGetter* request_context_getter_; |
| 214 | 214 |
| 215 // True when we're downloading or saving a dictionary. | 215 // True when we're downloading or saving a dictionary. |
| 216 bool obtaining_dictionary_; | 216 bool obtaining_dictionary_; |
| 217 | 217 |
| 218 // Remember state for auto spell correct. | 218 // Remember state for auto spell correct. |
| 219 bool auto_spell_correct_turned_on_; | 219 bool auto_spell_correct_turned_on_; |
| 220 | 220 |
| 221 // True if a platform-specific spellchecking engine is being used, | 221 // True if a platform-specific spellchecking engine is being used, |
| 222 // and False if hunspell is being used. | 222 // and False if hunspell is being used. |
| 223 bool is_using_platform_spelling_engine_; | 223 bool is_using_platform_spelling_engine_; |
| 224 | 224 |
| 225 // URLFetcher to download a file in memory. | 225 // URLFetcher to download a file in memory. |
| 226 scoped_ptr<URLFetcher> fetcher_; | 226 scoped_ptr<URLFetcher> fetcher_; |
| 227 | 227 |
| 228 // While Hunspell is loading, we add any new custom words to this queue. | 228 // 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. | 229 // We will add them to |hunspell_| when it is done loading. |
| 230 std::queue<std::string> custom_words_; | 230 std::queue<std::string> custom_words_; |
| 231 | 231 |
| 232 // Used for generating callbacks to spellchecker, since spellchecker is a | 232 // Used for generating callbacks to spellchecker, since spellchecker is a |
| 233 // non-reference counted object. | 233 // non-reference counted object. |
| 234 ScopedRunnableMethodFactory<SpellChecker> method_factory_; | 234 ScopedRunnableMethodFactory<SpellChecker> method_factory_; |
| 235 | 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(SpellChecker); | 236 DISALLOW_COPY_AND_ASSIGN(SpellChecker); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 #endif // CHROME_BROWSER_SPELLCHECKER_H_ | 239 #endif // CHROME_BROWSER_SPELLCHECKER_H_ |
| OLD | NEW |