| 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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
| 13 #include "chrome/browser/spellchecker/feedback_sender.h" | 13 #include "chrome/browser/spellchecker/feedback_sender.h" |
| 14 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" | 14 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
| 15 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" | 15 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" |
| 16 #include "chrome/common/spellcheck_common.h" | 16 #include "chrome/common/spellcheck_common.h" |
| 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 17 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 20 | 20 |
| 21 class Profile; | 21 class PrefService; |
| 22 class SpellCheckHostMetrics; | 22 class SpellCheckHostMetrics; |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class WaitableEvent; | 25 class WaitableEvent; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class RenderProcessHost; | 29 class RenderProcessHost; |
| 30 class BrowserContext; |
| 30 } | 31 } |
| 31 | 32 |
| 32 // Encapsulates the browser side spellcheck service. There is one of these per | 33 // Encapsulates the browser side spellcheck service. There is one of these per |
| 33 // profile and each is created by the SpellCheckServiceFactory. The | 34 // profile and each is created by the SpellCheckServiceFactory. The |
| 34 // SpellcheckService maintains any per-profile information about spellcheck. | 35 // SpellcheckService maintains any per-profile information about spellcheck. |
| 35 class SpellcheckService : public BrowserContextKeyedService, | 36 class SpellcheckService : public BrowserContextKeyedService, |
| 36 public content::NotificationObserver, | 37 public content::NotificationObserver, |
| 37 public SpellcheckCustomDictionary::Observer, | 38 public SpellcheckCustomDictionary::Observer, |
| 38 public SpellcheckHunspellDictionary::Observer { | 39 public SpellcheckHunspellDictionary::Observer { |
| 39 public: | 40 public: |
| 40 // Event types used for reporting the status of this class and its derived | 41 // Event types used for reporting the status of this class and its derived |
| 41 // classes to browser tests. | 42 // classes to browser tests. |
| 42 enum EventType { | 43 enum EventType { |
| 43 BDICT_NOTINITIALIZED, | 44 BDICT_NOTINITIALIZED, |
| 44 BDICT_CORRUPTED, | 45 BDICT_CORRUPTED, |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 // Dictionary format used for loading an external dictionary. | 48 // Dictionary format used for loading an external dictionary. |
| 48 enum DictionaryFormat { | 49 enum DictionaryFormat { |
| 49 DICT_HUNSPELL, | 50 DICT_HUNSPELL, |
| 50 DICT_TEXT, | 51 DICT_TEXT, |
| 51 DICT_UNKNOWN, | 52 DICT_UNKNOWN, |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 explicit SpellcheckService(Profile* profile); | 55 explicit SpellcheckService(content::BrowserContext* context); |
| 55 virtual ~SpellcheckService(); | 56 virtual ~SpellcheckService(); |
| 56 | 57 |
| 57 // This function computes a vector of strings which are to be displayed in | 58 // This function computes a vector of strings which are to be displayed in |
| 58 // the context menu over a text area for changing spell check languages. It | 59 // the context menu over a text area for changing spell check languages. It |
| 59 // returns the index of the current spell check language in the vector. | 60 // returns the index of the current spell check language in the vector. |
| 60 // TODO(port): this should take a vector of string16, but the implementation | 61 // TODO(port): this should take a vector of string16, but the implementation |
| 61 // has some dependencies in l10n util that need porting first. | 62 // has some dependencies in l10n util that need porting first. |
| 62 static int GetSpellCheckLanguages(Profile* profile, | 63 static int GetSpellCheckLanguages(content::BrowserContext* context, |
| 63 std::vector<std::string>* languages); | 64 std::vector<std::string>* languages); |
| 64 | 65 |
| 65 // Computes a vector of strings which are to be displayed in the context | 66 // Computes a vector of strings which are to be displayed in the context |
| 66 // menu from |accept_languages| and |dictionary_language|. | 67 // menu from |accept_languages| and |dictionary_language|. |
| 67 static void GetSpellCheckLanguagesFromAcceptLanguages( | 68 static void GetSpellCheckLanguagesFromAcceptLanguages( |
| 68 const std::vector<std::string>& accept_languages, | 69 const std::vector<std::string>& accept_languages, |
| 69 const std::string& dictionary_language, | 70 const std::string& dictionary_language, |
| 70 std::vector<std::string>* languages); | 71 std::vector<std::string>* languages); |
| 71 | 72 |
| 72 // Signals the event attached by AttachTestEvent() to report the specified | 73 // Signals the event attached by AttachTestEvent() to report the specified |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // Reacts to a change in user preference on which language should be used for | 143 // Reacts to a change in user preference on which language should be used for |
| 143 // spellchecking. | 144 // spellchecking. |
| 144 void OnSpellCheckDictionaryChanged(); | 145 void OnSpellCheckDictionaryChanged(); |
| 145 | 146 |
| 146 // Notification handler for changes to prefs::kSpellCheckUseSpellingService. | 147 // Notification handler for changes to prefs::kSpellCheckUseSpellingService. |
| 147 void OnUseSpellingServiceChanged(); | 148 void OnUseSpellingServiceChanged(); |
| 148 | 149 |
| 149 PrefChangeRegistrar pref_change_registrar_; | 150 PrefChangeRegistrar pref_change_registrar_; |
| 150 content::NotificationRegistrar registrar_; | 151 content::NotificationRegistrar registrar_; |
| 151 | 152 |
| 152 // A pointer to the profile which this service refers to. | 153 // A pointer to the BrowserContext which this service refers to. |
| 153 Profile* profile_; | 154 content::BrowserContext* context_; |
| 154 | 155 |
| 155 scoped_ptr<SpellCheckHostMetrics> metrics_; | 156 scoped_ptr<SpellCheckHostMetrics> metrics_; |
| 156 | 157 |
| 157 scoped_ptr<SpellcheckCustomDictionary> custom_dictionary_; | 158 scoped_ptr<SpellcheckCustomDictionary> custom_dictionary_; |
| 158 | 159 |
| 159 scoped_ptr<SpellcheckHunspellDictionary> hunspell_dictionary_; | 160 scoped_ptr<SpellcheckHunspellDictionary> hunspell_dictionary_; |
| 160 | 161 |
| 161 scoped_ptr<spellcheck::FeedbackSender> feedback_sender_; | 162 scoped_ptr<spellcheck::FeedbackSender> feedback_sender_; |
| 162 | 163 |
| 163 base::WeakPtrFactory<SpellcheckService> weak_ptr_factory_; | 164 base::WeakPtrFactory<SpellcheckService> weak_ptr_factory_; |
| 164 | 165 |
| 165 DISALLOW_COPY_AND_ASSIGN(SpellcheckService); | 166 DISALLOW_COPY_AND_ASSIGN(SpellcheckService); |
| 166 }; | 167 }; |
| 167 | 168 |
| 168 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ | 169 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_SERVICE_H_ |
| OLD | NEW |