Commit e83a503d authored by shimazu's avatar shimazu Committed by Commit bot

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}
parent e5ce2745
...@@ -231,7 +231,7 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( ...@@ -231,7 +231,7 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
int provider_id, int provider_id,
const GURL& pattern) { const GURL& pattern) {
if (!GetContext()) { if (!GetContext()) {
Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
thread_id, thread_id,
request_id, request_id,
blink::WebServiceWorkerError::ErrorTypeAbort, blink::WebServiceWorkerError::ErrorTypeAbort,
...@@ -246,7 +246,7 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( ...@@ -246,7 +246,7 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
return; return;
} }
if (!provider_host->IsContextAlive()) { if (!provider_host->IsContextAlive()) {
Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
thread_id, thread_id,
request_id, request_id,
blink::WebServiceWorkerError::ErrorTypeAbort, blink::WebServiceWorkerError::ErrorTypeAbort,
...@@ -535,7 +535,7 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete( ...@@ -535,7 +535,7 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete(
int request_id, int request_id,
ServiceWorkerStatusCode status) { ServiceWorkerStatusCode status) {
if (status != SERVICE_WORKER_OK) { if (status != SERVICE_WORKER_OK) {
SendRegistrationError(thread_id, request_id, status); SendUnregistrationError(thread_id, request_id, status);
return; return;
} }
...@@ -554,6 +554,18 @@ void ServiceWorkerDispatcherHost::SendRegistrationError( ...@@ -554,6 +554,18 @@ void ServiceWorkerDispatcherHost::SendRegistrationError(
thread_id, request_id, error_type, error_message)); 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() { ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
return context_wrapper_->context(); return context_wrapper_->context();
} }
......
...@@ -122,6 +122,10 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { ...@@ -122,6 +122,10 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
int request_id, int request_id,
ServiceWorkerStatusCode status); ServiceWorkerStatusCode status);
void SendUnregistrationError(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
ServiceWorkerContextCore* GetContext(); ServiceWorkerContextCore* GetContext();
int render_process_id_; int render_process_id_;
......
...@@ -58,6 +58,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { ...@@ -58,6 +58,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) {
OnUnregistered) OnUnregistered)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
OnRegistrationError) OnRegistrationError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError,
OnUnregistrationError)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
OnServiceWorkerStateChanged) OnServiceWorkerStateChanged)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
...@@ -94,7 +96,7 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( ...@@ -94,7 +96,7 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
return; return;
} }
int request_id = pending_callbacks_.Add(callbacks); int request_id = pending_registration_callbacks_.Add(callbacks);
thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
CurrentWorkerId(), request_id, provider_id, pattern, script_url)); CurrentWorkerId(), request_id, provider_id, pattern, script_url));
} }
...@@ -102,11 +104,11 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( ...@@ -102,11 +104,11 @@ void ServiceWorkerDispatcher::RegisterServiceWorker(
void ServiceWorkerDispatcher::UnregisterServiceWorker( void ServiceWorkerDispatcher::UnregisterServiceWorker(
int provider_id, int provider_id,
const GURL& pattern, const GURL& pattern,
WebServiceWorkerRegistrationCallbacks* callbacks) { WebServiceWorkerUnregistrationCallbacks* callbacks) {
DCHECK(callbacks); DCHECK(callbacks);
if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) {
scoped_ptr<WebServiceWorkerRegistrationCallbacks> scoped_ptr<WebServiceWorkerUnregistrationCallbacks>
owned_callbacks(callbacks); owned_callbacks(callbacks);
scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError(
WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); WebServiceWorkerError::ErrorTypeSecurity, "URL too long"));
...@@ -114,7 +116,7 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker( ...@@ -114,7 +116,7 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker(
return; return;
} }
int request_id = pending_callbacks_.Add(callbacks); int request_id = pending_unregistration_callbacks_.Add(callbacks);
thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
CurrentWorkerId(), request_id, provider_id, pattern)); CurrentWorkerId(), request_id, provider_id, pattern));
} }
...@@ -243,7 +245,7 @@ void ServiceWorkerDispatcher::OnRegistered( ...@@ -243,7 +245,7 @@ void ServiceWorkerDispatcher::OnRegistered(
const ServiceWorkerRegistrationObjectInfo& info, const ServiceWorkerRegistrationObjectInfo& info,
const ServiceWorkerVersionAttributes& attrs) { const ServiceWorkerVersionAttributes& attrs) {
WebServiceWorkerRegistrationCallbacks* callbacks = WebServiceWorkerRegistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id); pending_registration_callbacks_.Lookup(request_id);
DCHECK(callbacks); DCHECK(callbacks);
if (!callbacks) if (!callbacks)
return; return;
...@@ -255,20 +257,24 @@ void ServiceWorkerDispatcher::OnRegistered( ...@@ -255,20 +257,24 @@ void ServiceWorkerDispatcher::OnRegistered(
registration->SetActive(GetServiceWorker(attrs.active, true)); registration->SetActive(GetServiceWorker(attrs.active, true));
callbacks->onSuccess(registration); callbacks->onSuccess(registration);
pending_callbacks_.Remove(request_id); pending_registration_callbacks_.Remove(request_id);
} }
void ServiceWorkerDispatcher::OnUnregistered( void ServiceWorkerDispatcher::OnUnregistered(
int thread_id, int thread_id,
int request_id) { int request_id) {
WebServiceWorkerRegistrationCallbacks* callbacks = WebServiceWorkerUnregistrationCallbacks* callbacks =
pending_callbacks_.Lookup(request_id); pending_unregistration_callbacks_.Lookup(request_id);
DCHECK(callbacks); DCHECK(callbacks);
if (!callbacks) if (!callbacks)
return; return;
#ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN
callbacks->onSuccess(NULL); 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( void ServiceWorkerDispatcher::OnRegistrationError(
...@@ -277,7 +283,24 @@ void ServiceWorkerDispatcher::OnRegistrationError( ...@@ -277,7 +283,24 @@ void ServiceWorkerDispatcher::OnRegistrationError(
WebServiceWorkerError::ErrorType error_type, WebServiceWorkerError::ErrorType error_type,
const base::string16& message) { const base::string16& message) {
WebServiceWorkerRegistrationCallbacks* callbacks = 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); DCHECK(callbacks);
if (!callbacks) if (!callbacks)
return; return;
...@@ -285,7 +308,7 @@ void ServiceWorkerDispatcher::OnRegistrationError( ...@@ -285,7 +308,7 @@ void ServiceWorkerDispatcher::OnRegistrationError(
scoped_ptr<WebServiceWorkerError> error( scoped_ptr<WebServiceWorkerError> error(
new WebServiceWorkerError(error_type, message)); new WebServiceWorkerError(error_type, message));
callbacks->onError(error.release()); callbacks->onError(error.release());
pending_callbacks_.Remove(request_id); pending_unregistration_callbacks_.Remove(request_id);
} }
void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
......
...@@ -44,6 +44,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -44,6 +44,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
public: public:
typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks
WebServiceWorkerRegistrationCallbacks; WebServiceWorkerRegistrationCallbacks;
typedef
blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks
WebServiceWorkerUnregistrationCallbacks;
explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender);
virtual ~ServiceWorkerDispatcher(); virtual ~ServiceWorkerDispatcher();
...@@ -61,7 +64,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -61,7 +64,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
void UnregisterServiceWorker( void UnregisterServiceWorker(
int provider_id, int provider_id,
const GURL& pattern, const GURL& pattern,
WebServiceWorkerRegistrationCallbacks* callbacks); WebServiceWorkerUnregistrationCallbacks* callbacks);
// Called when a new provider context for a document is created. Usually // 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 // this happens when a new document is being loaded, and is called much
...@@ -113,7 +116,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -113,7 +116,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
private: private:
typedef IDMap<WebServiceWorkerRegistrationCallbacks, typedef IDMap<WebServiceWorkerRegistrationCallbacks,
IDMapOwnPointer> CallbackMap; IDMapOwnPointer> RegistrationCallbackMap;
typedef IDMap<WebServiceWorkerUnregistrationCallbacks,
IDMapOwnPointer> UnregistrationCallbackMap;
typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap;
typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap;
typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap;
...@@ -137,6 +142,10 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -137,6 +142,10 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
int request_id, int request_id,
blink::WebServiceWorkerError::ErrorType error_type, blink::WebServiceWorkerError::ErrorType error_type,
const base::string16& message); 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, void OnServiceWorkerStateChanged(int thread_id,
int handle_id, int handle_id,
blink::WebServiceWorkerState state); blink::WebServiceWorkerState state);
...@@ -180,7 +189,8 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { ...@@ -180,7 +189,8 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
void RemoveServiceWorkerRegistration( void RemoveServiceWorkerRegistration(
int registration_handle_id); int registration_handle_id);
CallbackMap pending_callbacks_; RegistrationCallbackMap pending_registration_callbacks_;
UnregistrationCallbackMap pending_unregistration_callbacks_;
ScriptClientMap script_clients_; ScriptClientMap script_clients_;
ProviderContextMap provider_contexts_; ProviderContextMap provider_contexts_;
WorkerObjectMap service_workers_; WorkerObjectMap service_workers_;
......
...@@ -78,7 +78,7 @@ void WebServiceWorkerProviderImpl::registerServiceWorker( ...@@ -78,7 +78,7 @@ void WebServiceWorkerProviderImpl::registerServiceWorker(
void WebServiceWorkerProviderImpl::unregisterServiceWorker( void WebServiceWorkerProviderImpl::unregisterServiceWorker(
const WebURL& pattern, const WebURL& pattern,
WebServiceWorkerRegistrationCallbacks* callbacks) { WebServiceWorkerUnregistrationCallbacks* callbacks) {
GetDispatcher()->UnregisterServiceWorker( GetDispatcher()->UnregisterServiceWorker(
provider_id_, pattern, callbacks); provider_id_, pattern, callbacks);
} }
......
...@@ -36,8 +36,9 @@ class WebServiceWorkerProviderImpl ...@@ -36,8 +36,9 @@ class WebServiceWorkerProviderImpl
const blink::WebURL& script_url, const blink::WebURL& script_url,
WebServiceWorkerRegistrationCallbacks*); WebServiceWorkerRegistrationCallbacks*);
virtual void unregisterServiceWorker(const blink::WebURL& pattern, virtual void unregisterServiceWorker(
WebServiceWorkerRegistrationCallbacks*); const blink::WebURL& pattern,
WebServiceWorkerUnregistrationCallbacks*);
ServiceWorkerProviderContext* context() { return context_.get(); } ServiceWorkerProviderContext* context() { return context_.get(); }
......
...@@ -197,13 +197,21 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_ServiceWorkerUnregistered, ...@@ -197,13 +197,21 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_ServiceWorkerUnregistered,
int /* request_id */) int /* request_id */)
// Sent when any kind of registration error occurs during a // Sent when any kind of registration error occurs during a
// RegisterServiceWorker / UnregisterServiceWorker handler above. // RegisterServiceWorker handler above.
IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError, IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError,
int /* thread_id */, int /* thread_id */,
int /* request_id */, int /* request_id */,
blink::WebServiceWorkerError::ErrorType /* code */, blink::WebServiceWorkerError::ErrorType /* code */,
base::string16 /* message */) 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. // Informs the child process that the ServiceWorker's state has changed.
IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerStateChanged, IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerStateChanged,
int /* thread_id */, int /* thread_id */,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment