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 <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/sequenced_task_runner_helpers.h" | 14 #include "base/sequenced_task_runner_helpers.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/common/service_worker/service_worker_provider_interfaces.mojom
.h" |
16 #include "content/common/service_worker/service_worker_types.h" | 17 #include "content/common/service_worker/service_worker_types.h" |
| 18 #include "mojo/public/cpp/bindings/associated_binding.h" |
17 | 19 |
18 namespace base { | 20 namespace base { |
19 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
20 } | 22 } |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 class ServiceWorkerHandleReference; | 26 class ServiceWorkerHandleReference; |
25 class ServiceWorkerRegistrationHandleReference; | 27 class ServiceWorkerRegistrationHandleReference; |
26 struct ServiceWorkerProviderContextDeleter; | 28 struct ServiceWorkerProviderContextDeleter; |
(...skipping 10 matching lines...) Expand all Loading... |
37 // references to them are kept until OnDisassociateRegistration() is called | 39 // references to them are kept until OnDisassociateRegistration() is called |
38 // or OnSetControllerServiceWorker() is called with an invalid worker info. | 40 // or OnSetControllerServiceWorker() is called with an invalid worker info. |
39 // - For controllers, this is used for keeping the associated registration and | 41 // - For controllers, this is used for keeping the associated registration and |
40 // its versions alive to create controller's ServiceWorkerGlobalScope. The | 42 // its versions alive to create controller's ServiceWorkerGlobalScope. The |
41 // references to them are kept until OnDisassociateRegistration() is called. | 43 // references to them are kept until OnDisassociateRegistration() is called. |
42 // | 44 // |
43 // These operations are actually done in delegate classes owned by this class: | 45 // These operations are actually done in delegate classes owned by this class: |
44 // ControlleeDelegate and ControllerDelegate. | 46 // ControlleeDelegate and ControllerDelegate. |
45 class CONTENT_EXPORT ServiceWorkerProviderContext | 47 class CONTENT_EXPORT ServiceWorkerProviderContext |
46 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, | 48 : public base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
47 ServiceWorkerProviderContextDeleter> { | 49 ServiceWorkerProviderContextDeleter>, |
| 50 NON_EXPORTED_BASE(public mojom::ServiceWorkerProvider) { |
48 public: | 51 public: |
49 ServiceWorkerProviderContext(int provider_id, | 52 // |provider_id| specifies which host will receive the message from this |
50 ServiceWorkerProviderType provider_type, | 53 // provider. |provider_type| changes the behavior of this provider |
51 ThreadSafeSender* thread_safe_sender); | 54 // context. |request| is an endpoint which is connected to |
| 55 // content::ServiceWorkerProviderHost which notifies changes of the |
| 56 // registration's and workers' status. |request| is bound with |binding_|. |
| 57 ServiceWorkerProviderContext( |
| 58 int provider_id, |
| 59 ServiceWorkerProviderType provider_type, |
| 60 mojom::ServiceWorkerProviderAssociatedRequest request, |
| 61 ThreadSafeSender* thread_safe_sender); |
52 | 62 |
53 // Called from ServiceWorkerDispatcher. | 63 // Called from ServiceWorkerDispatcher. |
54 void OnAssociateRegistration( | 64 void OnAssociateRegistration( |
55 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, | 65 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration, |
56 std::unique_ptr<ServiceWorkerHandleReference> installing, | 66 std::unique_ptr<ServiceWorkerHandleReference> installing, |
57 std::unique_ptr<ServiceWorkerHandleReference> waiting, | 67 std::unique_ptr<ServiceWorkerHandleReference> waiting, |
58 std::unique_ptr<ServiceWorkerHandleReference> active); | 68 std::unique_ptr<ServiceWorkerHandleReference> active); |
59 void OnDisassociateRegistration(); | 69 void OnDisassociateRegistration(); |
60 void OnSetControllerServiceWorker( | 70 void OnSetControllerServiceWorker( |
61 std::unique_ptr<ServiceWorkerHandleReference> controller, | 71 std::unique_ptr<ServiceWorkerHandleReference> controller, |
(...skipping 15 matching lines...) Expand all Loading... |
77 private: | 87 private: |
78 friend class base::DeleteHelper<ServiceWorkerProviderContext>; | 88 friend class base::DeleteHelper<ServiceWorkerProviderContext>; |
79 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, | 89 friend class base::RefCountedThreadSafe<ServiceWorkerProviderContext, |
80 ServiceWorkerProviderContextDeleter>; | 90 ServiceWorkerProviderContextDeleter>; |
81 friend struct ServiceWorkerProviderContextDeleter; | 91 friend struct ServiceWorkerProviderContextDeleter; |
82 | 92 |
83 class Delegate; | 93 class Delegate; |
84 class ControlleeDelegate; | 94 class ControlleeDelegate; |
85 class ControllerDelegate; | 95 class ControllerDelegate; |
86 | 96 |
87 ~ServiceWorkerProviderContext(); | 97 ~ServiceWorkerProviderContext() override; |
88 void DestructOnMainThread() const; | 98 void DestructOnMainThread() const; |
89 | 99 |
90 const int provider_id_; | 100 const int provider_id_; |
91 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 101 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
92 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 102 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 103 // Mojo binding for the |request| passed to the constructor. This keeps the |
| 104 // connection to the content::ServiceWorkerProviderHost in the browser process |
| 105 // alive. |
| 106 mojo::AssociatedBinding<mojom::ServiceWorkerProvider> binding_; |
93 | 107 |
94 std::unique_ptr<Delegate> delegate_; | 108 std::unique_ptr<Delegate> delegate_; |
95 | 109 |
96 std::set<uint32_t> used_features_; | 110 std::set<uint32_t> used_features_; |
97 | 111 |
98 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); | 112 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
99 }; | 113 }; |
100 | 114 |
101 struct ServiceWorkerProviderContextDeleter { | 115 struct ServiceWorkerProviderContextDeleter { |
102 static void Destruct(const ServiceWorkerProviderContext* context) { | 116 static void Destruct(const ServiceWorkerProviderContext* context) { |
103 context->DestructOnMainThread(); | 117 context->DestructOnMainThread(); |
104 } | 118 } |
105 }; | 119 }; |
106 | 120 |
107 } // namespace content | 121 } // namespace content |
108 | 122 |
109 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ | 123 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
OLD | NEW |