OLD | NEW |
---|---|
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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "content/browser/service_worker/embedded_worker_instance.h" | 24 #include "content/browser/service_worker/embedded_worker_instance.h" |
25 #include "content/browser/service_worker/embedded_worker_registry.h" | 25 #include "content/browser/service_worker/embedded_worker_registry.h" |
26 #include "content/browser/service_worker/service_worker_context_core.h" | 26 #include "content/browser/service_worker/service_worker_context_core.h" |
27 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 27 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
28 #include "content/browser/service_worker/service_worker_metrics.h" | 28 #include "content/browser/service_worker/service_worker_metrics.h" |
29 #include "content/browser/service_worker/service_worker_registration.h" | 29 #include "content/browser/service_worker/service_worker_registration.h" |
30 #include "content/browser/service_worker/service_worker_utils.h" | 30 #include "content/browser/service_worker/service_worker_utils.h" |
31 #include "content/browser/service_worker/stashed_port_manager.h" | 31 #include "content/browser/service_worker/stashed_port_manager.h" |
32 #include "content/browser/storage_partition_impl.h" | 32 #include "content/browser/storage_partition_impl.h" |
33 #include "content/common/service_worker/service_worker_messages.h" | 33 #include "content/common/service_worker/service_worker_messages.h" |
34 #include "content/common/service_worker/service_worker_type_converters.h" | |
34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/content_browser_client.h" | 36 #include "content/public/browser/content_browser_client.h" |
36 #include "content/public/browser/page_navigator.h" | 37 #include "content/public/browser/page_navigator.h" |
37 #include "content/public/browser/render_frame_host.h" | 38 #include "content/public/browser/render_frame_host.h" |
38 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
40 #include "content/public/browser/web_contents_observer.h" | 41 #include "content/public/browser/web_contents_observer.h" |
41 #include "content/public/common/child_process_host.h" | 42 #include "content/public/common/child_process_host.h" |
42 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
43 #include "content/public/common/content_switches.h" | 44 #include "content/public/common/content_switches.h" |
44 #include "content/public/common/result_codes.h" | 45 #include "content/public/common/result_codes.h" |
46 #include "content/public/common/service_registry.h" | |
45 #include "net/http/http_response_headers.h" | 47 #include "net/http/http_response_headers.h" |
46 #include "net/http/http_response_info.h" | 48 #include "net/http/http_response_info.h" |
47 | 49 |
48 namespace content { | 50 namespace content { |
49 | 51 |
50 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 52 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
51 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; | 53 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; |
52 using GetClientsCallback = | 54 using GetClientsCallback = |
53 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; | 55 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; |
54 | 56 |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 // Schedule calling this method after starting the worker. | 795 // Schedule calling this method after starting the worker. |
794 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 796 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
795 weak_factory_.GetWeakPtr(), callback, | 797 weak_factory_.GetWeakPtr(), callback, |
796 base::Bind(&self::DispatchSyncEvent, | 798 base::Bind(&self::DispatchSyncEvent, |
797 weak_factory_.GetWeakPtr(), | 799 weak_factory_.GetWeakPtr(), |
798 callback))); | 800 callback))); |
799 return; | 801 return; |
800 } | 802 } |
801 | 803 |
802 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); | 804 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); |
803 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 805 if (!background_sync_dispatcher_) { |
804 ServiceWorkerMsg_SyncEvent(request_id)); | 806 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( |
805 if (status != SERVICE_WORKER_OK) { | 807 mojo::GetProxy(&background_sync_dispatcher_)); |
806 sync_requests_.Remove(request_id); | 808 // TODO(iclelland): Register an appropriate mojo error handler with |
807 RunSoon(base::Bind(callback, status)); | 809 // set_connection_error_handler. This will be straightforward once |
810 // https://codereview.chromium.org/1210643002 lands. | |
Marijn Kruisselbrink
2015/07/17 17:12:15
In the last version of that CL I actually got rid
iclelland
2015/07/20 16:06:16
Cool, thanks for the heads-up. I've updated this t
| |
808 } | 811 } |
812 | |
813 // TODO(iclelland): Replace this with the real event registration details | |
814 // crbug.com/482066 | |
815 content::SyncRegistrationPtr null_event(content::SyncRegistration::New()); | |
816 | |
817 background_sync_dispatcher_->Sync( | |
818 null_event.Pass(), base::Bind(&self::OnSyncEventFinished, | |
819 weak_factory_.GetWeakPtr(), request_id)); | |
809 } | 820 } |
810 | 821 |
811 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 822 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
812 const StatusCallback& callback, | 823 const StatusCallback& callback, |
813 int64_t persistent_notification_id, | 824 int64_t persistent_notification_id, |
814 const PlatformNotificationData& notification_data) { | 825 const PlatformNotificationData& notification_data) { |
815 DCHECK_EQ(ACTIVATED, status()) << status(); | 826 DCHECK_EQ(ACTIVATED, status()) << status(); |
816 if (running_status() != RUNNING) { | 827 if (running_status() != RUNNING) { |
817 // Schedule calling this method after starting the worker. | 828 // Schedule calling this method after starting the worker. |
818 StartWorker(base::Bind( | 829 StartWorker(base::Bind( |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1188 bool handled = true; | 1199 bool handled = true; |
1189 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 1200 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
1190 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 1201 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
1191 OnGetClients) | 1202 OnGetClients) |
1192 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 1203 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
1193 OnActivateEventFinished) | 1204 OnActivateEventFinished) |
1194 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 1205 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
1195 OnInstallEventFinished) | 1206 OnInstallEventFinished) |
1196 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 1207 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
1197 OnFetchEventFinished) | 1208 OnFetchEventFinished) |
1198 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, | |
1199 OnSyncEventFinished) | |
1200 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 1209 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
1201 OnNotificationClickEventFinished) | 1210 OnNotificationClickEventFinished) |
1202 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | 1211 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
1203 OnPushEventFinished) | 1212 OnPushEventFinished) |
1204 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, | 1213 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, |
1205 OnGeofencingEventFinished) | 1214 OnGeofencingEventFinished) |
1206 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, | 1215 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, |
1207 OnCrossOriginConnectEventFinished) | 1216 OnCrossOriginConnectEventFinished) |
1208 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 1217 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
1209 OnOpenWindow) | 1218 OnOpenWindow) |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 ServiceWorkerMetrics::RecordFetchEventTime( | 1384 ServiceWorkerMetrics::RecordFetchEventTime( |
1376 result, base::TimeTicks::Now() - request->start_time); | 1385 result, base::TimeTicks::Now() - request->start_time); |
1377 | 1386 |
1378 scoped_refptr<ServiceWorkerVersion> protect(this); | 1387 scoped_refptr<ServiceWorkerVersion> protect(this); |
1379 request->callback.Run(SERVICE_WORKER_OK, result, response); | 1388 request->callback.Run(SERVICE_WORKER_OK, result, response); |
1380 RemoveCallbackAndStopIfRedundant(&fetch_requests_, request_id); | 1389 RemoveCallbackAndStopIfRedundant(&fetch_requests_, request_id); |
1381 } | 1390 } |
1382 | 1391 |
1383 void ServiceWorkerVersion::OnSyncEventFinished( | 1392 void ServiceWorkerVersion::OnSyncEventFinished( |
1384 int request_id, | 1393 int request_id, |
1385 blink::WebServiceWorkerEventResult result) { | 1394 ServiceWorkerEventStatus status) { |
1386 TRACE_EVENT1("ServiceWorker", | 1395 TRACE_EVENT1("ServiceWorker", |
1387 "ServiceWorkerVersion::OnSyncEventFinished", | 1396 "ServiceWorkerVersion::OnSyncEventFinished", |
1388 "Request id", request_id); | 1397 "Request id", request_id); |
1389 PendingRequest<StatusCallback>* request = sync_requests_.Lookup(request_id); | 1398 PendingRequest<StatusCallback>* request = sync_requests_.Lookup(request_id); |
1390 if (!request) { | 1399 if (!request) { |
1391 NOTREACHED() << "Got unexpected message: " << request_id; | 1400 NOTREACHED() << "Got unexpected message: " << request_id; |
1392 return; | 1401 return; |
1393 } | 1402 } |
1394 | 1403 |
1395 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
1396 if (result == blink::WebServiceWorkerEventResultRejected) { | |
1397 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
1398 } | |
1399 | |
1400 scoped_refptr<ServiceWorkerVersion> protect(this); | 1404 scoped_refptr<ServiceWorkerVersion> protect(this); |
1401 request->callback.Run(status); | 1405 request->callback.Run(mojo::ConvertTo<ServiceWorkerStatusCode>(status)); |
1402 RemoveCallbackAndStopIfRedundant(&sync_requests_, request_id); | 1406 RemoveCallbackAndStopIfRedundant(&sync_requests_, request_id); |
1403 } | 1407 } |
1404 | 1408 |
1405 void ServiceWorkerVersion::OnNotificationClickEventFinished( | 1409 void ServiceWorkerVersion::OnNotificationClickEventFinished( |
1406 int request_id) { | 1410 int request_id) { |
1407 TRACE_EVENT1("ServiceWorker", | 1411 TRACE_EVENT1("ServiceWorker", |
1408 "ServiceWorkerVersion::OnNotificationClickEventFinished", | 1412 "ServiceWorkerVersion::OnNotificationClickEventFinished", |
1409 "Request id", request_id); | 1413 "Request id", request_id); |
1410 PendingRequest<StatusCallback>* request = | 1414 PendingRequest<StatusCallback>* request = |
1411 notification_click_requests_.Lookup(request_id); | 1415 notification_click_requests_.Lookup(request_id); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2196 | 2200 |
2197 streaming_url_request_jobs_.clear(); | 2201 streaming_url_request_jobs_.clear(); |
2198 | 2202 |
2199 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 2203 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
2200 | 2204 |
2201 if (should_restart) | 2205 if (should_restart) |
2202 StartWorkerInternal(); | 2206 StartWorkerInternal(); |
2203 } | 2207 } |
2204 | 2208 |
2205 } // namespace content | 2209 } // namespace content |
OLD | NEW |