Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETTING S_PRIVATE_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETTING S_PRIVATE_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETTING S_PRIVATE_DELEGATE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETTING S_PRIVATE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "base/prefs/pref_change_registrar.h" | |
| 10 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" | |
| 11 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" | |
| 8 #include "chrome/common/extensions/api/language_settings_private.h" | 12 #include "chrome/common/extensions/api/language_settings_private.h" |
| 9 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/keyed_service.h" |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 10 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
| 11 | 17 |
| 12 namespace content { | 18 namespace content { |
| 13 class BrowserContext; | 19 class BrowserContext; |
| 14 } | 20 } |
| 15 | 21 |
| 16 namespace extensions { | 22 namespace extensions { |
| 17 | 23 |
| 18 // Observes language settings and routes changes as events to listeners of the | 24 // Observes language settings and routes changes as events to listeners of the |
| 19 // languageSettingsPrivate API. | 25 // languageSettingsPrivate API. |
| 20 class LanguageSettingsPrivateDelegate | 26 class LanguageSettingsPrivateDelegate |
| 21 : public KeyedService, | 27 : public KeyedService, |
| 22 public EventRouter::Observer { | 28 public EventRouter::Observer, |
| 29 public content::NotificationObserver, | |
| 30 public SpellcheckHunspellDictionary::Observer, | |
| 31 public SpellcheckCustomDictionary::Observer { | |
| 23 public: | 32 public: |
| 24 static LanguageSettingsPrivateDelegate* Create( | 33 static LanguageSettingsPrivateDelegate* Create( |
| 25 content::BrowserContext* browser_context); | 34 content::BrowserContext* browser_context); |
| 26 ~LanguageSettingsPrivateDelegate() override; | 35 ~LanguageSettingsPrivateDelegate() override; |
| 27 | 36 |
| 37 // Returns the languages and statuses of the enabled spellcheck dictionaries. | |
| 38 ScopedVector<api::language_settings_private::SpellcheckDictionaryStatus> | |
| 39 GetHunspellDictionaryStatuses(); | |
| 40 | |
| 28 protected: | 41 protected: |
| 29 explicit LanguageSettingsPrivateDelegate(content::BrowserContext* context); | 42 explicit LanguageSettingsPrivateDelegate(content::BrowserContext* context); |
| 30 | 43 |
| 31 // KeyedService implementation. | 44 // KeyedService implementation. |
| 32 void Shutdown() override; | 45 void Shutdown() override; |
| 33 | 46 |
| 34 // EventRouter::Observer implementation. | 47 // EventRouter::Observer implementation. |
| 35 void OnListenerAdded(const EventListenerInfo& details) override; | 48 void OnListenerAdded(const EventListenerInfo& details) override; |
| 36 void OnListenerRemoved(const EventListenerInfo& details) override; | 49 void OnListenerRemoved(const EventListenerInfo& details) override; |
| 37 | 50 |
| 51 // content::NotificationObserver implementation. | |
| 52 void Observe(int type, | |
| 53 const content::NotificationSource& source, | |
| 54 const content::NotificationDetails& details) override; | |
| 55 | |
| 56 // SpellcheckHunspellDictionary::Observer implementation. | |
| 57 void OnHunspellDictionaryInitialized() override; | |
| 58 void OnHunspellDictionaryDownloadBegin() override; | |
| 59 void OnHunspellDictionaryDownloadSuccess() override; | |
| 60 void OnHunspellDictionaryDownloadFailure() override; | |
| 61 | |
| 62 // SpellcheckCustomDictionary::Observer implementation. | |
| 63 void OnCustomDictionaryLoaded() override; | |
| 64 void OnCustomDictionaryChanged( | |
| 65 const SpellcheckCustomDictionary::Change& dictionary_change) override; | |
| 66 | |
| 38 private: | 67 private: |
| 68 // Updates the dictionaries that are used for spellchecking. | |
| 69 void RefreshDictionaries(bool was_listening, bool should_listen); | |
| 70 | |
| 71 // Returns the hunspell dictionaries that are used for spellchecking. | |
| 72 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.
| |
| 73 GetHunspellDictionaries(); | |
| 74 | |
| 39 // If there are any JavaScript listeners registered for spellcheck events, | 75 // If there are any JavaScript listeners registered for spellcheck events, |
| 40 // ensures we are registered for change notifications. Otherwise, unregisters | 76 // ensures we are registered for change notifications. Otherwise, unregisters |
| 41 // any observers. | 77 // any observers. |
| 42 void StartOrStopListeningForSpellcheckChanges(); | 78 void StartOrStopListeningForSpellcheckChanges(); |
| 43 | 79 |
| 80 // Handles the preference for which languages should be used for spellcheck | |
| 81 // by resetting the dictionaries and broadcasting an event. | |
| 82 void OnSpellcheckDictionariesChanged(); | |
| 83 | |
| 84 // Broadcasts an event with the list of spellcheck dictionary statuses. | |
| 85 void BroadcastDictionariesChangedEvent(); | |
| 86 | |
| 87 // The hunspell dictionaries that are used for spellchecking. | |
| 88 std::vector<base::WeakPtr<SpellcheckHunspellDictionary>> | |
| 89 hunspell_dictionaries_; | |
| 90 | |
| 91 // The custom dictionary that is used for spellchecking. | |
| 92 SpellcheckCustomDictionary* custom_dictionary_; | |
| 93 | |
| 44 content::BrowserContext* context_; | 94 content::BrowserContext* context_; |
| 45 | 95 |
| 46 // True if there are observers listening for spellcheck events. | 96 // True if there are observers listening for spellcheck events. |
| 47 bool listening_spellcheck_; | 97 bool listening_spellcheck_; |
| 48 | 98 |
| 99 // True if the profile has finished initializing. | |
| 100 bool profile_added_; | |
| 101 | |
| 102 content::NotificationRegistrar notification_registrar_; | |
| 103 | |
| 104 PrefChangeRegistrar pref_change_registrar_; | |
| 105 | |
| 49 DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate); | 106 DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate); |
| 50 }; | 107 }; |
| 51 | 108 |
| 52 } // namespace extensions | 109 } // namespace extensions |
| 53 | 110 |
| 54 #endif // CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETT INGS_PRIVATE_DELEGATE_H_ | 111 #endif // CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETT INGS_PRIVATE_DELEGATE_H_ |
| OLD | NEW |