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_NOTIFICATIONS_NOTIFIER_STATE_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFIER_STATE_TRACKER_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFIER_STATE_TRACKER_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFIER_STATE_TRACKER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
13 #include "components/prefs/pref_member.h" | 13 #include "components/prefs/pref_member.h" |
| 14 #include "extensions/features/features.h" |
14 | 15 |
15 #if defined(ENABLE_EXTENSIONS) | 16 #if BUILDFLAG(ENABLE_EXTENSIONS) |
16 #include "base/scoped_observer.h" | 17 #include "base/scoped_observer.h" |
17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/extension_registry_observer.h" | 19 #include "extensions/browser/extension_registry_observer.h" |
19 #endif | 20 #endif |
20 | 21 |
21 class Profile; | 22 class Profile; |
22 | 23 |
23 namespace message_center { | 24 namespace message_center { |
24 struct NotifierId; | 25 struct NotifierId; |
25 } | 26 } |
26 | 27 |
27 namespace user_prefs { | 28 namespace user_prefs { |
28 class PrefRegistrySyncable; | 29 class PrefRegistrySyncable; |
29 } | 30 } |
30 | 31 |
31 // Tracks whether a given NotifierId can send notifications. | 32 // Tracks whether a given NotifierId can send notifications. |
32 class NotifierStateTracker : public KeyedService | 33 class NotifierStateTracker : public KeyedService |
33 #if defined(ENABLE_EXTENSIONS) | 34 #if BUILDFLAG(ENABLE_EXTENSIONS) |
34 , public extensions::ExtensionRegistryObserver | 35 , public extensions::ExtensionRegistryObserver |
35 #endif | 36 #endif |
36 { | 37 { |
37 public: | 38 public: |
38 // Register profile-specific prefs of notifications. | 39 // Register profile-specific prefs of notifications. |
39 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 40 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
40 | 41 |
41 explicit NotifierStateTracker(Profile* profile); | 42 explicit NotifierStateTracker(Profile* profile); |
42 ~NotifierStateTracker() override; | 43 ~NotifierStateTracker() override; |
43 | 44 |
44 // Returns whether the notifier with |notifier_id| may send notifications. | 45 // Returns whether the notifier with |notifier_id| may send notifications. |
45 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id) const; | 46 bool IsNotifierEnabled(const message_center::NotifierId& notifier_id) const; |
46 | 47 |
47 // Updates whether the notifier with |notifier_id| may send notifications. | 48 // Updates whether the notifier with |notifier_id| may send notifications. |
48 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, | 49 void SetNotifierEnabled(const message_center::NotifierId& notifier_id, |
49 bool enabled); | 50 bool enabled); |
50 | 51 |
51 private: | 52 private: |
52 // Called when the string list pref has been changed. | 53 // Called when the string list pref has been changed. |
53 void OnStringListPrefChanged( | 54 void OnStringListPrefChanged( |
54 const char* pref_name, std::set<std::string>* ids_field); | 55 const char* pref_name, std::set<std::string>* ids_field); |
55 | 56 |
56 #if defined(ENABLE_EXTENSIONS) | 57 #if BUILDFLAG(ENABLE_EXTENSIONS) |
57 // Fires a permission-level change event when an extension notifier has had | 58 // Fires a permission-level change event when an extension notifier has had |
58 // their notification permission changed. | 59 // their notification permission changed. |
59 void FirePermissionLevelChangedEvent( | 60 void FirePermissionLevelChangedEvent( |
60 const message_center::NotifierId& notifier_id, | 61 const message_center::NotifierId& notifier_id, |
61 bool enabled); | 62 bool enabled); |
62 | 63 |
63 // extensions::ExtensionRegistryObserver: | 64 // extensions::ExtensionRegistryObserver: |
64 void OnExtensionUninstalled(content::BrowserContext* browser_context, | 65 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
65 const extensions::Extension* extension, | 66 const extensions::Extension* extension, |
66 extensions::UninstallReason reason) override; | 67 extensions::UninstallReason reason) override; |
67 #endif | 68 #endif |
68 | 69 |
69 // The profile which owns this object. | 70 // The profile which owns this object. |
70 Profile* profile_; | 71 Profile* profile_; |
71 | 72 |
72 // Prefs listener for disabled_extension_id. | 73 // Prefs listener for disabled_extension_id. |
73 StringListPrefMember disabled_extension_id_pref_; | 74 StringListPrefMember disabled_extension_id_pref_; |
74 | 75 |
75 // Prefs listener for disabled_system_component_id. | 76 // Prefs listener for disabled_system_component_id. |
76 StringListPrefMember disabled_system_component_id_pref_; | 77 StringListPrefMember disabled_system_component_id_pref_; |
77 | 78 |
78 // On-memory data for the availability of extensions. | 79 // On-memory data for the availability of extensions. |
79 std::set<std::string> disabled_extension_ids_; | 80 std::set<std::string> disabled_extension_ids_; |
80 | 81 |
81 // On-memory data for the availability of system_component. | 82 // On-memory data for the availability of system_component. |
82 std::set<std::string> disabled_system_component_ids_; | 83 std::set<std::string> disabled_system_component_ids_; |
83 | 84 |
84 #if defined(ENABLE_EXTENSIONS) | 85 #if BUILDFLAG(ENABLE_EXTENSIONS) |
85 // An observer to listen when extension is uninstalled. | 86 // An observer to listen when extension is uninstalled. |
86 ScopedObserver<extensions::ExtensionRegistry, | 87 ScopedObserver<extensions::ExtensionRegistry, |
87 extensions::ExtensionRegistryObserver> | 88 extensions::ExtensionRegistryObserver> |
88 extension_registry_observer_; | 89 extension_registry_observer_; |
89 #endif | 90 #endif |
90 | 91 |
91 DISALLOW_COPY_AND_ASSIGN(NotifierStateTracker); | 92 DISALLOW_COPY_AND_ASSIGN(NotifierStateTracker); |
92 }; | 93 }; |
93 | 94 |
94 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFIER_STATE_TRACKER_H_ | 95 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFIER_STATE_TRACKER_H_ |
OLD | NEW |