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" | 13 #include "base/synchronization/lock.h" |
14 #include "content/common/service_worker/service_worker_types.h" | 14 #include "content/common/service_worker/service_worker_types.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class MessageLoopProxy; | 17 class MessageLoopProxy; |
18 } | 18 } |
19 | 19 |
20 namespace IPC { | 20 namespace IPC { |
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 struct ServiceWorkerProviderContextDeleter; | 28 struct ServiceWorkerProviderContextDeleter; |
28 class ThreadSafeSender; | 29 class ThreadSafeSender; |
29 | 30 |
30 // An instance of this class holds document-related information (e.g. | 31 // An instance of this class holds document-related information (e.g. |
31 // .controller). Created and destructed on the main thread. | 32 // .controller). Created and destructed on the main thread. |
32 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers | 33 // TODO(kinuko): To support navigator.serviceWorker in dedicated workers |
33 // this needs to be RefCountedThreadSafe and .controller info needs to be | 34 // this needs to be RefCountedThreadSafe and .controller info needs to be |
34 // handled in a thread-safe manner (e.g. by a lock etc). | 35 // handled in a thread-safe manner (e.g. by a lock etc). |
35 class ServiceWorkerProviderContext | 36 class ServiceWorkerProviderContext |
36 : public base::RefCounted<ServiceWorkerProviderContext> { | 37 : public base::RefCounted<ServiceWorkerProviderContext> { |
37 public: | 38 public: |
38 explicit ServiceWorkerProviderContext(int provider_id); | 39 explicit ServiceWorkerProviderContext(int provider_id); |
39 | 40 |
40 // Called from ServiceWorkerDispatcher. | 41 // Called from ServiceWorkerDispatcher. |
41 void OnServiceWorkerStateChanged(int handle_id, | 42 void OnServiceWorkerStateChanged(int handle_id, |
42 blink::WebServiceWorkerState state); | 43 blink::WebServiceWorkerState state); |
43 void OnSetInstallingServiceWorker(int provider_id, | 44 void OnSetInstallingServiceWorker(int provider_id, |
44 const ServiceWorkerObjectInfo& info); | 45 const ServiceWorkerObjectInfo& info); |
45 void OnSetWaitingServiceWorker(int provider_id, | 46 void OnSetWaitingServiceWorker(int provider_id, |
46 const ServiceWorkerObjectInfo& info); | 47 const ServiceWorkerObjectInfo& info); |
47 void OnSetActiveServiceWorker(int provider_id, | 48 void OnSetActiveServiceWorker(int provider_id, |
48 const ServiceWorkerObjectInfo& info); | 49 const ServiceWorkerObjectInfo& info); |
49 void OnSetControllerServiceWorker(int provider_id, | 50 void OnSetControllerServiceWorker(int provider_id, |
50 const ServiceWorkerObjectInfo& info); | 51 const ServiceWorkerObjectInfo& info); |
51 | 52 |
| 53 void AssociateRegistration(const ServiceWorkerRegistrationObjectInfo& info); |
| 54 void UnassociateRegistration(); |
| 55 |
52 int provider_id() const { return provider_id_; } | 56 int provider_id() const { return provider_id_; } |
53 | 57 |
54 ServiceWorkerHandleReference* installing(); | 58 ServiceWorkerHandleReference* installing(); |
55 ServiceWorkerHandleReference* waiting(); | 59 ServiceWorkerHandleReference* waiting(); |
56 ServiceWorkerHandleReference* active(); | 60 ServiceWorkerHandleReference* active(); |
57 ServiceWorkerHandleReference* controller(); | 61 ServiceWorkerHandleReference* controller(); |
58 | 62 |
| 63 ServiceWorkerRegistrationHandleReference* registration(); |
| 64 |
59 // Gets the handle ID of the installing Service Worker, or | 65 // Gets the handle ID of the installing Service Worker, or |
60 // kInvalidServiceWorkerHandleId if the provider does not have a | 66 // kInvalidServiceWorkerHandleId if the provider does not have a |
61 // installing Service Worker. | 67 // installing Service Worker. |
62 int installing_handle_id() const; | 68 int installing_handle_id() const; |
63 | 69 |
64 // Gets the handle ID of the waiting Service Worker, or | 70 // Gets the handle ID of the waiting Service Worker, or |
65 // kInvalidServiceWorkerHandleId if the provider does not have a | 71 // kInvalidServiceWorkerHandleId if the provider does not have a |
66 // waiting Service Worker. | 72 // waiting Service Worker. |
67 int waiting_handle_id() const; | 73 int waiting_handle_id() const; |
68 | 74 |
69 // Gets the handle ID of the active Service Worker, or | 75 // Gets the handle ID of the active Service Worker, or |
70 // kInvalidServiceWorkerHandleId if the provider does not have an active | 76 // kInvalidServiceWorkerHandleId if the provider does not have an active |
71 // Service Worker. | 77 // Service Worker. |
72 int active_handle_id() const; | 78 int active_handle_id() const; |
73 | 79 |
74 // Gets the handle ID of the controller Service Worker, or | 80 // Gets the handle ID of the controller Service Worker, or |
75 // kInvalidServiceWorkerHandleId if the provider is not controlled | 81 // kInvalidServiceWorkerHandleId if the provider is not controlled |
76 // by a Service Worker. | 82 // by a Service Worker. |
77 int controller_handle_id() const; | 83 int controller_handle_id() const; |
78 | 84 |
| 85 // Gets the handle ID of the associated registration, or |
| 86 // kInvalidRegistrationHandleId if the provider does not have a ready |
| 87 // Service Worker registration. |
| 88 int registration_handle_id() const; |
| 89 |
79 private: | 90 private: |
80 friend class base::RefCounted<ServiceWorkerProviderContext>; | 91 friend class base::RefCounted<ServiceWorkerProviderContext>; |
81 ~ServiceWorkerProviderContext(); | 92 ~ServiceWorkerProviderContext(); |
82 | 93 |
83 const int provider_id_; | 94 const int provider_id_; |
84 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; | 95 scoped_refptr<base::MessageLoopProxy> main_thread_loop_proxy_; |
85 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 96 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
86 scoped_ptr<ServiceWorkerHandleReference> installing_; | 97 scoped_ptr<ServiceWorkerHandleReference> installing_; |
87 scoped_ptr<ServiceWorkerHandleReference> waiting_; | 98 scoped_ptr<ServiceWorkerHandleReference> waiting_; |
88 scoped_ptr<ServiceWorkerHandleReference> active_; | 99 scoped_ptr<ServiceWorkerHandleReference> active_; |
89 scoped_ptr<ServiceWorkerHandleReference> controller_; | 100 scoped_ptr<ServiceWorkerHandleReference> controller_; |
90 | 101 |
| 102 scoped_ptr<ServiceWorkerRegistrationHandleReference> registration_; |
| 103 |
91 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); | 104 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderContext); |
92 }; | 105 }; |
93 | 106 |
94 } // namespace content | 107 } // namespace content |
95 | 108 |
96 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ | 109 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_CONTEXT_H_ |
OLD | NEW |