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

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2724243003: Revert of [ServiceWorker] Mojofy ActivateEvent of Service Worker (Closed)
Patch Set: Created 3 years, 9 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 | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/service_worker/service_worker_context_client.h" 5 #include "content/renderer/service_worker/service_worker_context_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // worker thread. 186 // worker thread.
187 struct ServiceWorkerContextClient::WorkerContextData { 187 struct ServiceWorkerContextClient::WorkerContextData {
188 using ClientsCallbacksMap = 188 using ClientsCallbacksMap =
189 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; 189 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>;
190 using ClaimClientsCallbacksMap = 190 using ClaimClientsCallbacksMap =
191 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; 191 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>;
192 using ClientCallbacksMap = 192 using ClientCallbacksMap =
193 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; 193 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
194 using SkipWaitingCallbacksMap = 194 using SkipWaitingCallbacksMap =
195 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; 195 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
196 using ActivateEventCallbacksMap =
197 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
198 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 196 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
199 using PaymentRequestEventCallbacksMap = 197 using PaymentRequestEventCallbacksMap =
200 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; 198 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>;
201 using NotificationClickEventCallbacksMap = 199 using NotificationClickEventCallbacksMap =
202 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; 200 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
203 using NotificationCloseEventCallbacksMap = 201 using NotificationCloseEventCallbacksMap =
204 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; 202 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
205 using PushEventCallbacksMap = 203 using PushEventCallbacksMap =
206 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; 204 IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
207 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; 205 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
(...skipping 18 matching lines...) Expand all
226 224
227 // Pending callbacks for OpenWindow() and FocusClient(). 225 // Pending callbacks for OpenWindow() and FocusClient().
228 ClientCallbacksMap client_callbacks; 226 ClientCallbacksMap client_callbacks;
229 227
230 // Pending callbacks for SkipWaiting(). 228 // Pending callbacks for SkipWaiting().
231 SkipWaitingCallbacksMap skip_waiting_callbacks; 229 SkipWaitingCallbacksMap skip_waiting_callbacks;
232 230
233 // Pending callbacks for ClaimClients(). 231 // Pending callbacks for ClaimClients().
234 ClaimClientsCallbacksMap claim_clients_callbacks; 232 ClaimClientsCallbacksMap claim_clients_callbacks;
235 233
236 // Pending callbacks for Activate Events.
237 ActivateEventCallbacksMap activate_event_callbacks;
238
239 // Pending callbacks for Background Sync Events. 234 // Pending callbacks for Background Sync Events.
240 SyncEventCallbacksMap sync_event_callbacks; 235 SyncEventCallbacksMap sync_event_callbacks;
241 236
242 // Pending callbacks for Payment Request Events. 237 // Pending callbacks for Payment Request Events.
243 PaymentRequestEventCallbacksMap payment_request_event_callbacks; 238 PaymentRequestEventCallbacksMap payment_request_event_callbacks;
244 239
245 // Pending callbacks for Notification Click Events. 240 // Pending callbacks for Notification Click Events.
246 NotificationClickEventCallbacksMap notification_click_event_callbacks; 241 NotificationClickEventCallbacksMap notification_click_event_callbacks;
247 242
248 // Pending callbacks for Notification Close Events. 243 // Pending callbacks for Notification Close Events.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 400
406 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} 401 ServiceWorkerContextClient::~ServiceWorkerContextClient() {}
407 402
408 void ServiceWorkerContextClient::OnMessageReceived( 403 void ServiceWorkerContextClient::OnMessageReceived(
409 int thread_id, 404 int thread_id,
410 int embedded_worker_id, 405 int embedded_worker_id,
411 const IPC::Message& message) { 406 const IPC::Message& message) {
412 CHECK_EQ(embedded_worker_id_, embedded_worker_id); 407 CHECK_EQ(embedded_worker_id_, embedded_worker_id);
413 bool handled = true; 408 bool handled = true;
414 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) 409 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
410 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
415 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 411 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) 412 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
417 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) 413 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, 414 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
419 OnOpenWindowResponse) 415 OnOpenWindowResponse)
420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, 416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
421 OnOpenWindowError) 417 OnOpenWindowError)
422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
423 OnFocusClientResponse) 419 OnFocusClientResponse)
424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, 420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 564 }
569 565
570 void ServiceWorkerContextClient::willDestroyWorkerContext( 566 void ServiceWorkerContextClient::willDestroyWorkerContext(
571 v8::Local<v8::Context> context) { 567 v8::Local<v8::Context> context) {
572 // At this point WillStopCurrentWorkerThread is already called, so 568 // At this point WillStopCurrentWorkerThread is already called, so
573 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 569 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
574 // (while we're still on the worker thread). 570 // (while we're still on the worker thread).
575 proxy_ = NULL; 571 proxy_ = NULL;
576 572
577 // Aborts all the pending events callbacks. 573 // Aborts all the pending events callbacks.
578 AbortPendingEventCallbacks(context_->activate_event_callbacks);
579 AbortPendingEventCallbacks(context_->sync_event_callbacks); 574 AbortPendingEventCallbacks(context_->sync_event_callbacks);
580 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); 575 AbortPendingEventCallbacks(context_->notification_click_event_callbacks);
581 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); 576 AbortPendingEventCallbacks(context_->notification_close_event_callbacks);
582 AbortPendingEventCallbacks(context_->push_event_callbacks); 577 AbortPendingEventCallbacks(context_->push_event_callbacks);
583 AbortPendingEventCallbacks(context_->fetch_event_callbacks); 578 AbortPendingEventCallbacks(context_->fetch_event_callbacks);
584 AbortPendingEventCallbacks(context_->message_event_callbacks); 579 AbortPendingEventCallbacks(context_->message_event_callbacks);
585 580
586 // We have to clear callbacks now, as they need to be freed on the 581 // We have to clear callbacks now, as they need to be freed on the
587 // same thread. 582 // same thread.
588 context_.reset(); 583 context_.reset();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 657
663 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* 658 blink::WebDevToolsAgentClient::WebKitClientMessageLoop*
664 ServiceWorkerContextClient::createDevToolsMessageLoop() { 659 ServiceWorkerContextClient::createDevToolsMessageLoop() {
665 return DevToolsAgent::createMessageLoopWrapper(); 660 return DevToolsAgent::createMessageLoopWrapper();
666 } 661 }
667 662
668 void ServiceWorkerContextClient::didHandleActivateEvent( 663 void ServiceWorkerContextClient::didHandleActivateEvent(
669 int request_id, 664 int request_id,
670 blink::WebServiceWorkerEventResult result, 665 blink::WebServiceWorkerEventResult result,
671 double event_dispatch_time) { 666 double event_dispatch_time) {
672 const DispatchActivateEventCallback* callback = 667 Send(new ServiceWorkerHostMsg_ActivateEventFinished(
673 context_->activate_event_callbacks.Lookup(request_id); 668 GetRoutingID(), request_id, result,
674 DCHECK(callback); 669 base::Time::FromDoubleT(event_dispatch_time)));
675 callback->Run(EventResultToStatus(result),
676 base::Time::FromDoubleT(event_dispatch_time));
677 context_->activate_event_callbacks.Remove(request_id);
678 } 670 }
679 671
680 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( 672 void ServiceWorkerContextClient::didHandleExtendableMessageEvent(
681 int request_id, 673 int request_id,
682 blink::WebServiceWorkerEventResult result, 674 blink::WebServiceWorkerEventResult result,
683 double event_dispatch_time) { 675 double event_dispatch_time) {
684 const DispatchExtendableMessageEventCallback* callback = 676 const DispatchExtendableMessageEventCallback* callback =
685 context_->message_event_callbacks.Lookup(request_id); 677 context_->message_event_callbacks.Lookup(request_id);
686 DCHECK(callback); 678 DCHECK(callback);
687 callback->Run(EventResultToStatus(result), 679 callback->Run(EventResultToStatus(result),
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 926
935 // Register a registration and its version attributes with the dispatcher 927 // Register a registration and its version attributes with the dispatcher
936 // living on the worker thread. 928 // living on the worker thread.
937 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( 929 scoped_refptr<WebServiceWorkerRegistrationImpl> registration(
938 dispatcher->GetOrCreateRegistration(info, attrs)); 930 dispatcher->GetOrCreateRegistration(info, attrs));
939 931
940 proxy_->setRegistration( 932 proxy_->setRegistration(
941 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); 933 WebServiceWorkerRegistrationImpl::CreateHandle(registration));
942 } 934 }
943 935
944 void ServiceWorkerContextClient::DispatchActivateEvent( 936 void ServiceWorkerContextClient::OnActivateEvent(int request_id) {
945 const DispatchActivateEventCallback& callback) {
946 TRACE_EVENT0("ServiceWorker", 937 TRACE_EVENT0("ServiceWorker",
947 "ServiceWorkerContextClient::DispatchActivateEvent"); 938 "ServiceWorkerContextClient::OnActivateEvent");
948 int request_id = context_->activate_event_callbacks.Add(
949 base::MakeUnique<DispatchActivateEventCallback>(callback));
950 proxy_->dispatchActivateEvent(request_id); 939 proxy_->dispatchActivateEvent(request_id);
951 } 940 }
952 941
953 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( 942 void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
954 mojom::ExtendableMessageEventPtr event, 943 mojom::ExtendableMessageEventPtr event,
955 const DispatchExtendableMessageEventCallback& callback) { 944 const DispatchExtendableMessageEventCallback& callback) {
956 TRACE_EVENT0("ServiceWorker", 945 TRACE_EVENT0("ServiceWorker",
957 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); 946 "ServiceWorkerContextClient::DispatchExtendableMessageEvent");
958 int request_id = context_->message_event_callbacks.Add( 947 int request_id = context_->message_event_callbacks.Add(
959 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); 948 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback));
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 } 1294 }
1306 1295
1307 base::WeakPtr<ServiceWorkerContextClient> 1296 base::WeakPtr<ServiceWorkerContextClient>
1308 ServiceWorkerContextClient::GetWeakPtr() { 1297 ServiceWorkerContextClient::GetWeakPtr() {
1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1298 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1310 DCHECK(context_); 1299 DCHECK(context_);
1311 return context_->weak_factory.GetWeakPtr(); 1300 return context_->weak_factory.GetWeakPtr();
1312 } 1301 }
1313 1302
1314 } // namespace content 1303 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698