Chromium Code Reviews| Index: content/child/service_worker/service_worker_provider_context.h |
| diff --git a/content/child/service_worker/service_worker_provider_context.h b/content/child/service_worker/service_worker_provider_context.h |
| index 03a1d289c42eb2992cbaacbffa77a7b7faf58df2..e858ea9e743e843e544d1913fa2b11e0312fcb9c 100644 |
| --- a/content/child/service_worker/service_worker_provider_context.h |
| +++ b/content/child/service_worker/service_worker_provider_context.h |
| @@ -28,13 +28,12 @@ class ServiceWorkerRegistrationHandleReference; |
| struct ServiceWorkerProviderContextDeleter; |
| class ThreadSafeSender; |
| -// An instance of this class holds document-related information (e.g. |
| -// .controller). Created and destructed on the main thread. |
| -// TODO(kinuko): To support navigator.serviceWorker in dedicated workers |
| -// this needs to be RefCountedThreadSafe and .controller info needs to be |
| -// handled in a thread-safe manner (e.g. by a lock etc). |
| +// An instance of this class holds information related to Document/Worker. |
| +// Created and destructed on the main thread. Some functions can be called |
| +// on the worker thread (eg. GetVersionAttributes). |
| class ServiceWorkerProviderContext |
| - : public base::RefCounted<ServiceWorkerProviderContext> { |
| + : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
| + ServiceWorkerProviderContextDeleter> { |
| public: |
| explicit ServiceWorkerProviderContext(int provider_id); |
| @@ -81,21 +80,39 @@ class ServiceWorkerProviderContext |
| int registration_handle_id() const; |
| private: |
| - friend class base::RefCounted<ServiceWorkerProviderContext>; |
| + friend class base::DeleteHelper<ServiceWorkerProviderContext>; |
| + friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
| + ServiceWorkerProviderContextDeleter>; |
| + friend struct ServiceWorkerProviderContextDeleter; |
| + |
| ~ServiceWorkerProviderContext(); |
| + void DestructOnMainThread() const; |
| const int provider_id_; |
| scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
| scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| + |
| + // Protects (installing, waiting, active) worker and registration references. |
| + base::Lock lock_; |
|
kinuko
2015/01/22 08:05:44
It's unfortunate that we still need a lock while t
nhiroki
2015/01/22 09:09:16
Piggyback on StartWorker message could be a soluti
|
| + |
| + // Used on both the main thread and the worker thread. |
| scoped_ptr<ServiceWorkerHandleReference> installing_; |
| scoped_ptr<ServiceWorkerHandleReference> waiting_; |
| scoped_ptr<ServiceWorkerHandleReference> active_; |
| - scoped_ptr<ServiceWorkerHandleReference> controller_; |
| scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; |
| + // Used only on the main thread. |
| + scoped_ptr<ServiceWorkerHandleReference> controller_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
| }; |
| +struct ServiceWorkerProviderContextDeleter { |
| + static void Destruct(const ServiceWorkerProviderContext* context) { |
| + context->DestructOnMainThread(); |
| + } |
| +}; |
| + |
| } // namespace content |
| #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |