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

Side by Side Diff: content/browser/notifications/notification_event_dispatcher_impl.cc

Issue 1269923003: Plumb notification action index for desktop SW notificationclick (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@actions
Patch Set: Created 5 years, 4 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 #include "content/browser/notifications/notification_event_dispatcher_impl.h" 5 #include "content/browser/notifications/notification_event_dispatcher_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "content/browser/notifications/platform_notification_context_impl.h" 8 #include "content/browser/notifications/platform_notification_context_impl.h"
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" 9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
10 #include "content/browser/service_worker/service_worker_registration.h" 10 #include "content/browser/service_worker/service_worker_registration.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 BrowserThread::PostTask(BrowserThread::UI, 61 BrowserThread::PostTask(BrowserThread::UI,
62 FROM_HERE, 62 FROM_HERE,
63 base::Bind(dispatch_complete_callback, status)); 63 base::Bind(dispatch_complete_callback, status));
64 } 64 }
65 65
66 // Dispatches the notificationclick on |service_worker_registration| if the 66 // Dispatches the notificationclick on |service_worker_registration| if the
67 // registration was available. Must be called on the IO thread. 67 // registration was available. Must be called on the IO thread.
68 void DispatchNotificationClickEventOnRegistration( 68 void DispatchNotificationClickEventOnRegistration(
69 const NotificationDatabaseData& notification_database_data, 69 const NotificationDatabaseData& notification_database_data,
70 int action_index,
70 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, 71 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
71 ServiceWorkerStatusCode service_worker_status, 72 ServiceWorkerStatusCode service_worker_status,
72 const scoped_refptr<ServiceWorkerRegistration>& 73 const scoped_refptr<ServiceWorkerRegistration>&
73 service_worker_registration) { 74 service_worker_registration) {
74 DCHECK_CURRENTLY_ON(BrowserThread::IO); 75 DCHECK_CURRENTLY_ON(BrowserThread::IO);
75 if (service_worker_status == SERVICE_WORKER_OK) { 76 if (service_worker_status == SERVICE_WORKER_OK) {
76 base::Callback<void(ServiceWorkerStatusCode)> dispatch_event_callback = 77 base::Callback<void(ServiceWorkerStatusCode)> dispatch_event_callback =
77 base::Bind(&NotificationClickEventFinished, 78 base::Bind(&NotificationClickEventFinished,
78 dispatch_complete_callback, 79 dispatch_complete_callback,
79 service_worker_registration); 80 service_worker_registration);
80 81
81 service_worker_registration->active_version()-> 82 service_worker_registration->active_version()->
82 DispatchNotificationClickEvent( 83 DispatchNotificationClickEvent(
83 dispatch_event_callback, 84 dispatch_event_callback,
84 notification_database_data.notification_id, 85 notification_database_data.notification_id,
85 notification_database_data.notification_data); 86 notification_database_data.notification_data,
87 action_index);
86 return; 88 return;
87 } 89 }
88 90
89 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; 91 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS;
90 switch (service_worker_status) { 92 switch (service_worker_status) {
91 case SERVICE_WORKER_ERROR_NOT_FOUND: 93 case SERVICE_WORKER_ERROR_NOT_FOUND:
92 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER; 94 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER;
93 break; 95 break;
94 case SERVICE_WORKER_ERROR_FAILED: 96 case SERVICE_WORKER_ERROR_FAILED:
95 case SERVICE_WORKER_ERROR_ABORT: 97 case SERVICE_WORKER_ERROR_ABORT:
(...skipping 21 matching lines...) Expand all
117 119
118 BrowserThread::PostTask(BrowserThread::UI, 120 BrowserThread::PostTask(BrowserThread::UI,
119 FROM_HERE, 121 FROM_HERE,
120 base::Bind(dispatch_complete_callback, status)); 122 base::Bind(dispatch_complete_callback, status));
121 } 123 }
122 124
123 // Finds the ServiceWorkerRegistration associated with the |origin| and 125 // Finds the ServiceWorkerRegistration associated with the |origin| and
124 // |service_worker_registration_id|. Must be called on the IO thread. 126 // |service_worker_registration_id|. Must be called on the IO thread.
125 void FindServiceWorkerRegistration( 127 void FindServiceWorkerRegistration(
126 const GURL& origin, 128 const GURL& origin,
129 int action_index,
127 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, 130 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
128 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, 131 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
129 bool success, 132 bool success,
130 const NotificationDatabaseData& notification_database_data) { 133 const NotificationDatabaseData& notification_database_data) {
131 DCHECK_CURRENTLY_ON(BrowserThread::IO); 134 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132 if (!success) { 135 if (!success) {
133 BrowserThread::PostTask( 136 BrowserThread::PostTask(
134 BrowserThread::UI, 137 BrowserThread::UI,
135 FROM_HERE, 138 FROM_HERE,
136 base::Bind(dispatch_complete_callback, 139 base::Bind(dispatch_complete_callback,
137 PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR)); 140 PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR));
138 return; 141 return;
139 } 142 }
140 143
141 service_worker_context->FindRegistrationForId( 144 service_worker_context->FindRegistrationForId(
142 notification_database_data.service_worker_registration_id, 145 notification_database_data.service_worker_registration_id,
143 origin, 146 origin,
144 base::Bind(&DispatchNotificationClickEventOnRegistration, 147 base::Bind(&DispatchNotificationClickEventOnRegistration,
145 notification_database_data, 148 notification_database_data, action_index,
146 dispatch_complete_callback)); 149 dispatch_complete_callback));
147 } 150 }
148 151
149 // Reads the data associated with the |persistent_notification_id| belonging to 152 // Reads the data associated with the |persistent_notification_id| belonging to
150 // |origin| from the notification context. 153 // |origin| from the notification context.
151 void ReadNotificationDatabaseData( 154 void ReadNotificationDatabaseData(
152 int64_t persistent_notification_id, 155 int64_t persistent_notification_id,
153 const GURL& origin, 156 const GURL& origin,
157 int action_index,
154 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, 158 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
155 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, 159 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
156 scoped_refptr<PlatformNotificationContextImpl> notification_context) { 160 scoped_refptr<PlatformNotificationContextImpl> notification_context) {
157 DCHECK_CURRENTLY_ON(BrowserThread::IO); 161 DCHECK_CURRENTLY_ON(BrowserThread::IO);
158 notification_context->ReadNotificationData( 162 notification_context->ReadNotificationData(
159 persistent_notification_id, 163 persistent_notification_id,
160 origin, 164 origin,
161 base::Bind(&FindServiceWorkerRegistration, 165 base::Bind(&FindServiceWorkerRegistration,
162 origin, dispatch_complete_callback, service_worker_context)); 166 origin, action_index, dispatch_complete_callback,
167 service_worker_context));
163 } 168 }
164 169
165 } // namespace 170 } // namespace
166 171
167 // static 172 // static
168 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { 173 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() {
169 return NotificationEventDispatcherImpl::GetInstance(); 174 return NotificationEventDispatcherImpl::GetInstance();
170 } 175 }
171 176
172 NotificationEventDispatcherImpl* 177 NotificationEventDispatcherImpl*
173 NotificationEventDispatcherImpl::GetInstance() { 178 NotificationEventDispatcherImpl::GetInstance() {
174 DCHECK_CURRENTLY_ON(BrowserThread::UI); 179 DCHECK_CURRENTLY_ON(BrowserThread::UI);
175 return Singleton<NotificationEventDispatcherImpl>::get(); 180 return Singleton<NotificationEventDispatcherImpl>::get();
176 } 181 }
177 182
178 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} 183 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {}
179 184
180 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} 185 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {}
181 186
182 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( 187 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent(
183 BrowserContext* browser_context, 188 BrowserContext* browser_context,
184 int64_t persistent_notification_id, 189 int64_t persistent_notification_id,
185 const GURL& origin, 190 const GURL& origin,
191 int action_index,
186 const NotificationClickDispatchCompleteCallback& 192 const NotificationClickDispatchCompleteCallback&
187 dispatch_complete_callback) { 193 dispatch_complete_callback) {
188 DCHECK_CURRENTLY_ON(BrowserThread::UI); 194 DCHECK_CURRENTLY_ON(BrowserThread::UI);
189 DCHECK_GT(persistent_notification_id, 0); 195 DCHECK_GT(persistent_notification_id, 0);
190 DCHECK(origin.is_valid()); 196 DCHECK(origin.is_valid());
191 197
192 StoragePartition* partition = 198 StoragePartition* partition =
193 BrowserContext::GetStoragePartitionForSite(browser_context, origin); 199 BrowserContext::GetStoragePartitionForSite(browser_context, origin);
194 200
195 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = 201 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
196 static_cast<ServiceWorkerContextWrapper*>( 202 static_cast<ServiceWorkerContextWrapper*>(
197 partition->GetServiceWorkerContext()); 203 partition->GetServiceWorkerContext());
198 scoped_refptr<PlatformNotificationContextImpl> notification_context = 204 scoped_refptr<PlatformNotificationContextImpl> notification_context =
199 static_cast<PlatformNotificationContextImpl*>( 205 static_cast<PlatformNotificationContextImpl*>(
200 partition->GetPlatformNotificationContext()); 206 partition->GetPlatformNotificationContext());
201 207
202 BrowserThread::PostTask( 208 BrowserThread::PostTask(
203 BrowserThread::IO, 209 BrowserThread::IO,
204 FROM_HERE, 210 FROM_HERE,
205 base::Bind(&ReadNotificationDatabaseData, 211 base::Bind(&ReadNotificationDatabaseData,
206 persistent_notification_id, 212 persistent_notification_id,
207 origin, 213 origin,
214 action_index,
208 dispatch_complete_callback, 215 dispatch_complete_callback,
209 service_worker_context, 216 service_worker_context,
210 notification_context)); 217 notification_context));
211 } 218 }
212 219
213 } // namespace content 220 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698