OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 // document. | 40 // document. |
41 // | 41 // |
42 // Note this class can also host a running service worker, in which | 42 // Note this class can also host a running service worker, in which |
43 // case it will observe resource loads made directly by the service worker. | 43 // case it will observe resource loads made directly by the service worker. |
44 class CONTENT_EXPORT ServiceWorkerProviderHost | 44 class CONTENT_EXPORT ServiceWorkerProviderHost |
45 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), | 45 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), |
46 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 46 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { |
47 public: | 47 public: |
48 typedef base::Callback<void(bool)> FocusCallback; | 48 typedef base::Callback<void(bool)> FocusCallback; |
49 | 49 |
| 50 // If |render_frame_id| is MSG_ROUTING_NONE, this provider host works for the |
| 51 // worker context. |
50 ServiceWorkerProviderHost(int render_process_id, | 52 ServiceWorkerProviderHost(int render_process_id, |
51 int render_frame_id, | 53 int render_frame_id, |
52 int provider_id, | 54 int provider_id, |
53 base::WeakPtr<ServiceWorkerContextCore> context, | 55 base::WeakPtr<ServiceWorkerContextCore> context, |
54 ServiceWorkerDispatcherHost* dispatcher_host); | 56 ServiceWorkerDispatcherHost* dispatcher_host); |
55 virtual ~ServiceWorkerProviderHost(); | 57 virtual ~ServiceWorkerProviderHost(); |
56 | 58 |
57 int process_id() const { return render_process_id_; } | 59 int process_id() const { return render_process_id_; } |
58 int provider_id() const { return provider_id_; } | 60 int provider_id() const { return provider_id_; } |
59 int frame_id() const { return render_frame_id_; } | 61 int frame_id() const { return render_frame_id_; } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void PrepareForCrossSiteTransfer(); | 156 void PrepareForCrossSiteTransfer(); |
155 void CompleteCrossSiteTransfer( | 157 void CompleteCrossSiteTransfer( |
156 int new_process_id, | 158 int new_process_id, |
157 int new_frame_id, | 159 int new_frame_id, |
158 int new_provider_id, | 160 int new_provider_id, |
159 ServiceWorkerDispatcherHost* dispatcher_host); | 161 ServiceWorkerDispatcherHost* dispatcher_host); |
160 ServiceWorkerDispatcherHost* dispatcher_host() const { | 162 ServiceWorkerDispatcherHost* dispatcher_host() const { |
161 return dispatcher_host_; | 163 return dispatcher_host_; |
162 } | 164 } |
163 | 165 |
164 // Called from ServiceWorkerRegistrationHandle. | 166 // Sends event messages to the renderer. Events for the worker are queued up |
| 167 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
165 void SendUpdateFoundMessage( | 168 void SendUpdateFoundMessage( |
166 const ServiceWorkerRegistrationObjectInfo& object_info); | 169 const ServiceWorkerRegistrationObjectInfo& object_info); |
167 void SendSetVersionAttributesMessage( | 170 void SendSetVersionAttributesMessage( |
168 int registration_handle_id, | 171 int registration_handle_id, |
169 ChangedVersionAttributesMask changed_mask, | 172 ChangedVersionAttributesMask changed_mask, |
170 ServiceWorkerVersion* installing_version, | 173 ServiceWorkerVersion* installing_version, |
171 ServiceWorkerVersion* waiting_version, | 174 ServiceWorkerVersion* waiting_version, |
172 ServiceWorkerVersion* active_version); | 175 ServiceWorkerVersion* active_version); |
173 | |
174 // Called from ServiceWorkerHandle. | |
175 void SendServiceWorkerStateChangedMessage( | 176 void SendServiceWorkerStateChangedMessage( |
176 int worker_handle_id, | 177 int worker_handle_id, |
177 blink::WebServiceWorkerState state); | 178 blink::WebServiceWorkerState state); |
178 | 179 |
| 180 // Sets the worker thread id and flushes queued events. |
| 181 void SetReadyToSendMessagesToWorker(int render_thread_id); |
| 182 |
179 private: | 183 private: |
180 friend class ServiceWorkerProviderHostTest; | 184 friend class ServiceWorkerProviderHostTest; |
181 friend class ServiceWorkerWriteToCacheJobTest; | 185 friend class ServiceWorkerWriteToCacheJobTest; |
182 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 186 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
183 UpdateBefore24Hours); | 187 UpdateBefore24Hours); |
184 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 188 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
185 UpdateAfter24Hours); | 189 UpdateAfter24Hours); |
186 | 190 |
187 // ServiceWorkerRegistration::Listener overrides. | 191 // ServiceWorkerRegistration::Listener overrides. |
188 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 192 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
189 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 193 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
190 | 194 |
191 // Sets the controller version field to |version| or if |version| is NULL, | 195 // Sets the controller version field to |version| or if |version| is NULL, |
192 // clears the field. | 196 // clears the field. |
193 void SetControllerVersionAttribute(ServiceWorkerVersion* version); | 197 void SetControllerVersionAttribute(ServiceWorkerVersion* version); |
194 | 198 |
195 void SendAssociateRegistrationMessage(); | 199 void SendAssociateRegistrationMessage(); |
196 | 200 |
197 // Increase/decrease this host's process reference for |pattern|. | 201 // Increase/decrease this host's process reference for |pattern|. |
198 void IncreaseProcessReference(const GURL& pattern); | 202 void IncreaseProcessReference(const GURL& pattern); |
199 void DecreaseProcessReference(const GURL& pattern); | 203 void DecreaseProcessReference(const GURL& pattern); |
200 | 204 |
| 205 bool IsReadyToSendMessages() const; |
| 206 void Send(IPC::Message* message) const; |
| 207 |
201 int render_process_id_; | 208 int render_process_id_; |
202 int render_frame_id_; | 209 int render_frame_id_; |
| 210 int render_thread_id_; |
203 int provider_id_; | 211 int provider_id_; |
204 GURL document_url_; | 212 GURL document_url_; |
205 GURL topmost_frame_url_; | 213 GURL topmost_frame_url_; |
206 | 214 |
207 std::vector<GURL> associated_patterns_; | 215 std::vector<GURL> associated_patterns_; |
208 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 216 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
209 | 217 |
210 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 218 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
211 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 219 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
212 base::WeakPtr<ServiceWorkerContextCore> context_; | 220 base::WeakPtr<ServiceWorkerContextCore> context_; |
213 ServiceWorkerDispatcherHost* dispatcher_host_; | 221 ServiceWorkerDispatcherHost* dispatcher_host_; |
214 bool allow_association_; | 222 bool allow_association_; |
215 | 223 |
| 224 std::vector<base::Closure> queued_events_; |
| 225 |
216 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 226 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
217 }; | 227 }; |
218 | 228 |
219 } // namespace content | 229 } // namespace content |
220 | 230 |
221 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 231 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |