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