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 /content/child/service_worker | |
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}
Diffstat (limited to 'content/child/service_worker')
4 files changed, 52 insertions, 18 deletions
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(); } |