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

Side by Side Diff: chrome/browser/notifications/platform_notification_service_impl.h

Issue 784383002: Support persistent notifications in the PlatformNotificationServiceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-chrome-base
Patch Set: adds browser tests Created 6 years 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 2014 The Chromium Authors. All rights reserved. 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 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_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
7 7
8 #include "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "chrome/browser/notifications/notification.h"
10 #include "content/public/browser/platform_notification_service.h" 11 #include "content/public/browser/platform_notification_service.h"
12 #include "content/public/common/persistent_notification_status.h"
11 13
14 class NotificationDelegate;
12 class NotificationUIManager; 15 class NotificationUIManager;
13 class Profile; 16 class Profile;
14 17
15 // The platform notification service is the profile-agnostic entry point through 18 // The platform notification service is the profile-agnostic entry point through
16 // which Web Notifications can be controlled. 19 // which Web Notifications can be controlled.
17 class PlatformNotificationServiceImpl 20 class PlatformNotificationServiceImpl
18 : public content::PlatformNotificationService { 21 : public content::PlatformNotificationService {
19 public: 22 public:
20 // Returns the active instance of the service in the browser process. Safe to 23 // Returns the active instance of the service in the browser process. Safe to
21 // be called from any thread. 24 // be called from any thread.
22 static PlatformNotificationServiceImpl* GetInstance(); 25 static PlatformNotificationServiceImpl* GetInstance();
23 26
27 // To be called when a persistent notification has been clicked on. The
28 // Service Worker associated with the registration will be started if
29 // needed, on which the event will be fired. Must be called on the UI thread.
30 void OnPersistentNotificationClick(
31 content::BrowserContext* browser_context,
32 int64 service_worker_registration_id,
33 const std::string& notification_id,
34 const content::ShowDesktopNotificationHostMsgParams& params,
35 const base::Callback<void(content::PersistentNotificationStatus)>&
36 callback) const;
37
24 // Returns the Notification UI Manager through which notifications can be 38 // Returns the Notification UI Manager through which notifications can be
25 // displayed to the user. Can be overridden for testing. 39 // displayed to the user. Can be overridden for testing.
26 NotificationUIManager* GetNotificationUIManager() const; 40 NotificationUIManager* GetNotificationUIManager() const;
27 41
28 // content::PlatformNotificationService implementation. 42 // content::PlatformNotificationService implementation.
29 blink::WebNotificationPermission CheckPermission( 43 blink::WebNotificationPermission CheckPermission(
30 content::ResourceContext* resource_context, 44 content::ResourceContext* resource_context,
31 const GURL& origin, 45 const GURL& origin,
32 int render_process_id) override;; 46 int render_process_id) override;;
33 void DisplayNotification( 47 void DisplayNotification(
34 content::BrowserContext* browser_context, 48 content::BrowserContext* browser_context,
35 const content::ShowDesktopNotificationHostMsgParams& params, 49 const content::ShowDesktopNotificationHostMsgParams& params,
36 scoped_ptr<content::DesktopNotificationDelegate> delegate, 50 scoped_ptr<content::DesktopNotificationDelegate> delegate,
37 int render_process_id, 51 int render_process_id,
38 base::Closure* cancel_callback) override; 52 base::Closure* cancel_callback) override;
39 void DisplayPersistentNotification( 53 void DisplayPersistentNotification(
40 content::BrowserContext* browser_context, 54 content::BrowserContext* browser_context,
41 int64 service_worker_registration_id, 55 int64 service_worker_registration_id,
42 const content::ShowDesktopNotificationHostMsgParams& params, 56 const content::ShowDesktopNotificationHostMsgParams& params,
43 int render_process_id) override; 57 int render_process_id) override;
44 void ClosePersistentNotification( 58 void ClosePersistentNotification(
45 content::BrowserContext* browser_context, 59 content::BrowserContext* browser_context,
46 const std::string& persistent_notification_id) override; 60 const std::string& persistent_notification_id) override;
47 61
48 private: 62 private:
49 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>; 63 friend struct DefaultSingletonTraits<PlatformNotificationServiceImpl>;
64 friend class PlatformNotificationServiceBrowserTest;
50 friend class PlatformNotificationServiceTest; 65 friend class PlatformNotificationServiceTest;
51 FRIEND_TEST_ALL_PREFIXES( 66 FRIEND_TEST_ALL_PREFIXES(
52 PlatformNotificationServiceTest, DisplayNameForOrigin); 67 PlatformNotificationServiceTest, DisplayNameForOrigin);
53 68
54 PlatformNotificationServiceImpl(); 69 PlatformNotificationServiceImpl();
55 ~PlatformNotificationServiceImpl() override; 70 ~PlatformNotificationServiceImpl() override;
56 71
72 // Creates a new Web Notification-based Notification object.
73 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this
74 // through requires changing a whole lot of Notification constructor calls.
75 Notification CreateNotificationFromData(
76 Profile* profile,
77 const content::ShowDesktopNotificationHostMsgParams& params,
78 NotificationDelegate* delegate,
79 int render_process_id) const;
80
57 // Overrides the Notification UI Manager to use to |manager|. Only to be 81 // Overrides the Notification UI Manager to use to |manager|. Only to be
58 // used by tests. Tests are responsible for cleaning up after themselves. 82 // used by tests. Tests are responsible for cleaning up after themselves.
59 void SetNotificationUIManagerForTesting(NotificationUIManager* manager); 83 void SetNotificationUIManagerForTesting(NotificationUIManager* manager);
60 84
61 // Returns a display name for an origin in the process id, to be used in 85 // Returns a display name for an origin in the process id, to be used in
62 // permission infobar or on the frame of the notification toast. Different 86 // permission infobar or on the frame of the notification toast. Different
63 // from the origin itself when dealing with extensions. 87 // from the origin itself when dealing with extensions.
64 base::string16 DisplayNameForOriginInProcessId(Profile* profile, 88 base::string16 DisplayNameForOriginInProcessId(Profile* profile,
65 const GURL& origin, 89 const GURL& origin,
66 int process_id); 90 int process_id) const;
67 91
68 // Weak reference. Ownership maintains with the test. 92 // Weak reference. Ownership maintains with the test.
69 NotificationUIManager* notification_ui_manager_for_tests_; 93 NotificationUIManager* notification_ui_manager_for_tests_;
70 94
71 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); 95 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl);
72 }; 96 };
73 97
74 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ 98 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698