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

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

Powered by Google App Engine
This is Rietveld 408576698