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

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

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent 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
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 InstallEventCallbacksMap =
197 IDMap<std::unique_ptr<const DispatchInstallEventCallback>>;
196 using ActivateEventCallbacksMap = 198 using ActivateEventCallbacksMap =
197 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; 199 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
198 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 200 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
199 using PaymentRequestEventCallbacksMap = 201 using PaymentRequestEventCallbacksMap =
200 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; 202 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>;
201 using NotificationClickEventCallbacksMap = 203 using NotificationClickEventCallbacksMap =
202 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; 204 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
203 using NotificationCloseEventCallbacksMap = 205 using NotificationCloseEventCallbacksMap =
204 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; 206 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
205 using PushEventCallbacksMap = 207 using PushEventCallbacksMap =
(...skipping 20 matching lines...) Expand all
226 228
227 // Pending callbacks for OpenWindow() and FocusClient(). 229 // Pending callbacks for OpenWindow() and FocusClient().
228 ClientCallbacksMap client_callbacks; 230 ClientCallbacksMap client_callbacks;
229 231
230 // Pending callbacks for SkipWaiting(). 232 // Pending callbacks for SkipWaiting().
231 SkipWaitingCallbacksMap skip_waiting_callbacks; 233 SkipWaitingCallbacksMap skip_waiting_callbacks;
232 234
233 // Pending callbacks for ClaimClients(). 235 // Pending callbacks for ClaimClients().
234 ClaimClientsCallbacksMap claim_clients_callbacks; 236 ClaimClientsCallbacksMap claim_clients_callbacks;
235 237
238 // Pending callbacks for Install Events.
239 InstallEventCallbacksMap install_event_callbacks;
240
236 // Pending callbacks for Activate Events. 241 // Pending callbacks for Activate Events.
237 ActivateEventCallbacksMap activate_event_callbacks; 242 ActivateEventCallbacksMap activate_event_callbacks;
238 243
239 // Pending callbacks for Background Sync Events. 244 // Pending callbacks for Background Sync Events.
240 SyncEventCallbacksMap sync_event_callbacks; 245 SyncEventCallbacksMap sync_event_callbacks;
241 246
242 // Pending callbacks for Payment Request Events. 247 // Pending callbacks for Payment Request Events.
243 PaymentRequestEventCallbacksMap payment_request_event_callbacks; 248 PaymentRequestEventCallbacksMap payment_request_event_callbacks;
244 249
245 // Pending callbacks for Notification Click Events. 250 // Pending callbacks for Notification Click Events.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 410
406 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} 411 ServiceWorkerContextClient::~ServiceWorkerContextClient() {}
407 412
408 void ServiceWorkerContextClient::OnMessageReceived( 413 void ServiceWorkerContextClient::OnMessageReceived(
409 int thread_id, 414 int thread_id,
410 int embedded_worker_id, 415 int embedded_worker_id,
411 const IPC::Message& message) { 416 const IPC::Message& message) {
412 CHECK_EQ(embedded_worker_id_, embedded_worker_id); 417 CHECK_EQ(embedded_worker_id_, embedded_worker_id);
413 bool handled = true; 418 bool handled = true;
414 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) 419 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
415 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) 420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
417 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) 421 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, 422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
419 OnOpenWindowResponse) 423 OnOpenWindowResponse)
420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, 424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
421 OnOpenWindowError) 425 OnOpenWindowError)
422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 426 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
423 OnFocusClientResponse) 427 OnFocusClientResponse)
424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, 428 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse,
425 OnNavigateClientResponse) 429 OnNavigateClientResponse)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 context, service_worker_version_id_, script_url_); 571 context, service_worker_version_id_, script_url_);
568 } 572 }
569 573
570 void ServiceWorkerContextClient::willDestroyWorkerContext( 574 void ServiceWorkerContextClient::willDestroyWorkerContext(
571 v8::Local<v8::Context> context) { 575 v8::Local<v8::Context> context) {
572 // At this point WillStopCurrentWorkerThread is already called, so 576 // At this point WillStopCurrentWorkerThread is already called, so
573 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 577 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
574 // (while we're still on the worker thread). 578 // (while we're still on the worker thread).
575 proxy_ = NULL; 579 proxy_ = NULL;
576 580
577 // Aborts all the pending events callbacks. 581 // Aborts the all pending install event callbacks.
falken 2017/03/14 08:49:26 Can you document why install event is different th
xiaofengzhang 2017/04/01 02:27:21 Done.
582 for (WorkerContextData::InstallEventCallbacksMap::iterator it(
583 &context_->install_event_callbacks);
584 !it.IsAtEnd(); it.Advance()) {
falken 2017/03/14 08:49:26 I think you can use auto here
xiaofengzhang 2017/04/01 02:27:21 It seems can't. Because InstallEventCallbacksMap i
585 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, false,
falken 2017/03/14 08:49:26 false /* has_fetch_hander */
xiaofengzhang 2017/04/01 02:27:21 Done.
xiaofengzhang 2017/04/01 02:27:21 Done.
586 base::Time::Now());
587 }
588 // Aborts all other pending events callbacks.
578 AbortPendingEventCallbacks(context_->activate_event_callbacks); 589 AbortPendingEventCallbacks(context_->activate_event_callbacks);
579 AbortPendingEventCallbacks(context_->sync_event_callbacks); 590 AbortPendingEventCallbacks(context_->sync_event_callbacks);
580 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); 591 AbortPendingEventCallbacks(context_->notification_click_event_callbacks);
581 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); 592 AbortPendingEventCallbacks(context_->notification_close_event_callbacks);
582 AbortPendingEventCallbacks(context_->push_event_callbacks); 593 AbortPendingEventCallbacks(context_->push_event_callbacks);
583 AbortPendingEventCallbacks(context_->fetch_event_callbacks); 594 AbortPendingEventCallbacks(context_->fetch_event_callbacks);
584 AbortPendingEventCallbacks(context_->message_event_callbacks); 595 AbortPendingEventCallbacks(context_->message_event_callbacks);
585 596
586 // We have to clear callbacks now, as they need to be freed on the 597 // We have to clear callbacks now, as they need to be freed on the
587 // same thread. 598 // same thread.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 DCHECK(callback); 697 DCHECK(callback);
687 callback->Run(EventResultToStatus(result), 698 callback->Run(EventResultToStatus(result),
688 base::Time::FromDoubleT(event_dispatch_time)); 699 base::Time::FromDoubleT(event_dispatch_time));
689 context_->message_event_callbacks.Remove(request_id); 700 context_->message_event_callbacks.Remove(request_id);
690 } 701 }
691 702
692 void ServiceWorkerContextClient::didHandleInstallEvent( 703 void ServiceWorkerContextClient::didHandleInstallEvent(
693 int request_id, 704 int request_id,
694 blink::WebServiceWorkerEventResult result, 705 blink::WebServiceWorkerEventResult result,
695 double event_dispatch_time) { 706 double event_dispatch_time) {
696 Send(new ServiceWorkerHostMsg_InstallEventFinished( 707 const DispatchInstallEventCallback* callback =
697 GetRoutingID(), request_id, result, proxy_->hasFetchEventHandler(), 708 context_->install_event_callbacks.Lookup(request_id);
698 base::Time::FromDoubleT(event_dispatch_time))); 709 DCHECK(callback);
710 callback->Run(EventResultToStatus(result), proxy_->hasFetchEventHandler(),
711 base::Time::FromDoubleT(event_dispatch_time));
712 context_->install_event_callbacks.Remove(request_id);
699 } 713 }
700 714
701 void ServiceWorkerContextClient::respondToFetchEvent( 715 void ServiceWorkerContextClient::respondToFetchEvent(
702 int fetch_event_id, 716 int fetch_event_id,
703 double event_dispatch_time) { 717 double event_dispatch_time) {
704 Send(new ServiceWorkerHostMsg_FetchEventResponse( 718 Send(new ServiceWorkerHostMsg_FetchEventResponse(
705 GetRoutingID(), fetch_event_id, 719 GetRoutingID(), fetch_event_id,
706 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), 720 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(),
707 base::Time::FromDoubleT(event_dispatch_time))); 721 base::Time::FromDoubleT(event_dispatch_time)));
708 } 722 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 957
944 void ServiceWorkerContextClient::DispatchActivateEvent( 958 void ServiceWorkerContextClient::DispatchActivateEvent(
945 const DispatchActivateEventCallback& callback) { 959 const DispatchActivateEventCallback& callback) {
946 TRACE_EVENT0("ServiceWorker", 960 TRACE_EVENT0("ServiceWorker",
947 "ServiceWorkerContextClient::DispatchActivateEvent"); 961 "ServiceWorkerContextClient::DispatchActivateEvent");
948 int request_id = context_->activate_event_callbacks.Add( 962 int request_id = context_->activate_event_callbacks.Add(
949 base::MakeUnique<DispatchActivateEventCallback>(callback)); 963 base::MakeUnique<DispatchActivateEventCallback>(callback));
950 proxy_->dispatchActivateEvent(request_id); 964 proxy_->dispatchActivateEvent(request_id);
951 } 965 }
952 966
967 void ServiceWorkerContextClient::DispatchInstallEvent(
968 const DispatchInstallEventCallback& callback) {
969 TRACE_EVENT0("ServiceWorker",
970 "ServiceWorkerContextClient::DispatchInstallEvent");
971 int request_id = context_->install_event_callbacks.Add(
972 base::MakeUnique<DispatchInstallEventCallback>(callback));
973 proxy_->dispatchInstallEvent(request_id);
974 }
975
953 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( 976 void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
954 mojom::ExtendableMessageEventPtr event, 977 mojom::ExtendableMessageEventPtr event,
955 const DispatchExtendableMessageEventCallback& callback) { 978 const DispatchExtendableMessageEventCallback& callback) {
956 TRACE_EVENT0("ServiceWorker", 979 TRACE_EVENT0("ServiceWorker",
957 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); 980 "ServiceWorkerContextClient::DispatchExtendableMessageEvent");
958 int request_id = context_->message_event_callbacks.Add( 981 int request_id = context_->message_event_callbacks.Add(
959 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); 982 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback));
960 983
961 blink::WebMessagePortChannelArray ports = 984 blink::WebMessagePortChannelArray ports =
962 WebMessagePortChannelImpl::CreateFromMessagePipeHandles( 985 WebMessagePortChannelImpl::CreateFromMessagePipeHandles(
(...skipping 15 matching lines...) Expand all
978 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( 1001 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
979 sender_.get(), main_thread_task_runner_.get()); 1002 sender_.get(), main_thread_task_runner_.get());
980 scoped_refptr<WebServiceWorkerImpl> worker = 1003 scoped_refptr<WebServiceWorkerImpl> worker =
981 dispatcher->GetOrCreateServiceWorker(std::move(handle)); 1004 dispatcher->GetOrCreateServiceWorker(std::move(handle));
982 proxy_->dispatchExtendableMessageEvent( 1005 proxy_->dispatchExtendableMessageEvent(
983 request_id, blink::WebString::fromUTF16(event->message), 1006 request_id, blink::WebString::fromUTF16(event->message),
984 event->source_origin, std::move(ports), 1007 event->source_origin, std::move(ports),
985 WebServiceWorkerImpl::CreateHandle(worker)); 1008 WebServiceWorkerImpl::CreateHandle(worker));
986 } 1009 }
987 1010
988 void ServiceWorkerContextClient::OnInstallEvent(int request_id) {
989 TRACE_EVENT0("ServiceWorker",
990 "ServiceWorkerContextClient::OnInstallEvent");
991 proxy_->dispatchInstallEvent(request_id);
992 }
993
994 void ServiceWorkerContextClient::DispatchFetchEvent( 1011 void ServiceWorkerContextClient::DispatchFetchEvent(
995 int fetch_event_id, 1012 int fetch_event_id,
996 const ServiceWorkerFetchRequest& request, 1013 const ServiceWorkerFetchRequest& request,
997 mojom::FetchEventPreloadHandlePtr preload_handle, 1014 mojom::FetchEventPreloadHandlePtr preload_handle,
998 const DispatchFetchEventCallback& callback) { 1015 const DispatchFetchEventCallback& callback) {
999 std::unique_ptr<NavigationPreloadRequest> preload_request = 1016 std::unique_ptr<NavigationPreloadRequest> preload_request =
1000 preload_handle 1017 preload_handle
1001 ? base::MakeUnique<NavigationPreloadRequest>( 1018 ? base::MakeUnique<NavigationPreloadRequest>(
1002 fetch_event_id, request.url, std::move(preload_handle)) 1019 fetch_event_id, request.url, std::move(preload_handle))
1003 : nullptr; 1020 : nullptr;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 } 1322 }
1306 1323
1307 base::WeakPtr<ServiceWorkerContextClient> 1324 base::WeakPtr<ServiceWorkerContextClient>
1308 ServiceWorkerContextClient::GetWeakPtr() { 1325 ServiceWorkerContextClient::GetWeakPtr() {
1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1326 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1310 DCHECK(context_); 1327 DCHECK(context_);
1311 return context_->weak_factory.GetWeakPtr(); 1328 return context_->weak_factory.GetWeakPtr();
1312 } 1329 }
1313 1330
1314 } // namespace content 1331 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698