1 // Copyright (c) 2012 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_DESKTOP_NOTIFICATION_SERVICE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_
12 #include "base/basictypes.h"
13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/prefs/pref_member.h"
18 #include "base/scoped_observer.h"
19 #include "base/strings/string16.h"
20 #include "chrome/browser/content_settings/permission_context_base.h"
21 #include "components/content_settings/core/common/content_settings.h"
22 #include "components/keyed_service/core/keyed_service.h"
23 #include "ui/message_center/notifier_settings.h"
26 #if defined(ENABLE_EXTENSIONS)
27 #include "extensions/browser/extension_registry_observer.h"
32 #if defined(ENABLE_EXTENSIONS)
33 namespace extensions
{
34 class ExtensionRegistry
;
38 namespace user_prefs
{
39 class PrefRegistrySyncable
;
42 // The DesktopNotificationService is an object, owned by the Profile,
43 // which provides the creation of desktop "toasts" to web pages and workers.
44 class DesktopNotificationService
: public PermissionContextBase
45 #if defined(ENABLE_EXTENSIONS)
47 public extensions::ExtensionRegistryObserver
51 // Register profile-specific prefs of notifications.
52 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* prefs
);
54 explicit DesktopNotificationService(Profile
* profile
);
55 ~DesktopNotificationService() override
;
57 // Requests Web Notification permission for |requesting_frame|. The |callback|
58 // will be invoked after the user has made a decision.
59 void RequestNotificationPermission(
60 content::WebContents
* web_contents
,
61 const PermissionRequestID
& request_id
,
62 const GURL
& requesting_origin
,
64 const BrowserPermissionCallback
& result_callback
);
66 // Returns true if the notifier with |notifier_id| is allowed to send
68 bool IsNotifierEnabled(const message_center::NotifierId
& notifier_id
) const;
70 // Updates the availability of the notifier.
71 void SetNotifierEnabled(const message_center::NotifierId
& notifier_id
,
75 // Called when the string list pref has been changed.
76 void OnStringListPrefChanged(
77 const char* pref_name
, std::set
<std::string
>* ids_field
);
79 // Called when the disabled_extension_id pref has been changed.
80 void OnDisabledExtensionIdsChanged();
82 void FirePermissionLevelChangedEvent(
83 const message_center::NotifierId
& notifier_id
,
86 #if defined(ENABLE_EXTENSIONS)
87 // extensions::ExtensionRegistryObserver:
88 void OnExtensionUninstalled(content::BrowserContext
* browser_context
,
89 const extensions::Extension
* extension
,
90 extensions::UninstallReason reason
) override
;
93 // PermissionContextBase:
94 void UpdateContentSetting(const GURL
& requesting_origin
,
95 const GURL
& embedder_origin
,
96 ContentSetting content_setting
) override
;
98 // The profile which owns this object.
101 // Prefs listener for disabled_extension_id.
102 StringListPrefMember disabled_extension_id_pref_
;
104 // Prefs listener for disabled_system_component_id.
105 StringListPrefMember disabled_system_component_id_pref_
;
107 // On-memory data for the availability of extensions.
108 std::set
<std::string
> disabled_extension_ids_
;
110 // On-memory data for the availability of system_component.
111 std::set
<std::string
> disabled_system_component_ids_
;
113 #if defined(ENABLE_EXTENSIONS)
114 // An observer to listen when extension is uninstalled.
115 ScopedObserver
<extensions::ExtensionRegistry
,
116 extensions::ExtensionRegistryObserver
>
117 extension_registry_observer_
;
120 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService
);
123 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_