[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / chrome / browser / notifications / platform_notification_service_impl.h
blobb8aa58093ca7663c70ddcdf81f0a9ca7db12a82b
1 // Copyright 2014 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_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
8 #include <stdint.h>
9 #include <map>
10 #include <set>
11 #include <string>
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/singleton.h"
15 #include "base/strings/string16.h"
16 #include "chrome/browser/notifications/notification.h"
17 #include "content/public/browser/platform_notification_service.h"
18 #include "content/public/common/persistent_notification_status.h"
20 class NotificationDelegate;
21 class NotificationUIManager;
22 class Profile;
24 namespace gcm {
25 class PushMessagingBrowserTest;
28 // The platform notification service is the profile-agnostic entry point through
29 // which Web Notifications can be controlled.
30 class PlatformNotificationServiceImpl
31 : public content::PlatformNotificationService {
32 public:
33 // Returns the active instance of the service in the browser process. Safe to
34 // be called from any thread.
35 static PlatformNotificationServiceImpl* GetInstance();
37 // To be called when a persistent notification has been clicked on. The
38 // Service Worker associated with the registration will be started if
39 // needed, on which the event will be fired. Must be called on the UI thread.
40 void OnPersistentNotificationClick(
41 content::BrowserContext* browser_context,
42 int64_t persistent_notification_id,
43 const GURL& origin,
44 int action_index) const;
46 // To be called when a persistent notification has been closed. The data
47 // associated with the notification has to be pruned from the database in this
48 // case, to make sure that it continues to be in sync. Must be called on the
49 // UI thread.
50 void OnPersistentNotificationClose(
51 content::BrowserContext* browser_context,
52 int64_t persistent_notification_id,
53 const GURL& origin) const;
55 // Returns the Notification UI Manager through which notifications can be
56 // displayed to the user. Can be overridden for testing.
57 NotificationUIManager* GetNotificationUIManager() const;
59 // content::PlatformNotificationService implementation.
60 blink::WebNotificationPermission CheckPermissionOnUIThread(
61 content::BrowserContext* browser_context,
62 const GURL& origin,
63 int render_process_id) override;
64 blink::WebNotificationPermission CheckPermissionOnIOThread(
65 content::ResourceContext* resource_context,
66 const GURL& origin,
67 int render_process_id) override;
68 void DisplayNotification(
69 content::BrowserContext* browser_context,
70 const GURL& origin,
71 const SkBitmap& icon,
72 const content::PlatformNotificationData& notification_data,
73 scoped_ptr<content::DesktopNotificationDelegate> delegate,
74 base::Closure* cancel_callback) override;
75 void DisplayPersistentNotification(
76 content::BrowserContext* browser_context,
77 int64_t persistent_notification_id,
78 const GURL& origin,
79 const SkBitmap& icon,
80 const content::PlatformNotificationData& notification_data) override;
81 void ClosePersistentNotification(
82 content::BrowserContext* browser_context,
83 int64_t persistent_notification_id) override;
84 bool GetDisplayedPersistentNotifications(
85 content::BrowserContext* browser_context,
86 std::set<std::string>* displayed_notifications) override;
88 private:
89 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>;
90 friend class PlatformNotificationServiceBrowserTest;
91 friend class PlatformNotificationServiceTest;
92 friend class PushMessagingBrowserTest;
93 FRIEND_TEST_ALL_PREFIXES(
94 PlatformNotificationServiceTest, DisplayNameForOrigin);
95 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest,
96 TestWebOriginDisplayName);
98 PlatformNotificationServiceImpl();
99 ~PlatformNotificationServiceImpl() override;
101 // Creates a new Web Notification-based Notification object.
102 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this
103 // through requires changing a whole lot of Notification constructor calls.
104 Notification CreateNotificationFromData(
105 Profile* profile,
106 const GURL& origin,
107 const SkBitmap& icon,
108 const content::PlatformNotificationData& notification_data,
109 NotificationDelegate* delegate) const;
111 // Overrides the Notification UI Manager to use to |manager|. Only to be
112 // used by tests. Tests are responsible for cleaning up after themselves.
113 void SetNotificationUIManagerForTesting(NotificationUIManager* manager);
115 // Returns a display name for an origin, to be used in permission infobar or
116 // on the frame of the notification toast. Different from the origin itself
117 // when dealing with extensions.
118 base::string16 DisplayNameForOrigin(Profile* profile,
119 const GURL& origin) const;
121 // Translates a URL into a slightly more readable version that may omit
122 // the port and scheme for common cases.
123 // TODO(dewittj): Remove this when the proper function is implemented in a
124 // chrome/browser/ui library function. See crbug.com/402698.
125 static base::string16 WebOriginDisplayName(const GURL& origin,
126 const std::string& languages);
128 // Weak reference. Ownership maintains with the test.
129 NotificationUIManager* notification_ui_manager_for_tests_;
131 // Mapping between a persistent notification id and the id of the associated
132 // message_center::Notification object. Must only be used on the UI thread.
133 std::map<int64_t, std::string> persistent_notifications_;
135 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl);
138 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_