Chromium Code Reviews| 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" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/message_port_message_filter.h" | 19 #include "content/browser/message_port_message_filter.h" |
| 20 #include "content/browser/message_port_service.h" | 20 #include "content/browser/message_port_service.h" |
| 21 #include "content/browser/service_worker/embedded_worker_instance.h" | 21 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 22 #include "content/browser/service_worker/embedded_worker_registry.h" | 22 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 23 #include "content/browser/service_worker/service_worker_context_core.h" | 23 #include "content/browser/service_worker/service_worker_context_core.h" |
| 24 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 24 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 25 #include "content/browser/service_worker/service_worker_metrics.h" | 25 #include "content/browser/service_worker/service_worker_metrics.h" |
| 26 #include "content/browser/service_worker/service_worker_mojo_event_dispatcher.h" | |
| 26 #include "content/browser/service_worker/service_worker_registration.h" | 27 #include "content/browser/service_worker/service_worker_registration.h" |
| 27 #include "content/browser/service_worker/service_worker_utils.h" | 28 #include "content/browser/service_worker/service_worker_utils.h" |
| 28 #include "content/browser/service_worker/stashed_port_manager.h" | 29 #include "content/browser/service_worker/stashed_port_manager.h" |
| 29 #include "content/browser/storage_partition_impl.h" | 30 #include "content/browser/storage_partition_impl.h" |
| 30 #include "content/common/service_worker/service_worker_messages.h" | 31 #include "content/common/service_worker/service_worker_messages.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
| 33 #include "content/public/browser/page_navigator.h" | 34 #include "content/public/browser/page_navigator.h" |
| 34 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 35 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_contents_observer.h" | 38 #include "content/public/browser/web_contents_observer.h" |
| 38 #include "content/public/common/child_process_host.h" | 39 #include "content/public/common/child_process_host.h" |
| 39 #include "content/public/common/content_client.h" | 40 #include "content/public/common/content_client.h" |
| 40 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/common/result_codes.h" | 42 #include "content/public/common/result_codes.h" |
| 43 #include "content/public/common/service_registry.h" | |
| 42 #include "net/http/http_response_headers.h" | 44 #include "net/http/http_response_headers.h" |
| 43 #include "net/http/http_response_info.h" | 45 #include "net/http/http_response_info.h" |
| 44 | 46 |
| 45 namespace content { | 47 namespace content { |
| 46 | 48 |
| 47 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 49 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
| 48 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; | 50 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>; |
| 49 using GetClientsCallback = | 51 using GetClientsCallback = |
| 50 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; | 52 base::Callback<void(scoped_ptr<ServiceWorkerClients>)>; |
| 51 | 53 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 int64 version_id, | 476 int64 version_id, |
| 475 base::WeakPtr<ServiceWorkerContextCore> context) | 477 base::WeakPtr<ServiceWorkerContextCore> context) |
| 476 : version_id_(version_id), | 478 : version_id_(version_id), |
| 477 registration_id_(registration->id()), | 479 registration_id_(registration->id()), |
| 478 script_url_(script_url), | 480 script_url_(script_url), |
| 479 scope_(registration->pattern()), | 481 scope_(registration->pattern()), |
| 480 context_(context), | 482 context_(context), |
| 481 script_cache_map_(this, context), | 483 script_cache_map_(this, context), |
| 482 ping_controller_(new PingController(this)), | 484 ping_controller_(new PingController(this)), |
| 483 metrics_(new Metrics), | 485 metrics_(new Metrics), |
| 486 mojo_event_dispatcher_(new ServiceWorkerMojoEventDispatcher()), | |
| 484 weak_factory_(this) { | 487 weak_factory_(this) { |
| 485 DCHECK(context_); | 488 DCHECK(context_); |
| 486 DCHECK(registration); | 489 DCHECK(registration); |
| 487 context_->AddLiveVersion(this); | 490 context_->AddLiveVersion(this); |
| 488 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); | 491 embedded_worker_ = context_->embedded_worker_registry()->CreateWorker(); |
| 489 embedded_worker_->AddListener(this); | 492 embedded_worker_->AddListener(this); |
| 490 } | 493 } |
| 491 | 494 |
| 492 ServiceWorkerVersion::~ServiceWorkerVersion() { | 495 ServiceWorkerVersion::~ServiceWorkerVersion() { |
| 493 // The user may have closed the tab waiting for SW to start up. | 496 // The user may have closed the tab waiting for SW to start up. |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 if (running_status() != RUNNING) { | 738 if (running_status() != RUNNING) { |
| 736 // Schedule calling this method after starting the worker. | 739 // Schedule calling this method after starting the worker. |
| 737 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 740 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| 738 weak_factory_.GetWeakPtr(), callback, | 741 weak_factory_.GetWeakPtr(), callback, |
| 739 base::Bind(&self::DispatchSyncEvent, | 742 base::Bind(&self::DispatchSyncEvent, |
| 740 weak_factory_.GetWeakPtr(), | 743 weak_factory_.GetWeakPtr(), |
| 741 callback))); | 744 callback))); |
| 742 return; | 745 return; |
| 743 } | 746 } |
| 744 | 747 |
| 745 int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); | 748 mojo_event_dispatcher_->DispatchSyncEvent( |
| 746 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 749 embedded_worker_->process_id(), embedded_worker_->thread_id(), callback); |
| 747 ServiceWorkerMsg_SyncEvent(request_id)); | |
| 748 if (status != SERVICE_WORKER_OK) { | |
| 749 sync_callbacks_.Remove(request_id); | |
| 750 RunSoon(base::Bind(callback, status)); | |
| 751 } | |
| 752 } | 750 } |
| 753 | 751 |
| 754 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 752 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
| 755 const StatusCallback& callback, | 753 const StatusCallback& callback, |
| 756 int64_t persistent_notification_id, | 754 int64_t persistent_notification_id, |
| 757 const PlatformNotificationData& notification_data) { | 755 const PlatformNotificationData& notification_data) { |
| 758 DCHECK_EQ(ACTIVATED, status()) << status(); | 756 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 759 if (running_status() != RUNNING) { | 757 if (running_status() != RUNNING) { |
| 760 // Schedule calling this method after starting the worker. | 758 // Schedule calling this method after starting the worker. |
| 761 StartWorker(base::Bind( | 759 StartWorker(base::Bind( |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 // callbacks for events). | 1092 // callbacks for events). |
| 1095 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. | 1093 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. |
| 1096 RunIDMapCallbacks(&activate_callbacks_, | 1094 RunIDMapCallbacks(&activate_callbacks_, |
| 1097 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); | 1095 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); |
| 1098 RunIDMapCallbacks(&install_callbacks_, | 1096 RunIDMapCallbacks(&install_callbacks_, |
| 1099 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 1097 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
| 1100 RunIDMapCallbacks(&fetch_callbacks_, | 1098 RunIDMapCallbacks(&fetch_callbacks_, |
| 1101 SERVICE_WORKER_ERROR_FAILED, | 1099 SERVICE_WORKER_ERROR_FAILED, |
| 1102 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 1100 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
| 1103 ServiceWorkerResponse()); | 1101 ServiceWorkerResponse()); |
| 1104 RunIDMapCallbacks(&sync_callbacks_, | |
| 1105 SERVICE_WORKER_ERROR_FAILED); | |
|
jkarlin
2015/06/17 15:17:29
We still need this (or an equivalent) to stop the
iclelland
2015/06/18 16:01:14
Done.
| |
| 1106 RunIDMapCallbacks(¬ification_click_callbacks_, | 1102 RunIDMapCallbacks(¬ification_click_callbacks_, |
| 1107 SERVICE_WORKER_ERROR_FAILED); | 1103 SERVICE_WORKER_ERROR_FAILED); |
| 1108 RunIDMapCallbacks(&push_callbacks_, | 1104 RunIDMapCallbacks(&push_callbacks_, |
| 1109 SERVICE_WORKER_ERROR_FAILED); | 1105 SERVICE_WORKER_ERROR_FAILED); |
| 1110 RunIDMapCallbacks(&geofencing_callbacks_, | 1106 RunIDMapCallbacks(&geofencing_callbacks_, |
| 1111 SERVICE_WORKER_ERROR_FAILED); | 1107 SERVICE_WORKER_ERROR_FAILED); |
| 1112 RunIDMapCallbacks(&cross_origin_connect_callbacks_, | 1108 RunIDMapCallbacks(&cross_origin_connect_callbacks_, |
| 1113 SERVICE_WORKER_ERROR_FAILED, | 1109 SERVICE_WORKER_ERROR_FAILED, |
| 1114 false); | 1110 false); |
| 1115 | 1111 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 bool handled = true; | 1148 bool handled = true; |
| 1153 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 1149 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
| 1154 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 1150 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
| 1155 OnGetClients) | 1151 OnGetClients) |
| 1156 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 1152 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
| 1157 OnActivateEventFinished) | 1153 OnActivateEventFinished) |
| 1158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 1154 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
| 1159 OnInstallEventFinished) | 1155 OnInstallEventFinished) |
| 1160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 1156 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
| 1161 OnFetchEventFinished) | 1157 OnFetchEventFinished) |
| 1162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, | |
| 1163 OnSyncEventFinished) | |
| 1164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 1158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
| 1165 OnNotificationClickEventFinished) | 1159 OnNotificationClickEventFinished) |
| 1166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | 1160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
| 1167 OnPushEventFinished) | 1161 OnPushEventFinished) |
| 1168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, | 1162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, |
| 1169 OnGeofencingEventFinished) | 1163 OnGeofencingEventFinished) |
| 1170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, | 1164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, |
| 1171 OnCrossOriginConnectEventFinished) | 1165 OnCrossOriginConnectEventFinished) |
| 1172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 1166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
| 1173 OnOpenWindow) | 1167 OnOpenWindow) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1184 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, | 1178 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, |
| 1185 OnClaimClients) | 1179 OnClaimClients) |
| 1186 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker) | 1180 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker) |
| 1187 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_StashMessagePort, | 1181 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_StashMessagePort, |
| 1188 OnStashMessagePort) | 1182 OnStashMessagePort) |
| 1189 IPC_MESSAGE_UNHANDLED(handled = false) | 1183 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1190 IPC_END_MESSAGE_MAP() | 1184 IPC_END_MESSAGE_MAP() |
| 1191 return handled; | 1185 return handled; |
| 1192 } | 1186 } |
| 1193 | 1187 |
| 1188 void ServiceWorkerVersion::OnSyncEventFinished(const StatusCallback& callback, | |
| 1189 ServiceWorkerStatusCode status) { | |
| 1190 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 1191 TRACE_EVENT0("ServiceWorker", "ServiceWorkerVersion::OnSyncEventFinished") | |
| 1192 | |
| 1193 scoped_refptr<ServiceWorkerVersion> protect(this); | |
| 1194 callback.Run(status); | |
| 1195 StopIfRedundant(); | |
| 1196 } | |
| 1197 | |
| 1194 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( | 1198 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( |
| 1195 ServiceWorkerStatusCode status) { | 1199 ServiceWorkerStatusCode status) { |
| 1196 if (status != SERVICE_WORKER_OK) { | 1200 if (status != SERVICE_WORKER_OK) { |
| 1197 RunCallbacks(this, &start_callbacks_, | 1201 RunCallbacks(this, &start_callbacks_, |
| 1198 DeduceStartWorkerFailureReason(status)); | 1202 DeduceStartWorkerFailureReason(status)); |
| 1199 } | 1203 } |
| 1200 } | 1204 } |
| 1201 | 1205 |
| 1202 void ServiceWorkerVersion::DispatchInstallEventAfterStartWorker( | 1206 void ServiceWorkerVersion::DispatchInstallEventAfterStartWorker( |
| 1203 const StatusCallback& callback) { | 1207 const StatusCallback& callback) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1325 | 1329 |
| 1326 // TODO(kinuko): Record other event statuses too. | 1330 // TODO(kinuko): Record other event statuses too. |
| 1327 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 1331 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
| 1328 metrics_->RecordEventStatus(handled); | 1332 metrics_->RecordEventStatus(handled); |
| 1329 | 1333 |
| 1330 scoped_refptr<ServiceWorkerVersion> protect(this); | 1334 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1331 callback->Run(SERVICE_WORKER_OK, result, response); | 1335 callback->Run(SERVICE_WORKER_OK, result, response); |
| 1332 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); | 1336 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); |
| 1333 } | 1337 } |
| 1334 | 1338 |
| 1335 void ServiceWorkerVersion::OnSyncEventFinished( | |
| 1336 int request_id, | |
| 1337 blink::WebServiceWorkerEventResult result) { | |
| 1338 TRACE_EVENT1("ServiceWorker", | |
| 1339 "ServiceWorkerVersion::OnSyncEventFinished", | |
| 1340 "Request id", request_id); | |
| 1341 StatusCallback* callback = sync_callbacks_.Lookup(request_id); | |
| 1342 if (!callback) { | |
| 1343 NOTREACHED() << "Got unexpected message: " << request_id; | |
| 1344 return; | |
| 1345 } | |
| 1346 | |
| 1347 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
| 1348 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1349 switches::kEnableServiceWorkerSync)) { | |
| 1350 // Avoid potential race condition where flag is disabled after a sync event | |
| 1351 // was dispatched | |
| 1352 status = SERVICE_WORKER_ERROR_ABORT; | |
| 1353 } else if (result == blink::WebServiceWorkerEventResultRejected) { | |
| 1354 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
| 1355 } | |
| 1356 | |
| 1357 scoped_refptr<ServiceWorkerVersion> protect(this); | |
| 1358 callback->Run(status); | |
| 1359 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); | |
| 1360 } | |
| 1361 | |
| 1362 void ServiceWorkerVersion::OnNotificationClickEventFinished( | 1339 void ServiceWorkerVersion::OnNotificationClickEventFinished( |
| 1363 int request_id) { | 1340 int request_id) { |
| 1364 TRACE_EVENT1("ServiceWorker", | 1341 TRACE_EVENT1("ServiceWorker", |
| 1365 "ServiceWorkerVersion::OnNotificationClickEventFinished", | 1342 "ServiceWorkerVersion::OnNotificationClickEventFinished", |
| 1366 "Request id", request_id); | 1343 "Request id", request_id); |
| 1367 StatusCallback* callback = notification_click_callbacks_.Lookup(request_id); | 1344 StatusCallback* callback = notification_click_callbacks_.Lookup(request_id); |
| 1368 if (!callback) { | 1345 if (!callback) { |
| 1369 NOTREACHED() << "Got unexpected message: " << request_id; | 1346 NOTREACHED() << "Got unexpected message: " << request_id; |
| 1370 return; | 1347 return; |
| 1371 } | 1348 } |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1896 // forcibly fail pending callbacks so no one is stuck waiting | 1873 // forcibly fail pending callbacks so no one is stuck waiting |
| 1897 // for the worker. | 1874 // for the worker. |
| 1898 embedded_worker_->StopIfIdle(); | 1875 embedded_worker_->StopIfIdle(); |
| 1899 } | 1876 } |
| 1900 | 1877 |
| 1901 bool ServiceWorkerVersion::HasInflightRequests() const { | 1878 bool ServiceWorkerVersion::HasInflightRequests() const { |
| 1902 return | 1879 return |
| 1903 !activate_callbacks_.IsEmpty() || | 1880 !activate_callbacks_.IsEmpty() || |
| 1904 !install_callbacks_.IsEmpty() || | 1881 !install_callbacks_.IsEmpty() || |
| 1905 !fetch_callbacks_.IsEmpty() || | 1882 !fetch_callbacks_.IsEmpty() || |
| 1906 !sync_callbacks_.IsEmpty() || | |
|
jkarlin
2015/06/17 15:17:29
We can't just get rid of this. HasInflightRequests
iclelland
2015/06/18 16:01:14
Done.
| |
| 1907 !notification_click_callbacks_.IsEmpty() || | 1883 !notification_click_callbacks_.IsEmpty() || |
| 1908 !push_callbacks_.IsEmpty() || | 1884 !push_callbacks_.IsEmpty() || |
| 1909 !geofencing_callbacks_.IsEmpty() || | 1885 !geofencing_callbacks_.IsEmpty() || |
| 1910 !cross_origin_connect_callbacks_.IsEmpty() || | 1886 !cross_origin_connect_callbacks_.IsEmpty() || |
| 1911 !streaming_url_request_jobs_.empty(); | 1887 !streaming_url_request_jobs_.empty(); |
| 1912 } | 1888 } |
| 1913 | 1889 |
| 1914 void ServiceWorkerVersion::RecordStartWorkerResult( | 1890 void ServiceWorkerVersion::RecordStartWorkerResult( |
| 1915 ServiceWorkerStatusCode status) { | 1891 ServiceWorkerStatusCode status) { |
| 1916 base::TimeTicks start_time = start_time_; | 1892 base::TimeTicks start_time = start_time_; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1942 message.append(EmbeddedWorkerInstance::StartingPhaseToString(phase)); | 1918 message.append(EmbeddedWorkerInstance::StartingPhaseToString(phase)); |
| 1943 } | 1919 } |
| 1944 message.append("."); | 1920 message.append("."); |
| 1945 OnReportException(base::UTF8ToUTF16(message), -1, -1, GURL()); | 1921 OnReportException(base::UTF8ToUTF16(message), -1, -1, GURL()); |
| 1946 DVLOG(1) << message; | 1922 DVLOG(1) << message; |
| 1947 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.TimeoutPhase", | 1923 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.TimeoutPhase", |
| 1948 phase, | 1924 phase, |
| 1949 EmbeddedWorkerInstance::STARTING_PHASE_MAX_VALUE); | 1925 EmbeddedWorkerInstance::STARTING_PHASE_MAX_VALUE); |
| 1950 } | 1926 } |
| 1951 | 1927 |
| 1952 template <typename IDMAP> | 1928 void ServiceWorkerVersion::StopIfRedundant() { |
| 1953 void ServiceWorkerVersion::RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, | |
| 1954 int request_id) { | |
| 1955 RestartTick(&idle_time_); | 1929 RestartTick(&idle_time_); |
| 1956 callbacks->Remove(request_id); | |
| 1957 if (is_redundant()) { | 1930 if (is_redundant()) { |
| 1958 // The stop should be already scheduled, but try to stop immediately, in | 1931 // The stop should be already scheduled, but try to stop immediately, in |
| 1959 // order to release worker resources soon. | 1932 // order to release worker resources soon. |
| 1960 StopWorkerIfIdle(); | 1933 StopWorkerIfIdle(); |
| 1961 } | 1934 } |
| 1962 } | 1935 } |
| 1963 | 1936 |
| 1937 template <typename IDMAP> | |
| 1938 void ServiceWorkerVersion::RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, | |
| 1939 int request_id) { | |
| 1940 callbacks->Remove(request_id); | |
| 1941 StopIfRedundant(); | |
| 1942 } | |
| 1943 | |
| 1964 template <typename CallbackType> | 1944 template <typename CallbackType> |
| 1965 int ServiceWorkerVersion::AddRequest( | 1945 int ServiceWorkerVersion::AddRequest( |
| 1966 const CallbackType& callback, | 1946 const CallbackType& callback, |
| 1967 IDMap<CallbackType, IDMapOwnPointer>* callback_map, | 1947 IDMap<CallbackType, IDMapOwnPointer>* callback_map, |
| 1968 RequestType request_type) { | 1948 RequestType request_type) { |
| 1969 int request_id = callback_map->Add(new CallbackType(callback)); | 1949 int request_id = callback_map->Add(new CallbackType(callback)); |
| 1970 requests_.push(RequestInfo(request_id, request_type)); | 1950 requests_.push(RequestInfo(request_id, request_type)); |
| 1971 return request_id; | 1951 return request_id; |
| 1972 } | 1952 } |
| 1973 | 1953 |
| 1974 bool ServiceWorkerVersion::OnRequestTimeout(const RequestInfo& info) { | 1954 bool ServiceWorkerVersion::OnRequestTimeout(const RequestInfo& info) { |
| 1975 switch (info.type) { | 1955 switch (info.type) { |
| 1976 case REQUEST_ACTIVATE: | 1956 case REQUEST_ACTIVATE: |
| 1977 return RunIDMapCallback(&activate_callbacks_, info.id, | 1957 return RunIDMapCallback(&activate_callbacks_, info.id, |
| 1978 SERVICE_WORKER_ERROR_TIMEOUT); | 1958 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1979 case REQUEST_INSTALL: | 1959 case REQUEST_INSTALL: |
| 1980 return RunIDMapCallback(&install_callbacks_, info.id, | 1960 return RunIDMapCallback(&install_callbacks_, info.id, |
| 1981 SERVICE_WORKER_ERROR_TIMEOUT); | 1961 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1982 case REQUEST_FETCH: | 1962 case REQUEST_FETCH: |
| 1983 return RunIDMapCallback( | 1963 return RunIDMapCallback( |
| 1984 &fetch_callbacks_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, | 1964 &fetch_callbacks_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, |
| 1985 /* The other args are ignored for non-OK status. */ | 1965 /* The other args are ignored for non-OK status. */ |
| 1986 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); | 1966 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); |
| 1987 case REQUEST_SYNC: | |
| 1988 return RunIDMapCallback(&sync_callbacks_, info.id, | |
|
jkarlin
2015/06/17 15:17:29
We still need this (or an equivalent) to time out
iclelland
2015/06/18 16:01:14
Done.
| |
| 1989 SERVICE_WORKER_ERROR_TIMEOUT); | |
| 1990 case REQUEST_NOTIFICATION_CLICK: | 1967 case REQUEST_NOTIFICATION_CLICK: |
| 1991 return RunIDMapCallback(¬ification_click_callbacks_, info.id, | 1968 return RunIDMapCallback(¬ification_click_callbacks_, info.id, |
| 1992 SERVICE_WORKER_ERROR_TIMEOUT); | 1969 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1993 case REQUEST_PUSH: | 1970 case REQUEST_PUSH: |
| 1994 return RunIDMapCallback(&push_callbacks_, info.id, | 1971 return RunIDMapCallback(&push_callbacks_, info.id, |
| 1995 SERVICE_WORKER_ERROR_TIMEOUT); | 1972 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1996 case REQUEST_GEOFENCING: | 1973 case REQUEST_GEOFENCING: |
| 1997 return RunIDMapCallback(&geofencing_callbacks_, info.id, | 1974 return RunIDMapCallback(&geofencing_callbacks_, info.id, |
| 1998 SERVICE_WORKER_ERROR_TIMEOUT); | 1975 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1999 case REQUEST_CROSS_ORIGIN_CONNECT: | 1976 case REQUEST_CROSS_ORIGIN_CONNECT: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2035 return SERVICE_WORKER_ERROR_ABORT; | 2012 return SERVICE_WORKER_ERROR_ABORT; |
| 2036 default: | 2013 default: |
| 2037 return SERVICE_WORKER_ERROR_NETWORK; | 2014 return SERVICE_WORKER_ERROR_NETWORK; |
| 2038 } | 2015 } |
| 2039 } | 2016 } |
| 2040 | 2017 |
| 2041 return default_code; | 2018 return default_code; |
| 2042 } | 2019 } |
| 2043 | 2020 |
| 2044 } // namespace content | 2021 } // namespace content |
| OLD | NEW |