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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
33 #include "content/public/browser/page_navigator.h" | 33 #include "content/public/browser/page_navigator.h" |
34 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
35 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/web_contents_observer.h" | 37 #include "content/public/browser/web_contents_observer.h" |
38 #include "content/public/common/child_process_host.h" | 38 #include "content/public/common/child_process_host.h" |
39 #include "content/public/common/content_client.h" | 39 #include "content/public/common/content_client.h" |
40 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
41 #include "content/public/common/result_codes.h" | 41 #include "content/public/common/result_codes.h" |
42 #include "content/public/common/service_registry.h" | |
42 #include "net/http/http_response_headers.h" | 43 #include "net/http/http_response_headers.h" |
43 #include "net/http/http_response_info.h" | 44 #include "net/http/http_response_info.h" |
44 | 45 |
45 namespace content { | 46 namespace content { |
46 | 47 |
47 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 48 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
48 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; | 49 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; |
49 using GetClientsCallback = | 50 using GetClientsCallback = |
50 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; | 51 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; |
51 | 52 |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 // Schedule calling this method after starting the worker. | 748 // Schedule calling this method after starting the worker. |
748 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 749 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
749 weak_factory_.GetWeakPtr(), callback, | 750 weak_factory_.GetWeakPtr(), callback, |
750 base::Bind(&self::DispatchSyncEvent, | 751 base::Bind(&self::DispatchSyncEvent, |
751 weak_factory_.GetWeakPtr(), | 752 weak_factory_.GetWeakPtr(), |
752 callback))); | 753 callback))); |
753 return; | 754 return; |
754 } | 755 } |
755 | 756 |
756 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); | 757 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); |
757 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 758 mojo_event_dispatcher_.DispatchSyncEvent( |
758 ServiceWorkerMsg_SyncEvent(request_id)); | 759 embedded_worker_->process_id(), embedded_worker_->thread_id(), |
michaeln
2015/06/24 00:12:01
This won't quite work because ServiceWorkerVersion
iclelland
2015/06/25 15:17:34
I've uploaded a new patchset that does just this -
| |
759 if (status != SERVICE_WORKER_OK) { | 760 base::Bind(&self::OnSyncEventFinished, weak_factory_.GetWeakPtr(), |
760 sync_callbacks_.Remove(request_id); | 761 request_id)); |
761 RunSoon(base::Bind(callback, status)); | |
762 } | |
763 } | 762 } |
764 | 763 |
765 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 764 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
766 const StatusCallback& callback, | 765 const StatusCallback& callback, |
767 int64_t persistent_notification_id, | 766 int64_t persistent_notification_id, |
768 const PlatformNotificationData& notification_data) { | 767 const PlatformNotificationData& notification_data) { |
769 DCHECK_EQ(ACTIVATED, status()) << status(); | 768 DCHECK_EQ(ACTIVATED, status()) << status(); |
770 if (running_status() != RUNNING) { | 769 if (running_status() != RUNNING) { |
771 // Schedule calling this method after starting the worker. | 770 // Schedule calling this method after starting the worker. |
772 StartWorker(base::Bind( | 771 StartWorker(base::Bind( |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1167 bool handled = true; | 1166 bool handled = true; |
1168 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 1167 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
1169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 1168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
1170 OnGetClients) | 1169 OnGetClients) |
1171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 1170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
1172 OnActivateEventFinished) | 1171 OnActivateEventFinished) |
1173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 1172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
1174 OnInstallEventFinished) | 1173 OnInstallEventFinished) |
1175 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 1174 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
1176 OnFetchEventFinished) | 1175 OnFetchEventFinished) |
1177 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, | |
1178 OnSyncEventFinished) | |
1179 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 1176 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
1180 OnNotificationClickEventFinished) | 1177 OnNotificationClickEventFinished) |
1181 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | 1178 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
1182 OnPushEventFinished) | 1179 OnPushEventFinished) |
1183 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, | 1180 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, |
1184 OnGeofencingEventFinished) | 1181 OnGeofencingEventFinished) |
1185 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, | 1182 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, |
1186 OnCrossOriginConnectEventFinished) | 1183 OnCrossOriginConnectEventFinished) |
1187 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 1184 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
1188 OnOpenWindow) | 1185 OnOpenWindow) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 | 1337 |
1341 // TODO(kinuko): Record other event statuses too. | 1338 // TODO(kinuko): Record other event statuses too. |
1342 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 1339 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
1343 metrics_->RecordEventStatus(handled); | 1340 metrics_->RecordEventStatus(handled); |
1344 | 1341 |
1345 scoped_refptr<ServiceWorkerVersion> protect(this); | 1342 scoped_refptr<ServiceWorkerVersion> protect(this); |
1346 callback->Run(SERVICE_WORKER_OK, result, response); | 1343 callback->Run(SERVICE_WORKER_OK, result, response); |
1347 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); | 1344 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); |
1348 } | 1345 } |
1349 | 1346 |
1350 void ServiceWorkerVersion::OnSyncEventFinished( | 1347 void ServiceWorkerVersion::OnSyncEventFinished(int request_id, |
1351 int request_id, | 1348 ServiceWorkerStatusCode status) { |
1352 blink::WebServiceWorkerEventResult result) { | |
1353 TRACE_EVENT1("ServiceWorker", | 1349 TRACE_EVENT1("ServiceWorker", |
1354 "ServiceWorkerVersion::OnSyncEventFinished", | 1350 "ServiceWorkerVersion::OnSyncEventFinished", |
1355 "Request id", request_id); | 1351 "Request id", request_id); |
1356 StatusCallback* callback = sync_callbacks_.Lookup(request_id); | 1352 StatusCallback* callback = sync_callbacks_.Lookup(request_id); |
1357 if (!callback) { | 1353 if (!callback) { |
1358 NOTREACHED() << "Got unexpected message: " << request_id; | 1354 NOTREACHED() << "Got unexpected message: " << request_id; |
1359 return; | 1355 return; |
1360 } | 1356 } |
1361 | 1357 |
1362 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
1363 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1358 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
1364 switches::kEnableServiceWorkerSync)) { | 1359 switches::kEnableServiceWorkerSync)) { |
1365 // Avoid potential race condition where flag is disabled after a sync event | 1360 // Avoid potential race condition where flag is disabled after a sync event |
1366 // was dispatched | 1361 // was dispatched |
1367 status = SERVICE_WORKER_ERROR_ABORT; | 1362 status = SERVICE_WORKER_ERROR_ABORT; |
1368 } else if (result == blink::WebServiceWorkerEventResultRejected) { | |
1369 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
1370 } | 1363 } |
1371 | 1364 |
1372 scoped_refptr<ServiceWorkerVersion> protect(this); | 1365 scoped_refptr<ServiceWorkerVersion> protect(this); |
1373 callback->Run(status); | 1366 callback->Run(status); |
1374 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); | 1367 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); |
1375 } | 1368 } |
1376 | 1369 |
1377 void ServiceWorkerVersion::OnNotificationClickEventFinished( | 1370 void ServiceWorkerVersion::OnNotificationClickEventFinished( |
1378 int request_id) { | 1371 int request_id) { |
1379 TRACE_EVENT1("ServiceWorker", | 1372 TRACE_EVENT1("ServiceWorker", |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2050 return SERVICE_WORKER_ERROR_ABORT; | 2043 return SERVICE_WORKER_ERROR_ABORT; |
2051 default: | 2044 default: |
2052 return SERVICE_WORKER_ERROR_NETWORK; | 2045 return SERVICE_WORKER_ERROR_NETWORK; |
2053 } | 2046 } |
2054 } | 2047 } |
2055 | 2048 |
2056 return default_code; | 2049 return default_code; |
2057 } | 2050 } |
2058 | 2051 |
2059 } // namespace content | 2052 } // namespace content |
OLD | NEW |