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

Side by Side Diff: chrome/browser/extensions/api/settings_private/settings_private_event_router.h

Issue 1163593005: Update chrome.settingsPrivate to support CrOS-only settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issues preventing compilation on non-CrOS builds. Created 5 years, 6 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_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 "base/prefs/pref_change_registrar.h" 8 #include "base/prefs/pref_change_registrar.h"
9 #include "chrome/browser/chromeos/settings/cros_settings.h"
10 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
9 #include "components/keyed_service/core/keyed_service.h" 11 #include "components/keyed_service/core/keyed_service.h"
10 #include "extensions/browser/event_router.h" 12 #include "extensions/browser/event_router.h"
11 13
12 namespace content { 14 namespace content {
13 class BrowserContext; 15 class BrowserContext;
14 } 16 }
15 17
16 namespace extensions { 18 namespace extensions {
17 19
18 class SettingsPrivateDelegate; 20 class SettingsPrivateDelegate;
19 21
20 // This is an event router that will observe listeners to pref changes on the 22 // 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 23 // appropriate pref service(s) and notify listeners on the JavaScript
22 // settingsPrivate API. 24 // settingsPrivate API.
23 class SettingsPrivateEventRouter : public KeyedService, 25 class SettingsPrivateEventRouter : public KeyedService,
24 public EventRouter::Observer { 26 public EventRouter::Observer {
25 public: 27 public:
26 static SettingsPrivateEventRouter* Create( 28 static SettingsPrivateEventRouter* Create(
27 content::BrowserContext* browser_context); 29 content::BrowserContext* browser_context);
28 ~SettingsPrivateEventRouter() override; 30 ~SettingsPrivateEventRouter() override;
29 31
30 protected: 32 protected:
31 SettingsPrivateEventRouter() {}
32 explicit SettingsPrivateEventRouter(content::BrowserContext* context); 33 explicit SettingsPrivateEventRouter(content::BrowserContext* context);
33 34
34 // KeyedService overrides: 35 // KeyedService overrides:
35 void Shutdown() override; 36 void Shutdown() override;
36 37
37 // EventRouter::Observer overrides: 38 // EventRouter::Observer overrides:
38 void OnListenerAdded(const EventListenerInfo& details) override; 39 void OnListenerAdded(const EventListenerInfo& details) override;
39 void OnListenerRemoved(const EventListenerInfo& details) override; 40 void OnListenerRemoved(const EventListenerInfo& details) override;
40 41
41 // This registrar monitors for user prefs changes. 42 // This registrar monitors for user prefs changes.
42 PrefChangeRegistrar user_prefs_registrar_; 43 PrefChangeRegistrar user_prefs_registrar_;
43 44
44 // This registrar monitors for local state changes. 45 // This registrar monitors for local state changes.
45 PrefChangeRegistrar local_state_registrar_; 46 PrefChangeRegistrar local_state_registrar_;
46 47
47 private: 48 private:
48 // Decide if we should listen for pref changes or not. If there are any 49 // 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 // JavaScript listeners registered for the onPrefsChanged event, then we
50 // want to register for change notification from the PrefChangeRegistrar. 51 // want to register for change notification from the PrefChangeRegistrar.
51 // Otherwise, we want to unregister and not be listening for pref changes. 52 // Otherwise, we want to unregister and not be listening for pref changes.
52 void StartOrStopListeningForPrefsChanges(); 53 void StartOrStopListeningForPrefsChanges();
53 54
54 void OnPreferenceChanged(PrefService* service, const std::string& pref_name); 55 void OnPreferenceChanged(const std::string& pref_name);
55 56
56 PrefChangeRegistrar* FindRegistrarForPref(const std::string& pref_name); 57 PrefChangeRegistrar* FindRegistrarForPref(const std::string& pref_name);
57 58
59 typedef std::map<std::string,
60 linked_ptr<chromeos::CrosSettings::ObserverSubscription>>
61 SubscriptionMap;
62 SubscriptionMap cros_settings_subscription_map_;
63
58 content::BrowserContext* context_; 64 content::BrowserContext* context_;
59 bool listening_; 65 bool listening_;
60 66
67 scoped_ptr<PrefsUtil> prefs_util_;
68
61 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateEventRouter); 69 DISALLOW_COPY_AND_ASSIGN(SettingsPrivateEventRouter);
62 }; 70 };
63 71
64 } // namespace extensions 72 } // namespace extensions
65 73
66 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT _ROUTER_H_ 74 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_EVENT _ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698