OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ | 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ | 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 class Message; | 21 class Message; |
22 } | 22 } |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 class ServiceWorkerHandleReference; | 26 class ServiceWorkerHandleReference; |
27 class ServiceWorkerRegistrationHandleReference; | 27 class ServiceWorkerRegistrationHandleReference; |
28 struct ServiceWorkerProviderContextDeleter; | 28 struct ServiceWorkerProviderContextDeleter; |
29 class ThreadSafeSender; | 29 class ThreadSafeSender; |
30 | 30 |
31 // An instance of this class holds document-related information (e.g. | 31 // An instance of this class holds information related to Document/Worker. |
32 // .controller). Created and destructed on the main thread. | 32 // Created and destructed on the main thread. Some functions can be called |
33 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers | 33 // on the worker thread (eg. GetVersionAttributes). |
34 // this needs to be RefCountedThreadSafe and .controller info needs to be | |
35 // handled in a thread-safe manner (e.g. by a lock etc). | |
36 class ServiceWorkerProviderContext | 34 class ServiceWorkerProviderContext |
37 : public base::RefCounted<ServiceWorkerProviderContext> { | 35 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
36 ServiceWorkerProviderContextDeleter> { | |
38 public: | 37 public: |
39 explicit ServiceWorkerProviderContext(int provider_id); | 38 explicit ServiceWorkerProviderContext(int provider_id); |
40 | 39 |
41 // Called from ServiceWorkerDispatcher. | 40 // Called from ServiceWorkerDispatcher. |
42 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info, | 41 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info, |
43 const ServiceWorkerVersionAttributes& attrs); | 42 const ServiceWorkerVersionAttributes& attrs); |
44 void OnDisassociateRegistration(); | 43 void OnDisassociateRegistration(); |
45 void OnServiceWorkerStateChanged(int handle_id, | 44 void OnServiceWorkerStateChanged(int handle_id, |
46 blink::WebServiceWorkerState state); | 45 blink::WebServiceWorkerState state); |
47 void OnSetControllerServiceWorker(const ServiceWorkerObjectInfo& info); | 46 void OnSetControllerServiceWorker(const ServiceWorkerObjectInfo& info); |
(...skipping 26 matching lines...) Expand all Loading... | |
74 // kInvalidServiceWorkerHandleId if the provider is not controlled | 73 // kInvalidServiceWorkerHandleId if the provider is not controlled |
75 // by a Service Worker. | 74 // by a Service Worker. |
76 int controller_handle_id() const; | 75 int controller_handle_id() const; |
77 | 76 |
78 // Gets the handle ID of the associated registration, or | 77 // Gets the handle ID of the associated registration, or |
79 // kInvalidRegistrationHandleId if the provider is not associated with any | 78 // kInvalidRegistrationHandleId if the provider is not associated with any |
80 // registration. | 79 // registration. |
81 int registration_handle_id() const; | 80 int registration_handle_id() const; |
82 | 81 |
83 private: | 82 private: |
84 friend class base::RefCounted<ServiceWorkerProviderContext>; | 83 friend class base::DeleteHelper<ServiceWorkerProviderContext>; |
84 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, | |
85 ServiceWorkerProviderContextDeleter>; | |
86 friend struct ServiceWorkerProviderContextDeleter; | |
87 | |
85 ~ServiceWorkerProviderContext(); | 88 ~ServiceWorkerProviderContext(); |
89 void DestructOnMainThread() const; | |
86 | 90 |
87 const int provider_id_; | 91 const int provider_id_; |
88 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; | 92 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
89 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 93 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
94 | |
95 // Protects (installing, waiting, active) worker and registration references. | |
96 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
| |
97 | |
98 // Used on both the main thread and the worker thread. | |
90 scoped_ptr<ServiceWorkerHandleReference> installing_; | 99 scoped_ptr<ServiceWorkerHandleReference> installing_; |
91 scoped_ptr<ServiceWorkerHandleReference> waiting_; | 100 scoped_ptr<ServiceWorkerHandleReference> waiting_; |
92 scoped_ptr<ServiceWorkerHandleReference> active_; | 101 scoped_ptr<ServiceWorkerHandleReference> active_; |
93 scoped_ptr<ServiceWorkerHandleReference> controller_; | |
94 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; | 102 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; |
95 | 103 |
104 // Used only on the main thread. | |
105 scoped_ptr<ServiceWorkerHandleReference> controller_; | |
106 | |
96 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); | 107 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
97 }; | 108 }; |
98 | 109 |
110 struct ServiceWorkerProviderContextDeleter { | |
111 static void Destruct(const ServiceWorkerProviderContext* context) { | |
112 context->DestructOnMainThread(); | |
113 } | |
114 }; | |
115 | |
99 } // namespace content | 116 } // namespace content |
100 | 117 |
101 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ | 118 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
OLD | NEW |