Chromium Code Reviews| Index: chrome/browser/extensions/api/language_settings_private/language_settings_private_delegate.h |
| diff --git a/chrome/browser/extensions/api/language_settings_private/language_settings_private_delegate.h b/chrome/browser/extensions/api/language_settings_private/language_settings_private_delegate.h |
| index 5fec75339f48ae22f30571cf856766c7d802e2bf..e12c3eb0d6ef1888d09e8f3025cf0e3a8e22736e 100644 |
| --- a/chrome/browser/extensions/api/language_settings_private/language_settings_private_delegate.h |
| +++ b/chrome/browser/extensions/api/language_settings_private/language_settings_private_delegate.h |
| @@ -5,8 +5,14 @@ |
| #ifndef CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETTINGS_PRIVATE_DELEGATE_H_ |
| #define CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETTINGS_PRIVATE_DELEGATE_H_ |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/prefs/pref_change_registrar.h" |
| +#include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
| +#include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" |
| #include "chrome/common/extensions/api/language_settings_private.h" |
| #include "components/keyed_service/core/keyed_service.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| #include "extensions/browser/event_router.h" |
| namespace content { |
| @@ -19,12 +25,19 @@ namespace extensions { |
| // languageSettingsPrivate API. |
| class LanguageSettingsPrivateDelegate |
| : public KeyedService, |
| - public EventRouter::Observer { |
| + public EventRouter::Observer, |
| + public content::NotificationObserver, |
| + public SpellcheckHunspellDictionary::Observer, |
| + public SpellcheckCustomDictionary::Observer { |
| public: |
| static LanguageSettingsPrivateDelegate* Create( |
| content::BrowserContext* browser_context); |
| ~LanguageSettingsPrivateDelegate() override; |
| + // Returns the languages and statuses of the enabled spellcheck dictionaries. |
| + ScopedVector<api::language_settings_private::SpellcheckDictionaryStatus> |
| + GetHunspellDictionaryStatuses(); |
| + |
| protected: |
| explicit LanguageSettingsPrivateDelegate(content::BrowserContext* context); |
| @@ -35,17 +48,61 @@ class LanguageSettingsPrivateDelegate |
| void OnListenerAdded(const EventListenerInfo& details) override; |
| void OnListenerRemoved(const EventListenerInfo& details) override; |
| + // content::NotificationObserver implementation. |
| + void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) override; |
| + |
| + // SpellcheckHunspellDictionary::Observer implementation. |
| + void OnHunspellDictionaryInitialized() override; |
| + void OnHunspellDictionaryDownloadBegin() override; |
| + void OnHunspellDictionaryDownloadSuccess() override; |
| + void OnHunspellDictionaryDownloadFailure() override; |
| + |
| + // SpellcheckCustomDictionary::Observer implementation. |
| + void OnCustomDictionaryLoaded() override; |
| + void OnCustomDictionaryChanged( |
| + const SpellcheckCustomDictionary::Change& dictionary_change) override; |
| + |
| private: |
| + // Updates the dictionaries that are used for spellchecking. |
| + void RefreshDictionaries(bool was_listening, bool should_listen); |
| + |
| + // Returns the hunspell dictionaries that are used for spellchecking. |
| + const std::vector<base::WeakPtr<SpellcheckHunspellDictionary>>& |
|
stevenjb
2015/08/11 19:30:19
We should typedef this since it is also used in th
michaelpg
2015/08/14 00:10:49
Done.
|
| + GetHunspellDictionaries(); |
| + |
| // If there are any JavaScript listeners registered for spellcheck events, |
| // ensures we are registered for change notifications. Otherwise, unregisters |
| // any observers. |
| void StartOrStopListeningForSpellcheckChanges(); |
| + // Handles the preference for which languages should be used for spellcheck |
| + // by resetting the dictionaries and broadcasting an event. |
| + void OnSpellcheckDictionariesChanged(); |
| + |
| + // Broadcasts an event with the list of spellcheck dictionary statuses. |
| + void BroadcastDictionariesChangedEvent(); |
| + |
| + // The hunspell dictionaries that are used for spellchecking. |
| + std::vector<base::WeakPtr<SpellcheckHunspellDictionary>> |
| + hunspell_dictionaries_; |
| + |
| + // The custom dictionary that is used for spellchecking. |
| + SpellcheckCustomDictionary* custom_dictionary_; |
| + |
| content::BrowserContext* context_; |
| // True if there are observers listening for spellcheck events. |
| bool listening_spellcheck_; |
| + // True if the profile has finished initializing. |
| + bool profile_added_; |
| + |
| + content::NotificationRegistrar notification_registrar_; |
| + |
| + PrefChangeRegistrar pref_change_registrar_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate); |
| }; |