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

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: 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 std::vector<
39 scoped_ptr<api::language_settings_private::SpellcheckDictionaryStatus>>
stevenjb 2015/08/10 16:13:54 ScopedVector?
michaelpg 2015/08/10 23:31:51 Done.
40 GetHunspellDictionaryStatuses();
41
28 protected: 42 protected:
29 explicit LanguageSettingsPrivateDelegate(content::BrowserContext* context); 43 explicit LanguageSettingsPrivateDelegate(content::BrowserContext* context);
30 44
31 // KeyedService implementation. 45 // KeyedService implementation.
32 void Shutdown() override; 46 void Shutdown() override;
33 47
34 // EventRouter::Observer implementation. 48 // EventRouter::Observer implementation.
35 void OnListenerAdded(const EventListenerInfo& details) override; 49 void OnListenerAdded(const EventListenerInfo& details) override;
36 void OnListenerRemoved(const EventListenerInfo& details) override; 50 void OnListenerRemoved(const EventListenerInfo& details) override;
37 51
52 // content::NotificationObserver implementation.
53 void Observe(int type,
54 const content::NotificationSource& source,
55 const content::NotificationDetails& details) override;
56
57 // SpellcheckHunspellDictionary::Observer implementation.
58 void OnHunspellDictionaryInitialized() override;
59 void OnHunspellDictionaryDownloadBegin() override;
60 void OnHunspellDictionaryDownloadSuccess() override;
61 void OnHunspellDictionaryDownloadFailure() override;
62
63 // SpellcheckCustomDictionary::Observer implementation.
64 void OnCustomDictionaryLoaded() override;
65 void OnCustomDictionaryChanged(
66 const SpellcheckCustomDictionary::Change& dictionary_change) override;
67
38 private: 68 private:
69 // Updates the dictionaries that are used for spellchecking.
70 void RefreshDictionaries(bool was_listening, bool should_listen);
71
72 // Returns the hunspell dictionaries that are used for spellchecking.
73 const std::vector<base::WeakPtr<SpellcheckHunspellDictionary>>&
74 GetHunspellDictionaries();
75
39 // If there are any JavaScript listeners registered for spellcheck events, 76 // If there are any JavaScript listeners registered for spellcheck events,
40 // ensures we are registered for change notifications. Otherwise, unregisters 77 // ensures we are registered for change notifications. Otherwise, unregisters
41 // any observers. 78 // any observers.
42 void StartOrStopListeningForSpellcheckChanges(); 79 void StartOrStopListeningForSpellcheckChanges();
43 80
81 // Handles the preference for which languages should be used for spellcheck
82 // by resetting the dictionaries and broadcasting an event.
83 void OnSpellcheckDictionariesChanged();
84
85 // Broadcasts an event with the list of spellcheck dictionary statuses.
86 void BroadcastDictionariesChangedEvent();
87
88 // The hunspell dictionaries that are used for spellchecking.
89 std::vector<base::WeakPtr<SpellcheckHunspellDictionary>>
90 hunspell_dictionaries_;
91
92 // The custom dictionary that is used for spellchecking.
93 SpellcheckCustomDictionary* custom_dictionary_;
94
44 content::BrowserContext* context_; 95 content::BrowserContext* context_;
45 96
46 // True if there are observers listening for spellcheck events. 97 // True if there are observers listening for spellcheck events.
47 bool listening_spellcheck_; 98 bool listening_spellcheck_;
48 99
100 // True if the profile has finished initializing.
101 bool profile_added_;
102
103 content::NotificationRegistrar notification_registrar_;
104
105 PrefChangeRegistrar pref_change_registrar_;
106
49 DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate); 107 DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateDelegate);
50 }; 108 };
51 109
52 } // namespace extensions 110 } // namespace extensions
53 111
54 #endif // CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETT INGS_PRIVATE_DELEGATE_H_ 112 #endif // CHROME_BROWSER_EXTENSIONS_API_LANGUAGE_SETTINGS_PRIVATE_LANGUAGE_SETT INGS_PRIVATE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698