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

Side by Side Diff: content/child/notifications/notification_manager.cc

Issue 2480293004: Mandate unique_ptr for base::IDMap in IDMapOwnPointer mode. (Closed)
Patch Set: Make changes requested by danakj, fix a few more headers Created 4 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 #include "content/child/notifications/notification_manager.h" 5 #include "content/child/notifications/notification_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 notification_id, origin_gurl, 105 notification_id, origin_gurl,
106 ToPlatformNotificationData(notification_data), 106 ToPlatformNotificationData(notification_data),
107 ToNotificationResources(std::move(notification_resources)))); 107 ToNotificationResources(std::move(notification_resources))));
108 } 108 }
109 109
110 void NotificationManager::showPersistent( 110 void NotificationManager::showPersistent(
111 const blink::WebSecurityOrigin& origin, 111 const blink::WebSecurityOrigin& origin,
112 const blink::WebNotificationData& notification_data, 112 const blink::WebNotificationData& notification_data,
113 std::unique_ptr<blink::WebNotificationResources> notification_resources, 113 std::unique_ptr<blink::WebNotificationResources> notification_resources,
114 blink::WebServiceWorkerRegistration* service_worker_registration, 114 blink::WebServiceWorkerRegistration* service_worker_registration,
115 blink::WebNotificationShowCallbacks* callbacks) { 115 std::unique_ptr<blink::WebNotificationShowCallbacks> callbacks) {
116 DCHECK(service_worker_registration); 116 DCHECK(service_worker_registration);
117 DCHECK_EQ(notification_data.actions.size(), 117 DCHECK_EQ(notification_data.actions.size(),
118 notification_resources->actionIcons.size()); 118 notification_resources->actionIcons.size());
119 119
120 int64_t service_worker_registration_id = 120 int64_t service_worker_registration_id =
121 static_cast<WebServiceWorkerRegistrationImpl*>( 121 static_cast<WebServiceWorkerRegistrationImpl*>(
122 service_worker_registration) 122 service_worker_registration)
123 ->registrationId(); 123 ->registrationId();
124 124
125 std::unique_ptr<blink::WebNotificationShowCallbacks> owned_callbacks(
126 callbacks);
127
128 // Verify that the author-provided payload size does not exceed our limit. 125 // Verify that the author-provided payload size does not exceed our limit.
129 // This is an implementation-defined limit to prevent abuse of notification 126 // This is an implementation-defined limit to prevent abuse of notification
130 // data as a storage mechanism. A UMA histogram records the requested sizes, 127 // data as a storage mechanism. A UMA histogram records the requested sizes,
131 // which enables us to track how much data authors are attempting to store. 128 // which enables us to track how much data authors are attempting to store.
132 // 129 //
133 // If the size exceeds this limit, reject the showNotification() promise. This 130 // If the size exceeds this limit, reject the showNotification() promise. This
134 // is outside of the boundaries set by the specification, but it gives authors 131 // is outside of the boundaries set by the specification, but it gives authors
135 // an indication that something has gone wrong. 132 // an indication that something has gone wrong.
136 size_t author_data_size = notification_data.data.size(); 133 size_t author_data_size = notification_data.data.size();
137 134
138 UMA_HISTOGRAM_COUNTS_1000("Notifications.AuthorDataSize", author_data_size); 135 UMA_HISTOGRAM_COUNTS_1000("Notifications.AuthorDataSize", author_data_size);
139 136
140 if (author_data_size > PlatformNotificationData::kMaximumDeveloperDataSize) { 137 if (author_data_size > PlatformNotificationData::kMaximumDeveloperDataSize) {
141 owned_callbacks->onError(); 138 callbacks->onError();
142 return; 139 return;
143 } 140 }
144 141
145 // TODO(peter): GenerateNotificationId is more of a request id. Consider 142 // TODO(peter): GenerateNotificationId is more of a request id. Consider
146 // renaming the method in the NotificationDispatcher if this makes sense. 143 // renaming the method in the NotificationDispatcher if this makes sense.
147 int request_id = 144 int request_id =
148 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); 145 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
149 146
150 pending_show_notification_requests_.AddWithID(owned_callbacks.release(), 147 pending_show_notification_requests_.AddWithID(std::move(callbacks),
151 request_id); 148 request_id);
152 149
153 // TODO(mkwst): This is potentially doing the wrong thing with unique 150 // TODO(mkwst): This is potentially doing the wrong thing with unique
154 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See 151 // origins. Perhaps also 'file:', 'blob:' and 'filesystem:'. See
155 // https://crbug.com/490074 for detail. 152 // https://crbug.com/490074 for detail.
156 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent( 153 thread_safe_sender_->Send(new PlatformNotificationHostMsg_ShowPersistent(
157 request_id, service_worker_registration_id, url::Origin(origin).GetURL(), 154 request_id, service_worker_registration_id, url::Origin(origin).GetURL(),
158 ToPlatformNotificationData(notification_data), 155 ToPlatformNotificationData(notification_data),
159 ToNotificationResources(std::move(notification_resources)))); 156 ToNotificationResources(std::move(notification_resources))));
160 } 157 }
161 158
162 void NotificationManager::getNotifications( 159 void NotificationManager::getNotifications(
163 const blink::WebString& filter_tag, 160 const blink::WebString& filter_tag,
164 blink::WebServiceWorkerRegistration* service_worker_registration, 161 blink::WebServiceWorkerRegistration* service_worker_registration,
165 blink::WebNotificationGetCallbacks* callbacks) { 162 std::unique_ptr<blink::WebNotificationGetCallbacks> callbacks) {
166 DCHECK(service_worker_registration); 163 DCHECK(service_worker_registration);
167 DCHECK(callbacks); 164 DCHECK(callbacks);
168 165
169 WebServiceWorkerRegistrationImpl* service_worker_registration_impl = 166 WebServiceWorkerRegistrationImpl* service_worker_registration_impl =
170 static_cast<WebServiceWorkerRegistrationImpl*>( 167 static_cast<WebServiceWorkerRegistrationImpl*>(
171 service_worker_registration); 168 service_worker_registration);
172 169
173 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin(); 170 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin();
174 int64_t service_worker_registration_id = 171 int64_t service_worker_registration_id =
175 service_worker_registration_impl->registrationId(); 172 service_worker_registration_impl->registrationId();
176 173
177 // TODO(peter): GenerateNotificationId is more of a request id. Consider 174 // TODO(peter): GenerateNotificationId is more of a request id. Consider
178 // renaming the method in the NotificationDispatcher if this makes sense. 175 // renaming the method in the NotificationDispatcher if this makes sense.
179 int request_id = 176 int request_id =
180 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); 177 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
181 178
182 pending_get_notification_requests_.AddWithID(callbacks, request_id); 179 pending_get_notification_requests_.AddWithID(std::move(callbacks),
180 request_id);
183 181
184 thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications( 182 thread_safe_sender_->Send(new PlatformNotificationHostMsg_GetNotifications(
185 request_id, service_worker_registration_id, origin, 183 request_id, service_worker_registration_id, origin,
186 base::UTF16ToUTF8(base::StringPiece16(filter_tag)))); 184 base::UTF16ToUTF8(base::StringPiece16(filter_tag))));
187 } 185 }
188 186
189 void NotificationManager::close(blink::WebNotificationDelegate* delegate) { 187 void NotificationManager::close(blink::WebNotificationDelegate* delegate) {
190 for (auto& iter : active_page_notifications_) { 188 for (auto& iter : active_page_notifications_) {
191 if (iter.second.delegate != delegate) 189 if (iter.second.delegate != delegate)
192 continue; 190 continue;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 302
305 notifications[i] = web_notification_info; 303 notifications[i] = web_notification_info;
306 } 304 }
307 305
308 callbacks->onSuccess(notifications); 306 callbacks->onSuccess(notifications);
309 307
310 pending_get_notification_requests_.Remove(request_id); 308 pending_get_notification_requests_.Remove(request_id);
311 } 309 }
312 310
313 } // namespace content 311 } // namespace content
OLDNEW
« no previous file with comments | « content/child/notifications/notification_manager.h ('k') | content/child/push_messaging/push_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698