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

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

Issue 1814923002: Nuke NotificationUIManager from PlatformNotificationServiceImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profile_manager_load
Patch Set: Review comments + unique_ptr rename Created 4 years, 8 months 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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <unordered_set> 14 #include <unordered_set>
15 15
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "chrome/browser/notifications/notification.h" 20 #include "chrome/browser/notifications/notification.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "content/public/browser/platform_notification_service.h" 22 #include "content/public/browser/platform_notification_service.h"
23 #include "content/public/common/persistent_notification_status.h" 23 #include "content/public/common/persistent_notification_status.h"
24 24
25 class NotificationDelegate; 25 class NotificationDelegate;
26 class NotificationUIManager; 26 class NotificationDisplayService;
27 27
28 namespace content { 28 namespace content {
29 class BrowserContext; 29 class BrowserContext;
30 struct NotificationResources; 30 struct NotificationResources;
31 } 31 }
32 32
33 namespace gcm { 33 namespace gcm {
34 class PushMessagingBrowserTest; 34 class PushMessagingBrowserTest;
35 } 35 }
36 36
37 // The platform notification service is the profile-agnostic entry point through 37 // The platform notification service is the profile-agnostic entry point through
38 // which Web Notifications can be controlled. 38 // which Web Notifications can be controlled.
39 class PlatformNotificationServiceImpl 39 class PlatformNotificationServiceImpl
40 : public content::PlatformNotificationService { 40 : public content::PlatformNotificationService {
41 public: 41 public:
42 // Things you can do to a notification. 42 // Things you can do to a notification.
43 enum NotificationOperation { 43 enum NotificationOperation {
44 NOTIFICATION_CLICK, 44 NOTIFICATION_CLICK,
45 NOTIFICATION_CLOSE, 45 NOTIFICATION_CLOSE,
46 NOTIFICATION_SETTINGS 46 NOTIFICATION_SETTINGS
47 }; 47 };
48 48
49 // Returns the active instance of the service in the browser process. Safe to 49 // Returns the active instance of the service in the browser process. Safe to
50 // be called from any thread. 50 // be called from any thread.
51 static PlatformNotificationServiceImpl* GetInstance(); 51 static PlatformNotificationServiceImpl* GetInstance();
52 52
53 // Returns the notification display service to use. This is overriden in tests
54 NotificationDisplayService* GetNotificationDisplayService(Profile* profile);
Peter Beverloo 2016/04/20 17:34:08 TODO on changing to be private for prosperity?
Miguel Garcia 2016/04/21 14:32:10 Done.
55
53 // Load the profile corresponding to |profile_id| and perform the 56 // Load the profile corresponding to |profile_id| and perform the
54 // |operation| on the given notification once it has been loaded. 57 // |operation| on the given notification once it has been loaded.
55 void ProcessPersistentNotificationOperation( 58 void ProcessPersistentNotificationOperation(
56 NotificationOperation operation, 59 NotificationOperation operation,
57 const std::string& profile_id, 60 const std::string& profile_id,
58 bool incognito, 61 bool incognito,
59 const GURL& origin, 62 const GURL& origin,
60 int64_t persistent_notification_id, 63 int64_t persistent_notification_id,
61 int action_index); 64 int action_index);
62 65
63 // To be called when a persistent notification has been clicked on. The 66 // To be called when a persistent notification has been clicked on. The
64 // Service Worker associated with the registration will be started if 67 // Service Worker associated with the registration will be started if
65 // needed, on which the event will be fired. Must be called on the UI thread. 68 // needed, on which the event will be fired. Must be called on the UI thread.
66 void OnPersistentNotificationClick( 69 void OnPersistentNotificationClick(
67 content::BrowserContext* browser_context, 70 content::BrowserContext* browser_context,
68 int64_t persistent_notification_id, 71 int64_t persistent_notification_id,
69 const GURL& origin, 72 const GURL& origin,
70 int action_index); 73 int action_index);
71 74
72 // To be called when a persistent notification has been closed. The data 75 // To be called when a persistent notification has been closed. The data
73 // associated with the notification has to be pruned from the database in this 76 // associated with the notification has to be pruned from the database in this
74 // case, to make sure that it continues to be in sync. Must be called on the 77 // case, to make sure that it continues to be in sync. Must be called on the
75 // UI thread. 78 // UI thread.
76 void OnPersistentNotificationClose(content::BrowserContext* browser_context, 79 void OnPersistentNotificationClose(content::BrowserContext* browser_context,
77 int64_t persistent_notification_id, 80 int64_t persistent_notification_id,
78 const GURL& origin, 81 const GURL& origin,
79 bool by_user); 82 bool by_user);
80 83
81 // Returns the Notification UI Manager through which notifications can be
82 // displayed to the user. Can be overridden for testing.
83 NotificationUIManager* GetNotificationUIManager() const;
84 84
85 // Open the Notification settings screen when clicking the right button. 85 // Open the Notification settings screen when clicking the right button.
86 void OpenNotificationSettings(content::BrowserContext* browser_context); 86 void OpenNotificationSettings(content::BrowserContext* browser_context);
87 87
88 // content::PlatformNotificationService implementation. 88 // content::PlatformNotificationService implementation.
89 blink::WebNotificationPermission CheckPermissionOnUIThread( 89 blink::WebNotificationPermission CheckPermissionOnUIThread(
90 content::BrowserContext* browser_context, 90 content::BrowserContext* browser_context,
91 const GURL& origin, 91 const GURL& origin,
92 int render_process_id) override; 92 int render_process_id) override;
93 blink::WebNotificationPermission CheckPermissionOnIOThread( 93 blink::WebNotificationPermission CheckPermissionOnIOThread(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Creates a new Web Notification-based Notification object. 130 // Creates a new Web Notification-based Notification object.
131 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this 131 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this
132 // through requires changing a whole lot of Notification constructor calls. 132 // through requires changing a whole lot of Notification constructor calls.
133 Notification CreateNotificationFromData( 133 Notification CreateNotificationFromData(
134 Profile* profile, 134 Profile* profile,
135 const GURL& origin, 135 const GURL& origin,
136 const content::PlatformNotificationData& notification_data, 136 const content::PlatformNotificationData& notification_data,
137 const content::NotificationResources& notification_resources, 137 const content::NotificationResources& notification_resources,
138 NotificationDelegate* delegate) const; 138 NotificationDelegate* delegate) const;
139 139
140 // Overrides the Notification UI Manager to use to |manager|. Only to be
141 // used by tests. Tests are responsible for cleaning up after themselves.
142 void SetNotificationUIManagerForTesting(NotificationUIManager* manager);
143
144 // Returns a display name for an origin, to be used in the context message 140 // Returns a display name for an origin, to be used in the context message
145 base::string16 DisplayNameForContextMessage(Profile* profile, 141 base::string16 DisplayNameForContextMessage(Profile* profile,
146 const GURL& origin) const; 142 const GURL& origin) const;
147 143
148 // Platforms that display native notification interact with them through this 144 void SetNotificationDisplayServiceForTesting(
149 // object. 145 NotificationDisplayService* service);
150 std::unique_ptr<NotificationUIManager> native_notification_ui_manager_;
151
152 // Weak reference. Ownership maintains with the test.
153 NotificationUIManager* notification_ui_manager_for_tests_;
154 146
155 // Mapping between a persistent notification id and the id of the associated 147 // Mapping between a persistent notification id and the id of the associated
156 // message_center::Notification object. Must only be used on the UI thread. 148 // message_center::Notification object. Must only be used on the UI thread.
157 std::map<int64_t, std::string> persistent_notifications_; 149 std::map<int64_t, std::string> persistent_notifications_;
158 150
159 // Tracks the id of persistent notifications that have been closed 151 // Tracks the id of persistent notifications that have been closed
160 // programmatically to avoid dispatching close events for them. 152 // programmatically to avoid dispatching close events for them.
161 std::unordered_set<int64_t> closed_notifications_; 153 std::unordered_set<int64_t> closed_notifications_;
162 154
155 // Only set and used for tests, owned by the caller in that case.
156 NotificationDisplayService* test_display_service_;
157
163 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); 158 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl);
164 }; 159 };
165 160
166 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ 161 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698