OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT_RO
UTER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT_RO
UTER_H_ |
| 7 |
| 8 #include "base/prefs/pref_change_registrar.h" |
| 9 #include "components/keyed_service/core/keyed_service.h" |
| 10 #include "extensions/browser/event_router.h" |
| 11 |
| 12 namespace content { |
| 13 class BrowserContext; |
| 14 } |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 class SettingsPrivateDelegate; |
| 19 |
| 20 // This is an event router that will observe listeners to pref changes on the |
| 21 // appropriate pref service(s) and notify listeners on the JavaScript |
| 22 // settingsPrivate API. |
| 23 class SettingsPrivateEventRouter : public KeyedService, |
| 24 public EventRouter::Observer { |
| 25 public: |
| 26 static SettingsPrivateEventRouter* Create( |
| 27 content::BrowserContext* browser_context); |
| 28 ~SettingsPrivateEventRouter() override; |
| 29 |
| 30 protected: |
| 31 SettingsPrivateEventRouter() {} |
| 32 explicit SettingsPrivateEventRouter(content::BrowserContext* context); |
| 33 |
| 34 // KeyedService overrides: |
| 35 void Shutdown() override; |
| 36 |
| 37 // EventRouter::Observer overrides: |
| 38 void OnListenerAdded(const EventListenerInfo& details) override; |
| 39 void OnListenerRemoved(const EventListenerInfo& details) override; |
| 40 |
| 41 // This registrar monitors for user prefs changes. |
| 42 PrefChangeRegistrar user_prefs_registrar_; |
| 43 |
| 44 // This registrar monitors for local state changes. |
| 45 PrefChangeRegistrar local_state_registrar_; |
| 46 |
| 47 private: |
| 48 // Decide if we should listen for pref changes or not. If there are any |
| 49 // JavaScript listeners registered for the onPrefsChanged event, then we |
| 50 // want to register for change notification from the PrefChangeRegistrar. |
| 51 // Otherwise, we want to unregister and not be listening for pref changes. |
| 52 void StartOrStopListeningForPrefsChanges(); |
| 53 |
| 54 void OnPreferenceChanged(PrefService* service, const std::string& pref_name); |
| 55 |
| 56 PrefChangeRegistrar* FindRegistrarForPref(const std::string& pref_name); |
| 57 |
| 58 content::BrowserContext* context_; |
| 59 bool listening_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateEventRouter); |
| 62 }; |
| 63 |
| 64 } // namespace extensions |
| 65 |
| 66 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT
_ROUTER_H_ |
OLD | NEW |