Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/extensions/api/language_settings_private/language_settings_private_delegate.h

Issue 1283603002: Implement langageSettingsPrivate API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@LanguageSettingsAPIIDLChanges
Patch Set: Fix const error in l10n_util_collator Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 typedef std::vector<base::WeakPtr<SpellcheckHunspellDictionary>>
69 WeakDictionaries;
70
71 // Updates the dictionaries that are used for spellchecking.
72 void RefreshDictionaries(bool was_listening, bool should_listen);
73
74 // Returns the hunspell dictionaries that are used for spellchecking.
75 const WeakDictionaries& GetHunspellDictionaries();
76
39 // If there are any JavaScript listeners registered for spellcheck events, 77 // If there are any JavaScript listeners registered for spellcheck events,
40 // ensures we are registered for change notifications. Otherwise, unregisters 78 // ensures we are registered for change notifications. Otherwise, unregisters
41 // any observers. 79 // any observers.
42 void StartOrStopListeningForSpellcheckChanges(); 80 void StartOrStopListeningForSpellcheckChanges();
43 81
82 // Handles the preference for which languages should be used for spellcheck
83 // by resetting the dictionaries and broadcasting an event.
84 void OnSpellcheckDictionariesChanged();
85
86 // Broadcasts an event with the list of spellcheck dictionary statuses.
87 void BroadcastDictionariesChangedEvent();
88
89 // Removes observers from hunspell_dictionaries_.
90 void RemoveDictionaryObservers();
91
92 // The hunspell dictionaries that are used for spellchecking.
93 WeakDictionaries hunspell_dictionaries_;
94
95 // The custom dictionary that is used for spellchecking.
96 SpellcheckCustomDictionary* custom_dictionary_;
97
44 content::BrowserContext* context_; 98 content::BrowserContext* context_;
45 99
46 // True if there are observers listening for spellcheck events. 100 // True if there are observers listening for spellcheck events.
47 bool listening_spellcheck_; 101 bool listening_spellcheck_;
48 102
103 // True if the profile has finished initializing.
104 bool profile_added_;
105
106 content::NotificationRegistrar notification_registrar_;
107
108 PrefChangeRegistrar pref_change_registrar_;
109
49 DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate); 110 DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate);
50 }; 111 };
51 112
52 } // namespace extensions 113 } // namespace extensions
53 114
54 #endif // CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETT INGS_PRIVATE_DELEGATE_H_ 115 #endif // CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETT INGS_PRIVATE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698