diff options
author | shimazu <shimazu@chromium.org> | 2014-09-02 23:19:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-03 06:21:32 +0000 |
commit | e83a503dbe85d24dae8879fa1f36781bccfb862a (patch) | |
tree | 66979798e4475a5b552c5728fc7960ff496d551f | |
parent | e5ce274558eaf7231b9294318cc1db2bd9c553ba (diff) | |
download | chromium_src-e83a503dbe85d24dae8879fa1f36781bccfb862a.zip chromium_src-e83a503dbe85d24dae8879fa1f36781bccfb862a.tar.gz chromium_src-e83a503dbe85d24dae8879fa1f36781bccfb862a.tar.bz2 |
ServiceWorker: Change the return value of ServiceWorkerRegistration::unregister to boolean
1. [Blink] https://codereview.chromium.org/515083002/
2. [Chromium] This patch
3. [Blink] https://codereview.chromium.org/512163002/
4. [Chromium] https://codereview.chromium.org/509283003/
BUG=390894
TEST=N/A
Review URL: https://codereview.chromium.org/516823003
Cr-Commit-Position: refs/heads/master@{#293083}
7 files changed, 80 insertions, 22 deletions
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc index 44d5b79..b770556 100644 --- a/content/browser/service_worker/service_worker_dispatcher_host.cc +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc @@ -231,7 +231,7 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( int provider_id, const GURL& pattern) { if (!GetContext()) { - Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( + Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, @@ -246,7 +246,7 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( return; } if (!provider_host->IsContextAlive()) { - Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( + Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, @@ -535,7 +535,7 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete( int request_id, ServiceWorkerStatusCode status) { if (status != SERVICE_WORKER_OK) { - SendRegistrationError(thread_id, request_id, status); + SendUnregistrationError(thread_id, request_id, status); return; } @@ -554,6 +554,18 @@ void ServiceWorkerDispatcherHost::SendRegistrationError( thread_id, request_id, error_type, error_message)); } +void ServiceWorkerDispatcherHost::SendUnregistrationError( + int thread_id, + int request_id, + ServiceWorkerStatusCode status) { + base::string16 error_message; + blink::WebServiceWorkerError::ErrorType error_type; + GetServiceWorkerRegistrationStatusResponse( + status, &error_type, &error_message); + Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( + thread_id, request_id, error_type, error_message)); +} + ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { return context_wrapper_->context(); } diff --git a/content/browser/service_worker/service_worker_dispatcher_host.h b/content/browser/service_worker/service_worker_dispatcher_host.h index 9ea4296..0daa788 100644 --- a/content/browser/service_worker/service_worker_dispatcher_host.h +++ b/content/browser/service_worker/service_worker_dispatcher_host.h @@ -122,6 +122,10 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { int request_id, ServiceWorkerStatusCode status); + void SendUnregistrationError(int thread_id, + int request_id, + ServiceWorkerStatusCode status); + ServiceWorkerContextCore* GetContext(); int render_process_id_; diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc index 032dfa2..9bc8c7e 100644 --- a/content/child/service_worker/service_worker_dispatcher.cc +++ b/content/child/service_worker/service_worker_dispatcher.cc @@ -58,6 +58,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { OnUnregistered) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, OnRegistrationError) + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, + OnUnregistrationError) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, OnServiceWorkerStateChanged) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, @@ -94,7 +96,7 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( return; } - int request_id = pending_callbacks_.Add(callbacks); + int request_id = pending_registration_callbacks_.Add(callbacks); thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( CurrentWorkerId(), request_id, provider_id, pattern, script_url)); } @@ -102,11 +104,11 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( void ServiceWorkerDispatcher::UnregisterServiceWorker( int provider_id, const GURL& pattern, - WebServiceWorkerRegistrationCallbacks* callbacks) { + WebServiceWorkerUnregistrationCallbacks* callbacks) { DCHECK(callbacks); if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { - scoped_ptr<WebServiceWorkerRegistrationCallbacks> + scoped_ptr<WebServiceWorkerUnregistrationCallbacks> owned_callbacks(callbacks); scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); @@ -114,7 +116,7 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker( return; } - int request_id = pending_callbacks_.Add(callbacks); + int request_id = pending_unregistration_callbacks_.Add(callbacks); thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( CurrentWorkerId(), request_id, provider_id, pattern)); } @@ -243,7 +245,7 @@ void ServiceWorkerDispatcher::OnRegistered( const ServiceWorkerRegistrationObjectInfo& info, const ServiceWorkerVersionAttributes& attrs) { WebServiceWorkerRegistrationCallbacks* callbacks = - pending_callbacks_.Lookup(request_id); + pending_registration_callbacks_.Lookup(request_id); DCHECK(callbacks); if (!callbacks) return; @@ -255,20 +257,24 @@ void ServiceWorkerDispatcher::OnRegistered( registration->SetActive(GetServiceWorker(attrs.active, true)); callbacks->onSuccess(registration); - pending_callbacks_.Remove(request_id); + pending_registration_callbacks_.Remove(request_id); } void ServiceWorkerDispatcher::OnUnregistered( int thread_id, int request_id) { - WebServiceWorkerRegistrationCallbacks* callbacks = - pending_callbacks_.Lookup(request_id); + WebServiceWorkerUnregistrationCallbacks* callbacks = + pending_unregistration_callbacks_.Lookup(request_id); DCHECK(callbacks); if (!callbacks) return; - +#ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN callbacks->onSuccess(NULL); - pending_callbacks_.Remove(request_id); +#else + bool is_success = true; + callbacks->onSuccess(&is_success); +#endif + pending_unregistration_callbacks_.Remove(request_id); } void ServiceWorkerDispatcher::OnRegistrationError( @@ -277,7 +283,24 @@ void ServiceWorkerDispatcher::OnRegistrationError( WebServiceWorkerError::ErrorType error_type, const base::string16& message) { WebServiceWorkerRegistrationCallbacks* callbacks = - pending_callbacks_.Lookup(request_id); + pending_registration_callbacks_.Lookup(request_id); + DCHECK(callbacks); + if (!callbacks) + return; + + scoped_ptr<WebServiceWorkerError> error( + new WebServiceWorkerError(error_type, message)); + callbacks->onError(error.release()); + pending_registration_callbacks_.Remove(request_id); +} + +void ServiceWorkerDispatcher::OnUnregistrationError( + int thread_id, + int request_id, + WebServiceWorkerError::ErrorType error_type, + const base::string16& message) { + WebServiceWorkerUnregistrationCallbacks* callbacks = + pending_unregistration_callbacks_.Lookup(request_id); DCHECK(callbacks); if (!callbacks) return; @@ -285,7 +308,7 @@ void ServiceWorkerDispatcher::OnRegistrationError( scoped_ptr<WebServiceWorkerError> error( new WebServiceWorkerError(error_type, message)); callbacks->onError(error.release()); - pending_callbacks_.Remove(request_id); + pending_unregistration_callbacks_.Remove(request_id); } void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( diff --git a/content/child/service_worker/service_worker_dispatcher.h b/content/child/service_worker/service_worker_dispatcher.h index 3f136c28..6ff4fa5 100644 --- a/content/child/service_worker/service_worker_dispatcher.h +++ b/content/child/service_worker/service_worker_dispatcher.h @@ -44,6 +44,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { public: typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks WebServiceWorkerRegistrationCallbacks; + typedef + blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks + WebServiceWorkerUnregistrationCallbacks; explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); virtual ~ServiceWorkerDispatcher(); @@ -61,7 +64,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { void UnregisterServiceWorker( int provider_id, const GURL& pattern, - WebServiceWorkerRegistrationCallbacks* callbacks); + WebServiceWorkerUnregistrationCallbacks* callbacks); // Called when a new provider context for a document is created. Usually // this happens when a new document is being loaded, and is called much @@ -113,7 +116,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { private: typedef IDMap<WebServiceWorkerRegistrationCallbacks, - IDMapOwnPointer> CallbackMap; + IDMapOwnPointer> RegistrationCallbackMap; + typedef IDMap<WebServiceWorkerUnregistrationCallbacks, + IDMapOwnPointer> UnregistrationCallbackMap; typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; @@ -137,6 +142,10 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { int request_id, blink::WebServiceWorkerError::ErrorType error_type, const base::string16& message); + void OnUnregistrationError(int thread_id, + int request_id, + blink::WebServiceWorkerError::ErrorType error_type, + const base::string16& message); void OnServiceWorkerStateChanged(int thread_id, int handle_id, blink::WebServiceWorkerState state); @@ -180,7 +189,8 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { void RemoveServiceWorkerRegistration( int registration_handle_id); - CallbackMap pending_callbacks_; + RegistrationCallbackMap pending_registration_callbacks_; + UnregistrationCallbackMap pending_unregistration_callbacks_; ScriptClientMap script_clients_; ProviderContextMap provider_contexts_; WorkerObjectMap service_workers_; diff --git a/content/child/service_worker/web_service_worker_provider_impl.cc b/content/child/service_worker/web_service_worker_provider_impl.cc index ca4cfc7..7115561 100644 --- a/content/child/service_worker/web_service_worker_provider_impl.cc +++ b/content/child/service_worker/web_service_worker_provider_impl.cc @@ -78,7 +78,7 @@ void WebServiceWorkerProviderImpl::registerServiceWorker( void WebServiceWorkerProviderImpl::unregisterServiceWorker( const WebURL& pattern, - WebServiceWorkerRegistrationCallbacks* callbacks) { + WebServiceWorkerUnregistrationCallbacks* callbacks) { GetDispatcher()->UnregisterServiceWorker( provider_id_, pattern, callbacks); } diff --git a/content/child/service_worker/web_service_worker_provider_impl.h b/content/child/service_worker/web_service_worker_provider_impl.h index b78f4d0..e7a4a7d 100644 --- a/content/child/service_worker/web_service_worker_provider_impl.h +++ b/content/child/service_worker/web_service_worker_provider_impl.h @@ -36,8 +36,9 @@ class WebServiceWorkerProviderImpl const blink::WebURL& script_url, WebServiceWorkerRegistrationCallbacks*); - virtual void unregisterServiceWorker(const blink::WebURL& pattern, - WebServiceWorkerRegistrationCallbacks*); + virtual void unregisterServiceWorker( + const blink::WebURL& pattern, + WebServiceWorkerUnregistrationCallbacks*); ServiceWorkerProviderContext* context() { return context_.get(); } diff --git a/content/common/service_worker/service_worker_messages.h b/content/common/service_worker/service_worker_messages.h index 42943e5..f940d06 100644 --- a/content/common/service_worker/service_worker_messages.h +++ b/content/common/service_worker/service_worker_messages.h @@ -197,13 +197,21 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_ServiceWorkerUnregistered, int /* request_id */) // Sent when any kind of registration error occurs during a -// RegisterServiceWorker / UnregisterServiceWorker handler above. +// RegisterServiceWorker handler above. IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError, int /* thread_id */, int /* request_id */, blink::WebServiceWorkerError::ErrorType /* code */, base::string16 /* message */) +// Sent when any kind of registration error occurs during a +// UnregisterServiceWorker handler above. +IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerUnregistrationError, + int /* thread_id */, + int /* request_id */, + blink::WebServiceWorkerError::ErrorType /* code */, + base::string16 /* message */) + // Informs the child process that the ServiceWorker's state has changed. IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerStateChanged, int /* thread_id */, |