Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: content/child/service_worker/service_worker_provider_context.h

Issue 849163002: ServiceWorker: Expose registration within ServiceWorkerGlobalScope [2/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove dcheck Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698