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

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

Issue 2703343002: ServiceWorker: Use mojo's data pipe for respondWith(stream) (Closed)
Patch Set: Updated comments Created 3 years, 8 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 <map>
7 #include <memory> 8 #include <memory>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "base/threading/thread_local.h" 17 #include "base/threading/thread_local.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // Service workers are only available in secure contexts, so all requests 104 // Service workers are only available in secure contexts, so all requests
104 // are initiated in a secure context. 105 // are initiated in a secure context.
105 extra_data->set_initiated_in_secure_context(true); 106 extra_data->set_initiated_in_secure_context(true);
106 request.SetExtraData(extra_data.release()); 107 request.SetExtraData(extra_data.release());
107 } 108 }
108 109
109 private: 110 private:
110 std::unique_ptr<ServiceWorkerNetworkProvider> provider_; 111 std::unique_ptr<ServiceWorkerNetworkProvider> provider_;
111 }; 112 };
112 113
114 class StreamHandleListener
115 : public blink::WebServiceWorkerStreamHandle::Listener {
116 public:
117 StreamHandleListener(
118 blink::mojom::ServiceWorkerStreamCallbackPtr callback_ptr)
119 : callback_ptr_(std::move(callback_ptr)) {}
120
121 void OnAborted() override { callback_ptr_->OnAborted(); }
122 void OnCompleted() override { callback_ptr_->OnCompleted(); }
123
124 private:
125 blink::mojom::ServiceWorkerStreamCallbackPtr callback_ptr_;
126 };
127
113 ServiceWorkerStatusCode EventResultToStatus( 128 ServiceWorkerStatusCode EventResultToStatus(
114 blink::WebServiceWorkerEventResult result) { 129 blink::WebServiceWorkerEventResult result) {
115 switch (result) { 130 switch (result) {
116 case blink::kWebServiceWorkerEventResultCompleted: 131 case blink::kWebServiceWorkerEventResultCompleted:
117 return SERVICE_WORKER_OK; 132 return SERVICE_WORKER_OK;
118 case blink::kWebServiceWorkerEventResultRejected: 133 case blink::kWebServiceWorkerEventResultRejected:
119 return SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; 134 return SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
120 } 135 }
121 NOTREACHED() << "Got invalid result: " << result; 136 NOTREACHED() << "Got invalid result: " << result;
122 return SERVICE_WORKER_ERROR_FAILED; 137 return SERVICE_WORKER_ERROR_FAILED;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 web_response->SetStatusText(blink::WebString::FromUTF8(response.status_text)); 227 web_response->SetStatusText(blink::WebString::FromUTF8(response.status_text));
213 web_response->SetResponseType(response.response_type); 228 web_response->SetResponseType(response.response_type);
214 for (const auto& pair : response.headers) { 229 for (const auto& pair : response.headers) {
215 web_response->SetHeader(blink::WebString::FromUTF8(pair.first), 230 web_response->SetHeader(blink::WebString::FromUTF8(pair.first),
216 blink::WebString::FromUTF8(pair.second)); 231 blink::WebString::FromUTF8(pair.second));
217 } 232 }
218 if (!response.blob_uuid.empty()) { 233 if (!response.blob_uuid.empty()) {
219 web_response->SetBlob(blink::WebString::FromASCII(response.blob_uuid), 234 web_response->SetBlob(blink::WebString::FromASCII(response.blob_uuid),
220 response.blob_size); 235 response.blob_size);
221 } 236 }
222 web_response->SetStreamURL(blink::WebURL(response.stream_url));
223 web_response->SetError(response.error); 237 web_response->SetError(response.error);
224 web_response->SetResponseTime(response.response_time.ToInternalValue()); 238 web_response->SetResponseTime(response.response_time.ToInternalValue());
225 if (response.is_in_cache_storage) { 239 if (response.is_in_cache_storage) {
226 web_response->SetCacheStorageCacheName( 240 web_response->SetCacheStorageCacheName(
227 blink::WebString::FromUTF8(response.cache_storage_cache_name)); 241 blink::WebString::FromUTF8(response.cache_storage_cache_name));
228 } 242 }
229 243
230 std::vector<blink::WebString> cors_exposed_header_names; 244 std::vector<blink::WebString> cors_exposed_header_names;
231 for (const auto& name : response.cors_exposed_header_names) 245 for (const auto& name : response.cors_exposed_header_names)
232 cors_exposed_header_names.push_back(blink::WebString::FromUTF8(name)); 246 cors_exposed_header_names.push_back(blink::WebString::FromUTF8(name));
233 247
234 web_response->SetCorsExposedHeaderNames( 248 web_response->SetCorsExposedHeaderNames(
235 blink::WebVector<blink::WebString>(cors_exposed_header_names)); 249 blink::WebVector<blink::WebString>(cors_exposed_header_names));
236 } 250 }
237 251
238 // Use this template in willDestroyWorkerContext to abort all the pending 252 // Use this template in willDestroyWorkerContext to abort all the pending
239 // events callbacks. 253 // events callbacks.
240 template <typename T> 254 template <typename T>
241 void AbortPendingEventCallbacks(T& callbacks) { 255 void AbortPendingEventCallbacks(T& callbacks) {
242 for (typename T::iterator it(&callbacks); !it.IsAtEnd(); it.Advance()) { 256 for (typename T::iterator it(&callbacks); !it.IsAtEnd(); it.Advance()) {
243 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); 257 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
244 } 258 }
245 } 259 }
246 260
261 template <typename Key, typename Callback>
262 void AbortPendingEventCallbacks(std::map<Key, Callback>& callbacks) {
263 for (const auto& it : callbacks)
264 it.second.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
265 }
266
247 } // namespace 267 } // namespace
248 268
249 // Holding data that needs to be bound to the worker context on the 269 // Holding data that needs to be bound to the worker context on the
250 // worker thread. 270 // worker thread.
251 struct ServiceWorkerContextClient::WorkerContextData { 271 struct ServiceWorkerContextClient::WorkerContextData {
272 using SimpleEventCallback =
273 base::Callback<void(ServiceWorkerStatusCode, base::Time)>;
252 using ClientsCallbacksMap = 274 using ClientsCallbacksMap =
253 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; 275 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>;
254 using ClaimClientsCallbacksMap = 276 using ClaimClientsCallbacksMap =
255 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; 277 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>;
256 using ClientCallbacksMap = 278 using ClientCallbacksMap =
257 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; 279 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
258 using SkipWaitingCallbacksMap = 280 using SkipWaitingCallbacksMap =
259 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; 281 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
260 using ActivateEventCallbacksMap = 282 using ActivateEventCallbacksMap =
261 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; 283 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
262 using BackgroundFetchAbortEventCallbacksMap = 284 using BackgroundFetchAbortEventCallbacksMap =
263 IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>; 285 IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>;
264 using BackgroundFetchClickEventCallbacksMap = 286 using BackgroundFetchClickEventCallbacksMap =
265 IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>; 287 IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>;
266 using BackgroundFetchFailEventCallbacksMap = 288 using BackgroundFetchFailEventCallbacksMap =
267 IDMap<std::unique_ptr<const DispatchBackgroundFetchFailEventCallback>>; 289 IDMap<std::unique_ptr<const DispatchBackgroundFetchFailEventCallback>>;
268 using BackgroundFetchedEventCallbacksMap = 290 using BackgroundFetchedEventCallbacksMap =
269 IDMap<std::unique_ptr<const DispatchBackgroundFetchedEventCallback>>; 291 IDMap<std::unique_ptr<const DispatchBackgroundFetchedEventCallback>>;
270 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 292 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
271 using NotificationClickEventCallbacksMap = 293 using NotificationClickEventCallbacksMap =
272 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; 294 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
273 using NotificationCloseEventCallbacksMap = 295 using NotificationCloseEventCallbacksMap =
274 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; 296 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
275 using PushEventCallbacksMap = 297 using PushEventCallbacksMap =
276 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; 298 IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
277 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
278 using ExtendableMessageEventCallbacksMap = 299 using ExtendableMessageEventCallbacksMap =
279 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; 300 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>;
280 using NavigationPreloadRequestsMap = IDMap< 301 using NavigationPreloadRequestsMap = IDMap<
281 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; 302 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>;
282 303
283 explicit WorkerContextData(ServiceWorkerContextClient* owner) 304 explicit WorkerContextData(ServiceWorkerContextClient* owner)
284 : event_dispatcher_binding(owner), 305 : event_dispatcher_binding(owner),
285 weak_factory(owner), 306 weak_factory(owner),
286 proxy_weak_factory(owner->proxy_) {} 307 proxy_weak_factory(owner->proxy_) {}
287 308
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Pending callbacks for Notification Click Events. 355 // Pending callbacks for Notification Click Events.
335 NotificationClickEventCallbacksMap notification_click_event_callbacks; 356 NotificationClickEventCallbacksMap notification_click_event_callbacks;
336 357
337 // Pending callbacks for Notification Close Events. 358 // Pending callbacks for Notification Close Events.
338 NotificationCloseEventCallbacksMap notification_close_event_callbacks; 359 NotificationCloseEventCallbacksMap notification_close_event_callbacks;
339 360
340 // Pending callbacks for Push Events. 361 // Pending callbacks for Push Events.
341 PushEventCallbacksMap push_event_callbacks; 362 PushEventCallbacksMap push_event_callbacks;
342 363
343 // Pending callbacks for Fetch Events. 364 // Pending callbacks for Fetch Events.
344 FetchEventCallbacksMap fetch_event_callbacks; 365 std::map<int /* fetch_event_id */, SimpleEventCallback> fetch_event_callbacks;
366
367 // Pending callbacks for respondWith on each fetch event.
368 std::map<int /* fetch_event_id */,
369 mojom::ServiceWorkerFetchResponseCallbackPtr>
370 fetch_response_callbacks;
345 371
346 // Pending callbacks for Extendable Message Events. 372 // Pending callbacks for Extendable Message Events.
347 ExtendableMessageEventCallbacksMap message_event_callbacks; 373 ExtendableMessageEventCallbacksMap message_event_callbacks;
348 374
349 // Pending navigation preload requests. 375 // Pending navigation preload requests.
350 NavigationPreloadRequestsMap preload_requests; 376 NavigationPreloadRequestsMap preload_requests;
351 377
352 base::ThreadChecker thread_checker; 378 base::ThreadChecker thread_checker;
353 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; 379 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory;
354 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; 380 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 context, service_worker_version_id_, script_url_); 698 context, service_worker_version_id_, script_url_);
673 } 699 }
674 700
675 void ServiceWorkerContextClient::WillDestroyWorkerContext( 701 void ServiceWorkerContextClient::WillDestroyWorkerContext(
676 v8::Local<v8::Context> context) { 702 v8::Local<v8::Context> context) {
677 // At this point WillStopCurrentWorkerThread is already called, so 703 // At this point WillStopCurrentWorkerThread is already called, so
678 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 704 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
679 // (while we're still on the worker thread). 705 // (while we're still on the worker thread).
680 proxy_ = NULL; 706 proxy_ = NULL;
681 707
682 // Aborts all the pending events callbacks. 708 // Aborts all the pending events callbacks.
horo 2017/04/10 09:24:38 Is it OK not to abort all fetch_response_callbacks
shimazu 2017/04/11 01:32:58 Good point. There is no behavior change in my unde
horo 2017/04/11 05:41:53 Even if we don't call all fetch_response_callback,
683 AbortPendingEventCallbacks(context_->activate_event_callbacks); 709 AbortPendingEventCallbacks(context_->activate_event_callbacks);
684 AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks); 710 AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks);
685 AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks); 711 AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks);
686 AbortPendingEventCallbacks(context_->background_fetch_fail_event_callbacks); 712 AbortPendingEventCallbacks(context_->background_fetch_fail_event_callbacks);
687 AbortPendingEventCallbacks(context_->background_fetched_event_callbacks); 713 AbortPendingEventCallbacks(context_->background_fetched_event_callbacks);
688 AbortPendingEventCallbacks(context_->sync_event_callbacks); 714 AbortPendingEventCallbacks(context_->sync_event_callbacks);
689 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); 715 AbortPendingEventCallbacks(context_->notification_click_event_callbacks);
690 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); 716 AbortPendingEventCallbacks(context_->notification_close_event_callbacks);
691 AbortPendingEventCallbacks(context_->push_event_callbacks); 717 AbortPendingEventCallbacks(context_->push_event_callbacks);
692 AbortPendingEventCallbacks(context_->fetch_event_callbacks); 718 AbortPendingEventCallbacks(context_->fetch_event_callbacks);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 blink::WebServiceWorkerEventResult result, 877 blink::WebServiceWorkerEventResult result,
852 double event_dispatch_time) { 878 double event_dispatch_time) {
853 Send(new ServiceWorkerHostMsg_InstallEventFinished( 879 Send(new ServiceWorkerHostMsg_InstallEventFinished(
854 GetRoutingID(), request_id, result, proxy_->HasFetchEventHandler(), 880 GetRoutingID(), request_id, result, proxy_->HasFetchEventHandler(),
855 base::Time::FromDoubleT(event_dispatch_time))); 881 base::Time::FromDoubleT(event_dispatch_time)));
856 } 882 }
857 883
858 void ServiceWorkerContextClient::RespondToFetchEvent( 884 void ServiceWorkerContextClient::RespondToFetchEvent(
859 int fetch_event_id, 885 int fetch_event_id,
860 double event_dispatch_time) { 886 double event_dispatch_time) {
861 Send(new ServiceWorkerHostMsg_FetchEventResponse( 887 const mojom::ServiceWorkerFetchResponseCallbackPtr& response_callback =
862 GetRoutingID(), fetch_event_id, 888 context_->fetch_response_callbacks[fetch_event_id];
863 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse(), 889 DCHECK(response_callback.is_bound());
864 base::Time::FromDoubleT(event_dispatch_time))); 890 response_callback->OnFallback(base::Time::FromDoubleT(event_dispatch_time));
891 context_->fetch_response_callbacks.erase(fetch_event_id);
865 } 892 }
866 893
867 void ServiceWorkerContextClient::RespondToFetchEvent( 894 void ServiceWorkerContextClient::RespondToFetchEventWithResponse(
868 int fetch_event_id, 895 int fetch_event_id,
869 const blink::WebServiceWorkerResponse& web_response, 896 const blink::WebServiceWorkerResponse& web_response,
870 double event_dispatch_time) { 897 double event_dispatch_time) {
871 Send(new ServiceWorkerHostMsg_FetchEventResponse( 898 ServiceWorkerResponse response(
872 GetRoutingID(), fetch_event_id, 899 GetServiceWorkerResponseFromWebResponse(web_response));
873 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, 900 const mojom::ServiceWorkerFetchResponseCallbackPtr& response_callback =
874 GetServiceWorkerResponseFromWebResponse(web_response), 901 context_->fetch_response_callbacks[fetch_event_id];
875 base::Time::FromDoubleT(event_dispatch_time))); 902 if (response.blob_uuid.size()) {
903 // Send the legacy IPC due to the ordering issue between respondWith and
904 // blob.
905 // TODO(shimazu): mojofy this IPC after blob starts using sync IPC for
906 // creation or is mojofied: https://crbug.com/611935.
907 Send(new ServiceWorkerHostMsg_FetchEventResponse(
908 GetRoutingID(), fetch_event_id, response,
909 base::Time::FromDoubleT(event_dispatch_time)));
910 } else {
911 response_callback->OnResponse(response,
912 base::Time::FromDoubleT(event_dispatch_time));
913 }
914 context_->fetch_response_callbacks.erase(fetch_event_id);
915 }
916
917 void ServiceWorkerContextClient::RespondToFetchEventWithResponseStream(
918 int fetch_event_id,
919 const blink::WebServiceWorkerResponse& web_response,
920 blink::WebServiceWorkerStreamHandle* web_stream_handle,
921 double event_dispatch_time) {
922 ServiceWorkerResponse response(
923 GetServiceWorkerResponseFromWebResponse(web_response));
924 const mojom::ServiceWorkerFetchResponseCallbackPtr& response_callback =
925 context_->fetch_response_callbacks[fetch_event_id];
926 blink::mojom::ServiceWorkerStreamHandlePtr stream_handle =
927 blink::mojom::ServiceWorkerStreamHandle::New();
928 blink::mojom::ServiceWorkerStreamCallbackPtr callback_ptr;
929 stream_handle->callback_request = mojo::MakeRequest(&callback_ptr);
930 stream_handle->stream = web_stream_handle->DrainStreamDataPipe();
931
932 web_stream_handle->SetListener(
933 base::MakeUnique<StreamHandleListener>(std::move(callback_ptr)));
934
935 response_callback->OnResponseStream(
936 response, std::move(stream_handle),
937 base::Time::FromDoubleT(event_dispatch_time));
938 context_->fetch_response_callbacks.erase(fetch_event_id);
876 } 939 }
877 940
878 void ServiceWorkerContextClient::DidHandleFetchEvent( 941 void ServiceWorkerContextClient::DidHandleFetchEvent(
879 int fetch_event_id, 942 int fetch_event_id,
880 blink::WebServiceWorkerEventResult result, 943 blink::WebServiceWorkerEventResult result,
881 double event_dispatch_time) { 944 double event_dispatch_time) {
882 const FetchCallback* callback = 945 const WorkerContextData::SimpleEventCallback& callback =
883 context_->fetch_event_callbacks.Lookup(fetch_event_id); 946 context_->fetch_event_callbacks[fetch_event_id];
884 DCHECK(callback); 947 DCHECK(callback);
885 callback->Run(EventResultToStatus(result), 948 callback.Run(EventResultToStatus(result),
886 base::Time::FromDoubleT(event_dispatch_time)); 949 base::Time::FromDoubleT(event_dispatch_time));
887 context_->fetch_event_callbacks.Remove(fetch_event_id); 950 context_->fetch_event_callbacks.erase(fetch_event_id);
888 } 951 }
889 952
890 void ServiceWorkerContextClient::DidHandleNotificationClickEvent( 953 void ServiceWorkerContextClient::DidHandleNotificationClickEvent(
891 int request_id, 954 int request_id,
892 blink::WebServiceWorkerEventResult result, 955 blink::WebServiceWorkerEventResult result,
893 double event_dispatch_time) { 956 double event_dispatch_time) {
894 const DispatchNotificationClickEventCallback* callback = 957 const DispatchNotificationClickEventCallback* callback =
895 context_->notification_click_event_callbacks.Lookup(request_id); 958 context_->notification_click_event_callbacks.Lookup(request_id);
896 DCHECK(callback); 959 DCHECK(callback);
897 960
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { 1290 void ServiceWorkerContextClient::OnInstallEvent(int request_id) {
1228 TRACE_EVENT0("ServiceWorker", 1291 TRACE_EVENT0("ServiceWorker",
1229 "ServiceWorkerContextClient::OnInstallEvent"); 1292 "ServiceWorkerContextClient::OnInstallEvent");
1230 proxy_->DispatchInstallEvent(request_id); 1293 proxy_->DispatchInstallEvent(request_id);
1231 } 1294 }
1232 1295
1233 void ServiceWorkerContextClient::DispatchFetchEvent( 1296 void ServiceWorkerContextClient::DispatchFetchEvent(
1234 int fetch_event_id, 1297 int fetch_event_id,
1235 const ServiceWorkerFetchRequest& request, 1298 const ServiceWorkerFetchRequest& request,
1236 mojom::FetchEventPreloadHandlePtr preload_handle, 1299 mojom::FetchEventPreloadHandlePtr preload_handle,
1300 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback,
1237 const DispatchFetchEventCallback& callback) { 1301 const DispatchFetchEventCallback& callback) {
1238 std::unique_ptr<NavigationPreloadRequest> preload_request = 1302 std::unique_ptr<NavigationPreloadRequest> preload_request =
1239 preload_handle 1303 preload_handle
1240 ? base::MakeUnique<NavigationPreloadRequest>( 1304 ? base::MakeUnique<NavigationPreloadRequest>(
1241 fetch_event_id, request.url, std::move(preload_handle)) 1305 fetch_event_id, request.url, std::move(preload_handle))
1242 : nullptr; 1306 : nullptr;
1243 const bool navigation_preload_sent = !!preload_request; 1307 const bool navigation_preload_sent = !!preload_request;
1244 TRACE_EVENT0("ServiceWorker", 1308 TRACE_EVENT0("ServiceWorker",
1245 "ServiceWorkerContextClient::DispatchFetchEvent"); 1309 "ServiceWorkerContextClient::DispatchFetchEvent");
1246 context_->fetch_event_callbacks.AddWithID( 1310 context_->fetch_response_callbacks.insert(
1247 base::MakeUnique<FetchCallback>(callback), fetch_event_id); 1311 std::make_pair(fetch_event_id, std::move(response_callback)));
1312 context_->fetch_event_callbacks.insert(
1313 std::make_pair(fetch_event_id, std::move(callback)));
1248 if (preload_request) { 1314 if (preload_request) {
1249 context_->preload_requests.AddWithID(std::move(preload_request), 1315 context_->preload_requests.AddWithID(std::move(preload_request),
1250 fetch_event_id); 1316 fetch_event_id);
1251 } 1317 }
1252 1318
1253 blink::WebServiceWorkerRequest web_request; 1319 blink::WebServiceWorkerRequest web_request;
1254 ToWebServiceWorkerRequest(request, &web_request); 1320 ToWebServiceWorkerRequest(request, &web_request);
1255 1321
1256 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { 1322 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) {
1257 proxy_->DispatchForeignFetchEvent(fetch_event_id, web_request); 1323 proxy_->DispatchForeignFetchEvent(fetch_event_id, web_request);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 } 1587 }
1522 1588
1523 base::WeakPtr<ServiceWorkerContextClient> 1589 base::WeakPtr<ServiceWorkerContextClient>
1524 ServiceWorkerContextClient::GetWeakPtr() { 1590 ServiceWorkerContextClient::GetWeakPtr() {
1525 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1591 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1526 DCHECK(context_); 1592 DCHECK(context_);
1527 return context_->weak_factory.GetWeakPtr(); 1593 return context_->weak_factory.GetWeakPtr();
1528 } 1594 }
1529 1595
1530 } // namespace content 1596 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698