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 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/sequenced_task_runner_helpers.h" | 12 #include "base/sequenced_task_runner_helpers.h" |
13 #include "base/synchronization/lock.h" | |
14 #include "content/common/service_worker/service_worker_types.h" | 13 #include "content/common/service_worker/service_worker_types.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
18 } | 17 } |
19 | 18 |
20 namespace content { | 19 namespace content { |
21 | 20 |
22 class ServiceWorkerHandleReference; | 21 class ServiceWorkerHandleReference; |
23 class ServiceWorkerRegistrationHandleReference; | 22 class ServiceWorkerRegistrationHandleReference; |
24 struct ServiceWorkerProviderContextDeleter; | 23 struct ServiceWorkerProviderContextDeleter; |
25 class ThreadSafeSender; | 24 class ThreadSafeSender; |
26 | 25 |
27 // An instance of this class holds information related to Document/Worker. | 26 // An instance of this class holds information related to Document/Worker. |
28 // Created and destructed on the main thread. Unless otherwise noted, all | 27 // Created and destructed on the main thread. Unless otherwise noted, all |
29 // methods are called on the main thread. | 28 // methods are called on the main thread. |
29 // | |
30 // The role of this class varies for controllees and controllers: | |
31 // - For controllees, this is used for keeping the controller service worker | |
falken
2015/10/07 06:39:13
nit: keeping the <noun> alive
nhiroki
2015/10/07 07:50:38
Done.
| |
32 // until controllee's ServiceWorkerContainer is created. | |
33 // - For controllers, this is used for keeping the associated registration and | |
falken
2015/10/07 06:39:13
nit: ditto
nhiroki
2015/10/07 07:50:38
Done.
| |
34 // its versions until controller's ServiceWorkerGlobalScope is created. | |
falken
2015/10/07 06:39:13
Thanks for the comments. Can you also add comments
nhiroki
2015/10/07 07:50:38
Done.
| |
35 // | |
36 // These operations are actually done in delegate classes owned by this class: | |
37 // ControlleeDelegate and ControllerDelegate. | |
30 class ServiceWorkerProviderContext | 38 class ServiceWorkerProviderContext |
31 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, | 39 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
32 ServiceWorkerProviderContextDeleter> { | 40 ServiceWorkerProviderContextDeleter> { |
33 public: | 41 public: |
34 explicit ServiceWorkerProviderContext(int provider_id); | 42 ServiceWorkerProviderContext(int provider_id, |
43 ServiceWorkerProviderType provider_type); | |
35 | 44 |
36 // Called from ServiceWorkerDispatcher. | 45 // Called from ServiceWorkerDispatcher on the main thread. |
falken
2015/10/07 06:39:13
nit: We should either annotate each function with
nhiroki
2015/10/07 07:50:38
Point taken. Removed.
| |
37 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info, | 46 void OnAssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info, |
38 const ServiceWorkerVersionAttributes& attrs); | 47 const ServiceWorkerVersionAttributes& attrs); |
39 void OnDisassociateRegistration(); | 48 void OnDisassociateRegistration(); |
40 void OnSetControllerServiceWorker(const ServiceWorkerObjectInfo& info); | 49 void OnSetControllerServiceWorker(const ServiceWorkerObjectInfo& info); |
41 | 50 |
51 // Called on the worker thread. Used for initializing | |
52 // ServiceWorkerGlobalScope. | |
53 void GetAssociatedRegistration(ServiceWorkerRegistrationObjectInfo* info, | |
54 ServiceWorkerVersionAttributes* attrs); | |
55 | |
42 int provider_id() const { return provider_id_; } | 56 int provider_id() const { return provider_id_; } |
43 | 57 |
44 ServiceWorkerHandleReference* controller(); | 58 ServiceWorkerHandleReference* controller(); |
45 | 59 |
46 // Called on the worker thread. | |
47 bool GetRegistrationInfoAndVersionAttributes( | |
48 ServiceWorkerRegistrationObjectInfo* info, | |
49 ServiceWorkerVersionAttributes* attrs); | |
50 | |
51 private: | 60 private: |
52 friend class base::DeleteHelper<ServiceWorkerProviderContext>; | 61 friend class base::DeleteHelper<ServiceWorkerProviderContext>; |
53 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, | 62 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
54 ServiceWorkerProviderContextDeleter>; | 63 ServiceWorkerProviderContextDeleter>; |
55 friend struct ServiceWorkerProviderContextDeleter; | 64 friend struct ServiceWorkerProviderContextDeleter; |
56 | 65 |
66 class Delegate; | |
67 class ControlleeDelegate; | |
68 class ControllerDelegate; | |
69 | |
57 ~ServiceWorkerProviderContext(); | 70 ~ServiceWorkerProviderContext(); |
58 void DestructOnMainThread() const; | 71 void DestructOnMainThread() const; |
59 | 72 |
60 const int provider_id_; | 73 const int provider_id_; |
61 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 74 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
62 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 75 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
63 | 76 |
64 // Protects (installing, waiting, active) worker and registration references. | 77 scoped_ptr<Delegate> delegate_; |
65 base::Lock lock_; | |
66 | |
67 // Used on both the main thread and the worker thread. | |
68 scoped_ptr<ServiceWorkerHandleReference> installing_; | |
69 scoped_ptr<ServiceWorkerHandleReference> waiting_; | |
70 scoped_ptr<ServiceWorkerHandleReference> active_; | |
71 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; | |
72 | |
73 // Used only on the main thread. | |
74 scoped_ptr<ServiceWorkerHandleReference> controller_; | |
75 | 78 |
76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); | 79 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
77 }; | 80 }; |
78 | 81 |
79 struct ServiceWorkerProviderContextDeleter { | 82 struct ServiceWorkerProviderContextDeleter { |
80 static void Destruct(const ServiceWorkerProviderContext* context) { | 83 static void Destruct(const ServiceWorkerProviderContext* context) { |
81 context->DestructOnMainThread(); | 84 context->DestructOnMainThread(); |
82 } | 85 } |
83 }; | 86 }; |
84 | 87 |
85 } // namespace content | 88 } // namespace content |
86 | 89 |
87 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ | 90 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
OLD | NEW |