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

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

Issue 1575283003: Move notification click event dispatching out of ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@swversion-ipc-refactor
Patch Set: rebase and use DispatchSimpleEvent Created 4 years, 11 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/notifications/platform_notification_context_impl.h" 9 #include "content/browser/notifications/platform_notification_context_impl.h"
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" 10 #include "content/browser/service_worker/service_worker_context_wrapper.h"
11 #include "content/browser/service_worker/service_worker_registration.h" 11 #include "content/browser/service_worker/service_worker_registration.h"
12 #include "content/browser/service_worker/service_worker_storage.h" 12 #include "content/browser/service_worker/service_worker_storage.h"
13 #include "content/common/service_worker/service_worker_messages.h"
13 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_database_data.h" 16 #include "content/public/browser/notification_database_data.h"
16 #include "content/public/browser/storage_partition.h" 17 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/platform_notification_data.h" 18 #include "content/public/common/platform_notification_data.h"
18 19
19 namespace content { 20 namespace content {
20 namespace { 21 namespace {
21 22
22 using NotificationClickDispatchCompleteCallback = 23 using NotificationClickDispatchCompleteCallback =
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 case SERVICE_WORKER_ERROR_DISABLED_WORKER: 67 case SERVICE_WORKER_ERROR_DISABLED_WORKER:
67 case SERVICE_WORKER_ERROR_MAX_VALUE: 68 case SERVICE_WORKER_ERROR_MAX_VALUE:
68 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; 69 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR;
69 break; 70 break;
70 } 71 }
71 72
72 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
73 base::Bind(dispatch_complete_callback, status)); 74 base::Bind(dispatch_complete_callback, status));
74 } 75 }
75 76
77 // Dispatches the notificationclick event on |service_worker|. Most be called on
78 // the IO thread, and with the worker running.
79 void DispatchNotificationClickEventOnWorker(
80 const scoped_refptr<ServiceWorkerVersion>& service_worker,
81 const NotificationDatabaseData& notification_database_data,
82 int action_index,
83 const ServiceWorkerVersion::StatusCallback& callback) {
84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
85 int request_id = service_worker->StartRequest(
86 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback);
87 service_worker->DispatchSimpleEvent<
88 ServiceWorkerHostMsg_NotificationClickEventFinished>(
89 request_id,
90 ServiceWorkerMsg_NotificationClickEvent(
91 request_id, notification_database_data.notification_id,
92 notification_database_data.notification_data, action_index));
93 }
94
76 // Dispatches the notificationclick on |service_worker_registration| if the 95 // Dispatches the notificationclick on |service_worker_registration| if the
77 // registration was available. Must be called on the IO thread. 96 // registration was available. Must be called on the IO thread.
78 void DispatchNotificationClickEventOnRegistration( 97 void DispatchNotificationClickEventOnRegistration(
79 const NotificationDatabaseData& notification_database_data, 98 const NotificationDatabaseData& notification_database_data,
80 int action_index, 99 int action_index,
81 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, 100 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback,
82 ServiceWorkerStatusCode service_worker_status, 101 ServiceWorkerStatusCode service_worker_status,
83 const scoped_refptr<ServiceWorkerRegistration>& 102 const scoped_refptr<ServiceWorkerRegistration>&
84 service_worker_registration) { 103 service_worker_registration) {
85 DCHECK_CURRENTLY_ON(BrowserThread::IO); 104 DCHECK_CURRENTLY_ON(BrowserThread::IO);
86 #if defined(OS_ANDROID) 105 #if defined(OS_ANDROID)
87 // This LOG(INFO) deliberately exists to help track down the cause of 106 // This LOG(INFO) deliberately exists to help track down the cause of
88 // https://crbug.com/534537, where notifications sometimes do not react to 107 // https://crbug.com/534537, where notifications sometimes do not react to
89 // the user clicking on them. It should be removed once that's fixed. 108 // the user clicking on them. It should be removed once that's fixed.
90 LOG(INFO) << "Trying to dispatch notification for SW with status: " 109 LOG(INFO) << "Trying to dispatch notification for SW with status: "
91 << service_worker_status << " action_index: " << action_index; 110 << service_worker_status << " action_index: " << action_index;
92 #endif 111 #endif
93 if (service_worker_status == SERVICE_WORKER_OK) { 112 if (service_worker_status == SERVICE_WORKER_OK) {
94 base::Callback<void(ServiceWorkerStatusCode)> dispatch_event_callback = 113 ServiceWorkerVersion::StatusCallback dispatch_event_callback =
95 base::Bind(&NotificationClickEventFinished, dispatch_complete_callback, 114 base::Bind(&NotificationClickEventFinished, dispatch_complete_callback,
96 service_worker_registration); 115 service_worker_registration);
97 116
98 DCHECK(service_worker_registration->active_version()); 117 DCHECK(service_worker_registration->active_version());
99 service_worker_registration->active_version() 118 service_worker_registration->active_version()->RunAfterStartWorker(
100 ->DispatchNotificationClickEvent( 119 base::Bind(
101 dispatch_event_callback, notification_database_data.notification_id, 120 &DispatchNotificationClickEventOnWorker,
102 notification_database_data.notification_data, action_index); 121 make_scoped_refptr(service_worker_registration->active_version()),
122 notification_database_data, action_index, dispatch_event_callback),
123 dispatch_event_callback);
103 return; 124 return;
104 } 125 }
105 126
106 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; 127 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS;
107 switch (service_worker_status) { 128 switch (service_worker_status) {
108 case SERVICE_WORKER_ERROR_NOT_FOUND: 129 case SERVICE_WORKER_ERROR_NOT_FOUND:
109 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER; 130 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER;
110 break; 131 break;
111 case SERVICE_WORKER_ERROR_FAILED: 132 case SERVICE_WORKER_ERROR_FAILED:
112 case SERVICE_WORKER_ERROR_ABORT: 133 case SERVICE_WORKER_ERROR_ABORT:
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 partition->GetPlatformNotificationContext()); 247 partition->GetPlatformNotificationContext());
227 248
228 BrowserThread::PostTask( 249 BrowserThread::PostTask(
229 BrowserThread::IO, FROM_HERE, 250 BrowserThread::IO, FROM_HERE,
230 base::Bind(&ReadNotificationDatabaseData, persistent_notification_id, 251 base::Bind(&ReadNotificationDatabaseData, persistent_notification_id,
231 origin, action_index, dispatch_complete_callback, 252 origin, action_index, dispatch_complete_callback,
232 service_worker_context, notification_context)); 253 service_worker_context, notification_context));
233 } 254 }
234 255
235 } // namespace content 256 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698