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_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT_RO
UTER_H_ | 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_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT_RO
UTER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
12 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" | 13 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" |
13 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
14 #include "components/prefs/pref_change_registrar.h" | 15 #include "components/prefs/pref_change_registrar.h" |
15 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class BrowserContext; | 19 class BrowserContext; |
19 } | 20 } |
20 | 21 |
(...skipping 27 matching lines...) Expand all Loading... |
48 | 49 |
49 private: | 50 private: |
50 // Decide if we should listen for pref changes or not. If there are any | 51 // Decide if we should listen for pref changes or not. If there are any |
51 // JavaScript listeners registered for the onPrefsChanged event, then we | 52 // JavaScript listeners registered for the onPrefsChanged event, then we |
52 // want to register for change notification from the PrefChangeRegistrar. | 53 // want to register for change notification from the PrefChangeRegistrar. |
53 // Otherwise, we want to unregister and not be listening for pref changes. | 54 // Otherwise, we want to unregister and not be listening for pref changes. |
54 void StartOrStopListeningForPrefsChanges(); | 55 void StartOrStopListeningForPrefsChanges(); |
55 | 56 |
56 void OnPreferenceChanged(const std::string& pref_name); | 57 void OnPreferenceChanged(const std::string& pref_name); |
57 | 58 |
| 59 // Sends a pref change to any listeners (if they exist; no-ops otherwise). |
| 60 void SendPrefChange(const std::string& pref_name); |
| 61 |
58 PrefChangeRegistrar* FindRegistrarForPref(const std::string& pref_name); | 62 PrefChangeRegistrar* FindRegistrarForPref(const std::string& pref_name); |
59 | 63 |
60 using SubscriptionMap = | 64 using SubscriptionMap = |
61 std::map<std::string, | 65 std::map<std::string, |
62 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>>; | 66 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>>; |
63 SubscriptionMap cros_settings_subscription_map_; | 67 SubscriptionMap cros_settings_subscription_map_; |
64 | 68 |
65 content::BrowserContext* context_; | 69 content::BrowserContext* context_; |
66 bool listening_; | 70 bool listening_; |
67 | 71 |
68 std::unique_ptr<PrefsUtil> prefs_util_; | 72 std::unique_ptr<PrefsUtil> prefs_util_; |
69 | 73 |
| 74 base::WeakPtrFactory<SettingsPrivateEventRouter> weak_ptr_factory_; |
| 75 |
70 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateEventRouter); | 76 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateEventRouter); |
71 }; | 77 }; |
72 | 78 |
73 } // namespace extensions | 79 } // namespace extensions |
74 | 80 |
75 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT
_ROUTER_H_ | 81 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT
_ROUTER_H_ |
OLD | NEW |