diff options
author | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-20 00:10:23 +0000 |
---|---|---|
committer | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-20 00:13:43 +0000 |
commit | 6f473719564d3cd7570e8fc9ce32fd9698ccb8e0 (patch) | |
tree | d6a5b15ddf8539fbd458c0e403c35b8c02a789ac /content/child/service_worker | |
parent | 0409d5b06b693c017834f9419f52baaa706dac27 (diff) | |
download | chromium_src-6f473719564d3cd7570e8fc9ce32fd9698ccb8e0.zip chromium_src-6f473719564d3cd7570e8fc9ce32fd9698ccb8e0.tar.gz chromium_src-6f473719564d3cd7570e8fc9ce32fd9698ccb8e0.tar.bz2 |
ServiceWorker: Introduce ServiceWorkerRegistrationObjectInfo for cleanup
This change introduces ServiceWorkerRegistrationObjectInfo which carries
'handle_id' and 'scope' for ServiceWorkerRegistration object in the renderer
side over the IPC message, and removes unnecessary reference counting for
ServiceWorker object on the registration sequence.
BUG=384119, 396400
TEST=content_unittests --gtest_filter=ServiceWorker*
TEST=run_webkit_tests.py --debug http/tests/serviceworker
Review URL: https://codereview.chromium.org/486083002
Cr-Commit-Position: refs/heads/master@{#290709}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290709 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/child/service_worker')
6 files changed, 34 insertions, 53 deletions
diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc index b8c5c1e..0322bb2 100644 --- a/content/child/service_worker/service_worker_dispatcher.cc +++ b/content/child/service_worker/service_worker_dispatcher.cc @@ -205,21 +205,20 @@ WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker( WebServiceWorkerRegistrationImpl* ServiceWorkerDispatcher::GetServiceWorkerRegistration( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, bool adopt_handle) { - if (registration_handle_id == kInvalidServiceWorkerRegistrationHandleId) + if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) return NULL; RegistrationObjectMap::iterator existing_registration = - registrations_.find(registration_handle_id); + registrations_.find(info.handle_id); if (existing_registration != registrations_.end()) { if (adopt_handle) { // We are instructed to adopt a handle but we already have one, so // adopt and destroy a handle ref. ServiceWorkerRegistrationHandleReference::Adopt( - registration_handle_id, info, thread_safe_sender_); + info, thread_safe_sender_); } return existing_registration->second; } @@ -227,9 +226,9 @@ ServiceWorkerDispatcher::GetServiceWorkerRegistration( scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( - registration_handle_id, info, thread_safe_sender_) + info, thread_safe_sender_) : ServiceWorkerRegistrationHandleReference::Create( - registration_handle_id, info, thread_safe_sender_); + info, thread_safe_sender_); // WebServiceWorkerRegistrationImpl constructor calls // AddServiceWorkerRegistration. @@ -239,21 +238,14 @@ ServiceWorkerDispatcher::GetServiceWorkerRegistration( void ServiceWorkerDispatcher::OnRegistered( int thread_id, int request_id, - int registration_handle_id, - const ServiceWorkerObjectInfo& info) { + const ServiceWorkerRegistrationObjectInfo& info) { WebServiceWorkerRegistrationCallbacks* callbacks = pending_callbacks_.Lookup(request_id); DCHECK(callbacks); if (!callbacks) return; - callbacks->onSuccess(GetServiceWorkerRegistration( - registration_handle_id, info, true)); - - // The handle ref is unused, so adopt and destroy it. - // TODO(nhiroki): ServiceWorkerDispatcherHost don't have to pass a handle ref. - ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); - + callbacks->onSuccess(GetServiceWorkerRegistration(info, true)); pending_callbacks_.Remove(request_id); } diff --git a/content/child/service_worker/service_worker_dispatcher.h b/content/child/service_worker/service_worker_dispatcher.h index 877b8e1..9997afd 100644 --- a/content/child/service_worker/service_worker_dispatcher.h +++ b/content/child/service_worker/service_worker_dispatcher.h @@ -34,6 +34,7 @@ class ThreadSafeSender; class WebServiceWorkerImpl; class WebServiceWorkerRegistrationImpl; struct ServiceWorkerObjectInfo; +struct ServiceWorkerRegistrationObjectInfo; struct ServiceWorkerVersionAttributes; // This class manages communication with the browser process about @@ -98,8 +99,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { // |adopt_handle| is true, a ServiceWorkerRegistrationHandleReference will be // adopted for the specified registration. WebServiceWorkerRegistrationImpl* GetServiceWorkerRegistration( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, bool adopt_handle); // |thread_safe_sender| needs to be passed in because if the call leads to @@ -129,8 +129,7 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { void OnRegistered(int thread_id, int request_id, - int registration_handle_id, - const ServiceWorkerObjectInfo& info); + const ServiceWorkerRegistrationObjectInfo& info); void OnUnregistered(int thread_id, int request_id); void OnRegistrationError(int thread_id, diff --git a/content/child/service_worker/service_worker_message_filter.cc b/content/child/service_worker/service_worker_message_filter.cc index 0033207..34588ba 100644 --- a/content/child/service_worker/service_worker_message_filter.cc +++ b/content/child/service_worker/service_worker_message_filter.cc @@ -81,10 +81,8 @@ void ServiceWorkerMessageFilter::OnStaleMessageReceived( void ServiceWorkerMessageFilter::OnStaleRegistered( int thread_id, int request_id, - int registration_handle_id, - const ServiceWorkerObjectInfo& info) { - SendServiceWorkerObjectDestroyed(thread_safe_sender_, info.handle_id); - SendRegistrationObjectDestroyed(thread_safe_sender_, registration_handle_id); + const ServiceWorkerRegistrationObjectInfo& info) { + SendRegistrationObjectDestroyed(thread_safe_sender_, info.handle_id); } void ServiceWorkerMessageFilter::OnStaleSetVersionAttributes( diff --git a/content/child/service_worker/service_worker_message_filter.h b/content/child/service_worker/service_worker_message_filter.h index d1e59fa..40a67bc 100644 --- a/content/child/service_worker/service_worker_message_filter.h +++ b/content/child/service_worker/service_worker_message_filter.h @@ -16,6 +16,7 @@ namespace content { class ThreadSafeSender; struct ServiceWorkerObjectInfo; +struct ServiceWorkerRegistrationObjectInfo; struct ServiceWorkerVersionAttributes; class CONTENT_EXPORT ServiceWorkerMessageFilter @@ -37,8 +38,7 @@ class CONTENT_EXPORT ServiceWorkerMessageFilter void OnStaleRegistered( int thread_id, int request_id, - int registration_handle_id, - const ServiceWorkerObjectInfo& info); + const ServiceWorkerRegistrationObjectInfo& info); void OnStaleSetVersionAttributes( int thread_id, int provider_id, diff --git a/content/child/service_worker/service_worker_registration_handle_reference.cc b/content/child/service_worker/service_worker_registration_handle_reference.cc index 3b72a35..dfbbe21 100644 --- a/content/child/service_worker/service_worker_registration_handle_reference.cc +++ b/content/child/service_worker/service_worker_registration_handle_reference.cc @@ -6,49 +6,44 @@ #include "content/child/thread_safe_sender.h" #include "content/common/service_worker/service_worker_messages.h" -#include "content/common/service_worker/service_worker_types.h" namespace content { scoped_ptr<ServiceWorkerRegistrationHandleReference> ServiceWorkerRegistrationHandleReference::Create( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, ThreadSafeSender* sender) { return make_scoped_ptr(new ServiceWorkerRegistrationHandleReference( - registration_handle_id, info, sender, true)); + info, sender, true)); } scoped_ptr<ServiceWorkerRegistrationHandleReference> ServiceWorkerRegistrationHandleReference::Adopt( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, ThreadSafeSender* sender) { return make_scoped_ptr(new ServiceWorkerRegistrationHandleReference( - registration_handle_id, info, sender, false)); + info, sender, false)); } ServiceWorkerRegistrationHandleReference:: ServiceWorkerRegistrationHandleReference( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, ThreadSafeSender* sender, bool increment_ref_in_ctor) - : handle_id_(registration_handle_id), - scope_(info.scope), + : info_(info), sender_(sender) { - DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId, handle_id_); + DCHECK_NE(kInvalidServiceWorkerRegistrationHandleId, info_.handle_id); DCHECK(sender_); if (increment_ref_in_ctor) return; sender_->Send( - new ServiceWorkerHostMsg_IncrementRegistrationRefCount(handle_id_)); + new ServiceWorkerHostMsg_IncrementRegistrationRefCount(info_.handle_id)); } ServiceWorkerRegistrationHandleReference:: ~ServiceWorkerRegistrationHandleReference() { sender_->Send( - new ServiceWorkerHostMsg_DecrementRegistrationRefCount(handle_id_)); + new ServiceWorkerHostMsg_DecrementRegistrationRefCount(info_.handle_id)); } } // namespace content diff --git a/content/child/service_worker/service_worker_registration_handle_reference.h b/content/child/service_worker/service_worker_registration_handle_reference.h index fdfb109..066c89f 100644 --- a/content/child/service_worker/service_worker_registration_handle_reference.h +++ b/content/child/service_worker/service_worker_registration_handle_reference.h @@ -7,42 +7,39 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "content/common/service_worker/service_worker_types.h" #include "url/gurl.h" namespace content { class ThreadSafeSender; -struct ServiceWorkerObjectInfo; class ServiceWorkerRegistrationHandleReference { public: // Creates a new ServiceWorkerRegistrationHandleReference and increments // ref-count. static scoped_ptr<ServiceWorkerRegistrationHandleReference> Create( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, ThreadSafeSender* sender); // Creates a new ServiceWorkerRegistrationHandleReference by adopting a // ref-count. static scoped_ptr<ServiceWorkerRegistrationHandleReference> Adopt( - int registration_handle_id, - const ServiceWorkerObjectInfo& info, + const ServiceWorkerRegistrationObjectInfo& info, ThreadSafeSender* sender); ~ServiceWorkerRegistrationHandleReference(); - int handle_id() const { return handle_id_; } - GURL scope() const { return scope_; } + int handle_id() const { return info_.handle_id; } + GURL scope() const { return info_.scope; } private: - ServiceWorkerRegistrationHandleReference(int registration_handle_id, - const ServiceWorkerObjectInfo& info, - ThreadSafeSender* sender, - bool increment_ref_in_ctor); + ServiceWorkerRegistrationHandleReference( + const ServiceWorkerRegistrationObjectInfo& info, + ThreadSafeSender* sender, + bool increment_ref_in_ctor); - const int handle_id_; - const GURL scope_; + ServiceWorkerRegistrationObjectInfo info_; scoped_refptr<ThreadSafeSender> sender_; DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistrationHandleReference); |