| 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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 // Schedule calling this method after starting the worker. | 741 // Schedule calling this method after starting the worker. |
| 741 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 742 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 742 weak_factory_.GetWeakPtr(), callback, | 743 weak_factory_.GetWeakPtr(), callback, |
| 743 base::Bind(&self::DispatchSyncEvent, | 744 base::Bind(&self::DispatchSyncEvent, |
| 744 weak_factory_.GetWeakPtr(), | 745 weak_factory_.GetWeakPtr(), |
| 745 callback))); | 746 callback))); |
| 746 return; | 747 return; |
| 747 } | 748 } |
| 748 | 749 |
| 749 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); | 750 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); |
| 750 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 751 mojo_event_dispatcher_.DispatchSyncEvent( |
| 751 ServiceWorkerMsg_SyncEvent(request_id)); | 752 embedded_worker_->process_id(), embedded_worker_->thread_id(), |
| 752 if (status != SERVICE_WORKER_OK) { | 753 base::Bind(&self::OnSyncEventFinished, weak_factory_.GetWeakPtr(), |
| 753 sync_callbacks_.Remove(request_id); | 754 request_id)); |
| 754 RunSoon(base::Bind(callback, status)); | |
| 755 } | |
| 756 } | 755 } |
| 757 | 756 |
| 758 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 757 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
| 759 const StatusCallback& callback, | 758 const StatusCallback& callback, |
| 760 int64_t persistent_notification_id, | 759 int64_t persistent_notification_id, |
| 761 const PlatformNotificationData& notification_data) { | 760 const PlatformNotificationData& notification_data) { |
| 762 DCHECK_EQ(ACTIVATED, status()) << status(); | 761 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 763 if (running_status() != RUNNING) { | 762 if (running_status() != RUNNING) { |
| 764 // Schedule calling this method after starting the worker. | 763 // Schedule calling this method after starting the worker. |
| 765 StartWorker(base::Bind( | 764 StartWorker(base::Bind( |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 bool handled = true; | 1155 bool handled = true; |
| 1157 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 1156 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
| 1158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 1157 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
| 1159 OnGetClients) | 1158 OnGetClients) |
| 1160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 1159 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
| 1161 OnActivateEventFinished) | 1160 OnActivateEventFinished) |
| 1162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 1161 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
| 1163 OnInstallEventFinished) | 1162 OnInstallEventFinished) |
| 1164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 1163 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
| 1165 OnFetchEventFinished) | 1164 OnFetchEventFinished) |
| 1166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, | |
| 1167 OnSyncEventFinished) | |
| 1168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 1165 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
| 1169 OnNotificationClickEventFinished) | 1166 OnNotificationClickEventFinished) |
| 1170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | 1167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
| 1171 OnPushEventFinished) | 1168 OnPushEventFinished) |
| 1172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, | 1169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, |
| 1173 OnGeofencingEventFinished) | 1170 OnGeofencingEventFinished) |
| 1174 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, | 1171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, |
| 1175 OnCrossOriginConnectEventFinished) | 1172 OnCrossOriginConnectEventFinished) |
| 1176 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 1173 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
| 1177 OnOpenWindow) | 1174 OnOpenWindow) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 | 1326 |
| 1330 // TODO(kinuko): Record other event statuses too. | 1327 // TODO(kinuko): Record other event statuses too. |
| 1331 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 1328 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
| 1332 metrics_->RecordEventStatus(handled); | 1329 metrics_->RecordEventStatus(handled); |
| 1333 | 1330 |
| 1334 scoped_refptr<ServiceWorkerVersion> protect(this); | 1331 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1335 callback->Run(SERVICE_WORKER_OK, result, response); | 1332 callback->Run(SERVICE_WORKER_OK, result, response); |
| 1336 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); | 1333 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); |
| 1337 } | 1334 } |
| 1338 | 1335 |
| 1339 void ServiceWorkerVersion::OnSyncEventFinished( | 1336 void ServiceWorkerVersion::OnSyncEventFinished(int request_id, |
| 1340 int request_id, | 1337 ServiceWorkerStatusCode status) { |
| 1341 blink::WebServiceWorkerEventResult result) { | |
| 1342 TRACE_EVENT1("ServiceWorker", | 1338 TRACE_EVENT1("ServiceWorker", |
| 1343 "ServiceWorkerVersion::OnSyncEventFinished", | 1339 "ServiceWorkerVersion::OnSyncEventFinished", |
| 1344 "Request id", request_id); | 1340 "Request id", request_id); |
| 1345 StatusCallback* callback = sync_callbacks_.Lookup(request_id); | 1341 StatusCallback* callback = sync_callbacks_.Lookup(request_id); |
| 1346 if (!callback) { | 1342 if (!callback) { |
| 1347 NOTREACHED() << "Got unexpected message: " << request_id; | 1343 NOTREACHED() << "Got unexpected message: " << request_id; |
| 1348 return; | 1344 return; |
| 1349 } | 1345 } |
| 1350 | 1346 |
| 1351 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
| 1352 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 1347 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1353 switches::kEnableServiceWorkerSync)) { | 1348 switches::kEnableServiceWorkerSync)) { |
| 1354 // Avoid potential race condition where flag is disabled after a sync event | 1349 // Avoid potential race condition where flag is disabled after a sync event |
| 1355 // was dispatched | 1350 // was dispatched |
| 1356 status = SERVICE_WORKER_ERROR_ABORT; | 1351 status = SERVICE_WORKER_ERROR_ABORT; |
| 1357 } else if (result == blink::WebServiceWorkerEventResultRejected) { | |
| 1358 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
| 1359 } | 1352 } |
| 1360 | 1353 |
| 1361 scoped_refptr<ServiceWorkerVersion> protect(this); | 1354 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1362 callback->Run(status); | 1355 callback->Run(status); |
| 1363 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); | 1356 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); |
| 1364 } | 1357 } |
| 1365 | 1358 |
| 1366 void ServiceWorkerVersion::OnNotificationClickEventFinished( | 1359 void ServiceWorkerVersion::OnNotificationClickEventFinished( |
| 1367 int request_id) { | 1360 int request_id) { |
| 1368 TRACE_EVENT1("ServiceWorker", | 1361 TRACE_EVENT1("ServiceWorker", |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 return SERVICE_WORKER_ERROR_ABORT; | 2032 return SERVICE_WORKER_ERROR_ABORT; |
| 2040 default: | 2033 default: |
| 2041 return SERVICE_WORKER_ERROR_NETWORK; | 2034 return SERVICE_WORKER_ERROR_NETWORK; |
| 2042 } | 2035 } |
| 2043 } | 2036 } |
| 2044 | 2037 |
| 2045 return default_code; | 2038 return default_code; |
| 2046 } | 2039 } |
| 2047 | 2040 |
| 2048 } // namespace content | 2041 } // namespace content |
| OLD | NEW |