Chromium Code Reviews| Index: content/browser/service_worker/service_worker_version.cc |
| diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc |
| index db9350a62ffd903432d75d9f46c334d3cfd6749f..ef55e0fa9954633e5f616dbf50d923f35c0834a2 100644 |
| --- a/content/browser/service_worker/service_worker_version.cc |
| +++ b/content/browser/service_worker/service_worker_version.cc |
| @@ -23,6 +23,7 @@ |
| #include "content/browser/service_worker/service_worker_context_core.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| #include "content/browser/service_worker/service_worker_metrics.h" |
| +#include "content/browser/service_worker/service_worker_mojo_event_dispatcher.h" |
| #include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/browser/service_worker/service_worker_utils.h" |
| #include "content/browser/service_worker/stashed_port_manager.h" |
| @@ -39,6 +40,7 @@ |
| #include "content/public/common/content_client.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/result_codes.h" |
| +#include "content/public/common/service_registry.h" |
| #include "net/http/http_response_headers.h" |
| #include "net/http/http_response_info.h" |
| @@ -481,6 +483,7 @@ ServiceWorkerVersion::ServiceWorkerVersion( |
| script_cache_map_(this, context), |
| ping_controller_(new PingController(this)), |
| metrics_(new Metrics), |
| + mojo_event_dispatcher_(new ServiceWorkerMojoEventDispatcher()), |
| weak_factory_(this) { |
| DCHECK(context_); |
| DCHECK(registration); |
| @@ -742,13 +745,8 @@ void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { |
| return; |
| } |
| - int request_id = AddRequest(callback, &sync_callbacks_, REQUEST_SYNC); |
| - ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
| - ServiceWorkerMsg_SyncEvent(request_id)); |
| - if (status != SERVICE_WORKER_OK) { |
| - sync_callbacks_.Remove(request_id); |
| - RunSoon(base::Bind(callback, status)); |
| - } |
| + mojo_event_dispatcher_->DispatchSyncEvent( |
| + embedded_worker_->process_id(), embedded_worker_->thread_id(), callback); |
| } |
| void ServiceWorkerVersion::DispatchNotificationClickEvent( |
| @@ -1101,8 +1099,6 @@ void ServiceWorkerVersion::OnStopped( |
| SERVICE_WORKER_ERROR_FAILED, |
| SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
| ServiceWorkerResponse()); |
| - RunIDMapCallbacks(&sync_callbacks_, |
| - 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.
|
| RunIDMapCallbacks(¬ification_click_callbacks_, |
| SERVICE_WORKER_ERROR_FAILED); |
| RunIDMapCallbacks(&push_callbacks_, |
| @@ -1159,8 +1155,6 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { |
| OnInstallEventFinished) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
| OnFetchEventFinished) |
| - IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, |
| - OnSyncEventFinished) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
| OnNotificationClickEventFinished) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
| @@ -1191,6 +1185,16 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { |
| return handled; |
| } |
| +void ServiceWorkerVersion::OnSyncEventFinished(const StatusCallback& callback, |
| + ServiceWorkerStatusCode status) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + TRACE_EVENT0("ServiceWorker", "ServiceWorkerVersion::OnSyncEventFinished") |
| + |
| + scoped_refptr<ServiceWorkerVersion> protect(this); |
| + callback.Run(status); |
| + StopIfRedundant(); |
| +} |
| + |
| void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( |
| ServiceWorkerStatusCode status) { |
| if (status != SERVICE_WORKER_OK) { |
| @@ -1332,33 +1336,6 @@ void ServiceWorkerVersion::OnFetchEventFinished( |
| RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); |
| } |
| -void ServiceWorkerVersion::OnSyncEventFinished( |
| - int request_id, |
| - blink::WebServiceWorkerEventResult result) { |
| - TRACE_EVENT1("ServiceWorker", |
| - "ServiceWorkerVersion::OnSyncEventFinished", |
| - "Request id", request_id); |
| - StatusCallback* callback = sync_callbacks_.Lookup(request_id); |
| - if (!callback) { |
| - NOTREACHED() << "Got unexpected message: " << request_id; |
| - return; |
| - } |
| - |
| - ServiceWorkerStatusCode status = SERVICE_WORKER_OK; |
| - if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kEnableServiceWorkerSync)) { |
| - // Avoid potential race condition where flag is disabled after a sync event |
| - // was dispatched |
| - status = SERVICE_WORKER_ERROR_ABORT; |
| - } else if (result == blink::WebServiceWorkerEventResultRejected) { |
| - status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; |
| - } |
| - |
| - scoped_refptr<ServiceWorkerVersion> protect(this); |
| - callback->Run(status); |
| - RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); |
| -} |
| - |
| void ServiceWorkerVersion::OnNotificationClickEventFinished( |
| int request_id) { |
| TRACE_EVENT1("ServiceWorker", |
| @@ -1903,7 +1880,6 @@ bool ServiceWorkerVersion::HasInflightRequests() const { |
| !activate_callbacks_.IsEmpty() || |
| !install_callbacks_.IsEmpty() || |
| !fetch_callbacks_.IsEmpty() || |
| - !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.
|
| !notification_click_callbacks_.IsEmpty() || |
| !push_callbacks_.IsEmpty() || |
| !geofencing_callbacks_.IsEmpty() || |
| @@ -1949,11 +1925,8 @@ void ServiceWorkerVersion::RecordStartWorkerResult( |
| EmbeddedWorkerInstance::STARTING_PHASE_MAX_VALUE); |
| } |
| -template <typename IDMAP> |
| -void ServiceWorkerVersion::RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, |
| - int request_id) { |
| +void ServiceWorkerVersion::StopIfRedundant() { |
| RestartTick(&idle_time_); |
| - callbacks->Remove(request_id); |
| if (is_redundant()) { |
| // The stop should be already scheduled, but try to stop immediately, in |
| // order to release worker resources soon. |
| @@ -1961,6 +1934,13 @@ void ServiceWorkerVersion::RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, |
| } |
| } |
| +template <typename IDMAP> |
| +void ServiceWorkerVersion::RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, |
| + int request_id) { |
| + callbacks->Remove(request_id); |
| + StopIfRedundant(); |
| +} |
| + |
| template <typename CallbackType> |
| int ServiceWorkerVersion::AddRequest( |
| const CallbackType& callback, |
| @@ -1984,9 +1964,6 @@ bool ServiceWorkerVersion::OnRequestTimeout(const RequestInfo& info) { |
| &fetch_callbacks_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, |
| /* The other args are ignored for non-OK status. */ |
| SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); |
| - case REQUEST_SYNC: |
| - 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.
|
| - SERVICE_WORKER_ERROR_TIMEOUT); |
| case REQUEST_NOTIFICATION_CLICK: |
| return RunIDMapCallback(¬ification_click_callbacks_, info.id, |
| SERVICE_WORKER_ERROR_TIMEOUT); |