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

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

Powered by Google App Engine
This is Rietveld 408576698