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

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

Powered by Google App Engine
This is Rietveld 408576698