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

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 1235803003: ServiceWorker: Introduce ExtendableMessageEvent to replace MessageEvent Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 if (!provider_host->GetRegistrationForReady(base::Bind( 671 if (!provider_host->GetRegistrationForReady(base::Bind(
672 &ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete, 672 &ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete,
673 this, thread_id, request_id, provider_host->AsWeakPtr()))) { 673 this, thread_id, request_id, provider_host->AsWeakPtr()))) {
674 bad_message::ReceivedBadMessage( 674 bad_message::ReceivedBadMessage(
675 this, bad_message::SWDH_GET_REGISTRATION_FOR_READY_ALREADY_IN_PROGRESS); 675 this, bad_message::SWDH_GET_REGISTRATION_FOR_READY_ALREADY_IN_PROGRESS);
676 } 676 }
677 } 677 }
678 678
679 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( 679 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
680 int handle_id, 680 int handle_id,
681 int provider_id,
681 const base::string16& message, 682 const base::string16& message,
682 const std::vector<TransferredMessagePort>& sent_message_ports) { 683 const std::vector<TransferredMessagePort>& sent_message_ports) {
683 TRACE_EVENT0("ServiceWorker", 684 TRACE_EVENT0("ServiceWorker",
684 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); 685 "ServiceWorkerDispatcherHost::OnPostMessageToWorker");
685 if (!GetContext()) 686 if (!GetContext())
686 return; 687 return;
687 688
688 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 689 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
689 if (!handle) { 690 if (!handle) {
690 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE); 691 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE);
691 return; 692 return;
692 } 693 }
693 694 ServiceWorkerProviderHost* provider_host =
695 GetContext()->GetProviderHost(render_process_id_, provider_id);
696 if (!provider_host) {
697 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE);
698 return;
699 }
694 handle->version()->DispatchMessageEvent( 700 handle->version()->DispatchMessageEvent(
695 message, sent_message_ports, 701 provider_host, message, sent_message_ports,
696 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 702 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
697 } 703 }
698 704
699 void ServiceWorkerDispatcherHost::OnProviderCreated( 705 void ServiceWorkerDispatcherHost::OnProviderCreated(
700 int provider_id, 706 int provider_id,
701 int route_id, 707 int route_id,
702 ServiceWorkerProviderType provider_type) { 708 ServiceWorkerProviderType provider_type) {
703 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 709 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
704 tracked_objects::ScopedTracker tracking_profile( 710 tracked_objects::ScopedTracker tracking_profile(
705 FROM_HERE_WITH_EXPLICIT_FUNCTION( 711 FROM_HERE_WITH_EXPLICIT_FUNCTION(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 840
835 ServiceWorkerRegistration* registration = 841 ServiceWorkerRegistration* registration =
836 GetContext()->GetLiveRegistration(registration_id); 842 GetContext()->GetLiveRegistration(registration_id);
837 DCHECK(registration); 843 DCHECK(registration);
838 844
839 ServiceWorkerRegistrationObjectInfo info; 845 ServiceWorkerRegistrationObjectInfo info;
840 ServiceWorkerVersionAttributes attrs; 846 ServiceWorkerVersionAttributes attrs;
841 GetRegistrationObjectInfoAndVersionAttributes( 847 GetRegistrationObjectInfoAndVersionAttributes(
842 provider_host->AsWeakPtr(), registration, &info, &attrs); 848 provider_host->AsWeakPtr(), registration, &info, &attrs);
843 849
844 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( 850 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(thread_id, request_id,
845 thread_id, request_id, info, attrs)); 851 provider_id, info, attrs));
846 TRACE_EVENT_ASYNC_END1("ServiceWorker", 852 TRACE_EVENT_ASYNC_END1("ServiceWorker",
847 "ServiceWorkerDispatcherHost::RegisterServiceWorker", 853 "ServiceWorkerDispatcherHost::RegisterServiceWorker",
848 request_id, 854 request_id,
849 "Registration ID", 855 "Registration ID",
850 registration_id); 856 registration_id);
851 } 857 }
852 858
853 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection( 859 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection(
854 int embedded_worker_id) { 860 int embedded_worker_id) {
855 TRACE_EVENT0("ServiceWorker", 861 TRACE_EVENT0("ServiceWorker",
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 ServiceWorkerRegistrationObjectInfo info; 1096 ServiceWorkerRegistrationObjectInfo info;
1091 ServiceWorkerVersionAttributes attrs; 1097 ServiceWorkerVersionAttributes attrs;
1092 if (status == SERVICE_WORKER_OK) { 1098 if (status == SERVICE_WORKER_OK) {
1093 DCHECK(registration.get()); 1099 DCHECK(registration.get());
1094 if (!registration->is_uninstalling()) { 1100 if (!registration->is_uninstalling()) {
1095 GetRegistrationObjectInfoAndVersionAttributes( 1101 GetRegistrationObjectInfoAndVersionAttributes(
1096 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); 1102 provider_host->AsWeakPtr(), registration.get(), &info, &attrs);
1097 } 1103 }
1098 } 1104 }
1099 1105
1100 Send(new ServiceWorkerMsg_DidGetRegistration( 1106 Send(new ServiceWorkerMsg_DidGetRegistration(thread_id, request_id,
1101 thread_id, request_id, info, attrs)); 1107 provider_id, info, attrs));
1102 } 1108 }
1103 1109
1104 void ServiceWorkerDispatcherHost::GetRegistrationsComplete( 1110 void ServiceWorkerDispatcherHost::GetRegistrationsComplete(
1105 int thread_id, 1111 int thread_id,
1106 int provider_id, 1112 int provider_id,
1107 int request_id, 1113 int request_id,
1108 const std::vector<scoped_refptr<ServiceWorkerRegistration>>& 1114 const std::vector<scoped_refptr<ServiceWorkerRegistration>>&
1109 registrations) { 1115 registrations) {
1110 TRACE_EVENT_ASYNC_END0("ServiceWorker", 1116 TRACE_EVENT_ASYNC_END0("ServiceWorker",
1111 "ServiceWorkerDispatcherHost::GetRegistrations", 1117 "ServiceWorkerDispatcherHost::GetRegistrations",
(...skipping 15 matching lines...) Expand all
1127 ServiceWorkerRegistrationObjectInfo object_info; 1133 ServiceWorkerRegistrationObjectInfo object_info;
1128 ServiceWorkerVersionAttributes version_attr; 1134 ServiceWorkerVersionAttributes version_attr;
1129 GetRegistrationObjectInfoAndVersionAttributes( 1135 GetRegistrationObjectInfoAndVersionAttributes(
1130 provider_host->AsWeakPtr(), registration.get(), &object_info, 1136 provider_host->AsWeakPtr(), registration.get(), &object_info,
1131 &version_attr); 1137 &version_attr);
1132 object_infos.push_back(object_info); 1138 object_infos.push_back(object_info);
1133 version_attrs.push_back(version_attr); 1139 version_attrs.push_back(version_attr);
1134 } 1140 }
1135 } 1141 }
1136 1142
1137 Send(new ServiceWorkerMsg_DidGetRegistrations(thread_id, request_id, 1143 Send(new ServiceWorkerMsg_DidGetRegistrations(
1138 object_infos, version_attrs)); 1144 thread_id, request_id, provider_id, object_infos, version_attrs));
1139 } 1145 }
1140 1146
1141 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( 1147 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete(
1142 int thread_id, 1148 int thread_id,
1143 int request_id, 1149 int request_id,
1144 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 1150 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
1145 ServiceWorkerRegistration* registration) { 1151 ServiceWorkerRegistration* registration) {
1146 DCHECK(registration); 1152 DCHECK(registration);
1147 TRACE_EVENT_ASYNC_END1("ServiceWorker", 1153 TRACE_EVENT_ASYNC_END1("ServiceWorker",
1148 "ServiceWorkerDispatcherHost::GetRegistrationForReady", 1154 "ServiceWorkerDispatcherHost::GetRegistrationForReady",
1149 request_id, 1155 request_id,
1150 "Registration ID", 1156 "Registration ID",
1151 registration ? registration->id() 1157 registration ? registration->id()
1152 : kInvalidServiceWorkerRegistrationId); 1158 : kInvalidServiceWorkerRegistrationId);
1153 1159
1154 if (!GetContext()) 1160 if (!GetContext())
1155 return; 1161 return;
1156 1162
1157 ServiceWorkerRegistrationObjectInfo info; 1163 ServiceWorkerRegistrationObjectInfo info;
1158 ServiceWorkerVersionAttributes attrs; 1164 ServiceWorkerVersionAttributes attrs;
1159 GetRegistrationObjectInfoAndVersionAttributes( 1165 GetRegistrationObjectInfoAndVersionAttributes(
1160 provider_host, registration, &info, &attrs); 1166 provider_host, registration, &info, &attrs);
1161 Send(new ServiceWorkerMsg_DidGetRegistrationForReady( 1167 Send(new ServiceWorkerMsg_DidGetRegistrationForReady(
1162 thread_id, request_id, info, attrs)); 1168 thread_id, request_id, provider_host->provider_id(), info, attrs));
1163 } 1169 }
1164 1170
1165 void ServiceWorkerDispatcherHost::SendRegistrationError( 1171 void ServiceWorkerDispatcherHost::SendRegistrationError(
1166 int thread_id, 1172 int thread_id,
1167 int request_id, 1173 int request_id,
1168 ServiceWorkerStatusCode status, 1174 ServiceWorkerStatusCode status,
1169 const std::string& status_message) { 1175 const std::string& status_message) {
1170 base::string16 error_message; 1176 base::string16 error_message;
1171 blink::WebServiceWorkerError::ErrorType error_type; 1177 blink::WebServiceWorkerError::ErrorType error_type;
1172 GetServiceWorkerRegistrationStatusResponse(status, status_message, 1178 GetServiceWorkerRegistrationStatusResponse(status, status_message,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 if (!handle) { 1234 if (!handle) {
1229 bad_message::ReceivedBadMessage(this, 1235 bad_message::ReceivedBadMessage(this,
1230 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1236 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1231 return; 1237 return;
1232 } 1238 }
1233 handle->version()->StopWorker( 1239 handle->version()->StopWorker(
1234 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1240 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1235 } 1241 }
1236 1242
1237 } // namespace content 1243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698