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 #include "content/browser/service_worker/service_worker_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "content/browser/message_port_message_filter.h" | 8 #include "content/browser/message_port_message_filter.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 10 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 web_contents->GetDelegate()->ActivateContents(web_contents); | 39 web_contents->GetDelegate()->ActivateContents(web_contents); |
40 } | 40 } |
41 | 41 |
42 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 42 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
43 base::Bind(callback, result)); | 43 base::Bind(callback, result)); |
44 } | 44 } |
45 | 45 |
46 } // anonymous namespace | 46 } // anonymous namespace |
47 | 47 |
48 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 48 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
49 int render_process_id, int render_frame_id, int provider_id, | 49 int render_process_id, |
| 50 int render_frame_id, |
| 51 int provider_id, |
50 base::WeakPtr<ServiceWorkerContextCore> context, | 52 base::WeakPtr<ServiceWorkerContextCore> context, |
51 ServiceWorkerDispatcherHost* dispatcher_host) | 53 ServiceWorkerDispatcherHost* dispatcher_host) |
52 : render_process_id_(render_process_id), | 54 : render_process_id_(render_process_id), |
53 render_frame_id_(render_frame_id), | 55 render_frame_id_(render_frame_id), |
| 56 render_thread_id_(kDocumentMainThreadId), |
54 provider_id_(provider_id), | 57 provider_id_(provider_id), |
55 context_(context), | 58 context_(context), |
56 dispatcher_host_(dispatcher_host), | 59 dispatcher_host_(dispatcher_host), |
57 allow_association_(true) { | 60 allow_association_(true) { |
58 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 61 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 62 if (render_frame_id == MSG_ROUTING_NONE) { |
| 63 // Actual thread id is set when the worker context gets started. |
| 64 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
| 65 } |
59 } | 66 } |
60 | 67 |
61 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 68 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
62 // Clear docurl so the deferred activation of a waiting worker | 69 // Clear docurl so the deferred activation of a waiting worker |
63 // won't associate the new version with a provider being destroyed. | 70 // won't associate the new version with a provider being destroyed. |
64 document_url_ = GURL(); | 71 document_url_ = GURL(); |
65 if (controlling_version_.get()) | 72 if (controlling_version_.get()) |
66 controlling_version_->RemoveControllee(this); | 73 controlling_version_->RemoveControllee(this); |
67 if (associated_registration_.get()) { | 74 if (associated_registration_.get()) { |
68 DecreaseProcessReference(associated_registration_->pattern()); | 75 DecreaseProcessReference(associated_registration_->pattern()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 version->AddControllee(this); | 119 version->AddControllee(this); |
113 if (previous_version.get()) | 120 if (previous_version.get()) |
114 previous_version->RemoveControllee(this); | 121 previous_version->RemoveControllee(this); |
115 | 122 |
116 if (!dispatcher_host_) | 123 if (!dispatcher_host_) |
117 return; // Could be NULL in some tests. | 124 return; // Could be NULL in some tests. |
118 | 125 |
119 bool should_notify_controllerchange = | 126 bool should_notify_controllerchange = |
120 previous_version && version && version->skip_waiting(); | 127 previous_version && version && version->skip_waiting(); |
121 | 128 |
122 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 129 // SetController message should be sent only for the document context. |
123 kDocumentMainThreadId, provider_id(), | 130 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
| 131 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 132 render_thread_id_, provider_id(), |
124 CreateAndRegisterServiceWorkerHandle(version), | 133 CreateAndRegisterServiceWorkerHandle(version), |
125 should_notify_controllerchange)); | 134 should_notify_controllerchange)); |
126 } | 135 } |
127 | 136 |
128 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 137 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
129 if (!context_) | 138 if (!context_) |
130 return true; // System is shutting down. | 139 return true; // System is shutting down. |
131 if (active_version()) | 140 if (active_version()) |
132 return false; // Unexpected bad message. | 141 return false; // Unexpected bad message. |
133 | 142 |
(...skipping 20 matching lines...) Expand all Loading... |
154 DecreaseProcessReference(associated_registration_->pattern()); | 163 DecreaseProcessReference(associated_registration_->pattern()); |
155 IncreaseProcessReference(registration->pattern()); | 164 IncreaseProcessReference(registration->pattern()); |
156 | 165 |
157 associated_registration_ = registration; | 166 associated_registration_ = registration; |
158 associated_registration_->AddListener(this); | 167 associated_registration_->AddListener(this); |
159 SendAssociateRegistrationMessage(); | 168 SendAssociateRegistrationMessage(); |
160 SetControllerVersionAttribute(registration->active_version()); | 169 SetControllerVersionAttribute(registration->active_version()); |
161 } | 170 } |
162 | 171 |
163 void ServiceWorkerProviderHost::DisassociateRegistration() { | 172 void ServiceWorkerProviderHost::DisassociateRegistration() { |
| 173 queued_events_.clear(); |
164 if (!associated_registration_.get()) | 174 if (!associated_registration_.get()) |
165 return; | 175 return; |
166 DecreaseProcessReference(associated_registration_->pattern()); | 176 DecreaseProcessReference(associated_registration_->pattern()); |
167 associated_registration_->RemoveListener(this); | 177 associated_registration_->RemoveListener(this); |
168 associated_registration_ = NULL; | 178 associated_registration_ = NULL; |
169 SetControllerVersionAttribute(NULL); | 179 SetControllerVersionAttribute(NULL); |
170 | 180 |
171 if (dispatcher_host_) { | 181 if (!dispatcher_host_) |
172 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration( | 182 return; |
173 kDocumentMainThreadId, provider_id())); | 183 |
174 } | 184 // Disassociation message should be sent only for the document context. |
| 185 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
| 186 Send(new ServiceWorkerMsg_DisassociateRegistration( |
| 187 render_thread_id_, provider_id())); |
175 } | 188 } |
176 | 189 |
177 scoped_ptr<ServiceWorkerRequestHandler> | 190 scoped_ptr<ServiceWorkerRequestHandler> |
178 ServiceWorkerProviderHost::CreateRequestHandler( | 191 ServiceWorkerProviderHost::CreateRequestHandler( |
179 FetchRequestMode request_mode, | 192 FetchRequestMode request_mode, |
180 FetchCredentialsMode credentials_mode, | 193 FetchCredentialsMode credentials_mode, |
181 ResourceType resource_type, | 194 ResourceType resource_type, |
182 RequestContextType request_context_type, | 195 RequestContextType request_context_type, |
183 RequestContextFrameType frame_type, | 196 RequestContextFrameType frame_type, |
184 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 197 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 const base::string16& message, | 246 const base::string16& message, |
234 const std::vector<int>& sent_message_port_ids) { | 247 const std::vector<int>& sent_message_port_ids) { |
235 if (!dispatcher_host_) | 248 if (!dispatcher_host_) |
236 return; // Could be NULL in some tests. | 249 return; // Could be NULL in some tests. |
237 | 250 |
238 std::vector<int> new_routing_ids; | 251 std::vector<int> new_routing_ids; |
239 dispatcher_host_->message_port_message_filter()-> | 252 dispatcher_host_->message_port_message_filter()-> |
240 UpdateMessagePortsWithNewRoutes(sent_message_port_ids, | 253 UpdateMessagePortsWithNewRoutes(sent_message_port_ids, |
241 &new_routing_ids); | 254 &new_routing_ids); |
242 | 255 |
243 dispatcher_host_->Send( | 256 Send(new ServiceWorkerMsg_MessageToDocument( |
244 new ServiceWorkerMsg_MessageToDocument( | 257 kDocumentMainThreadId, provider_id(), |
245 kDocumentMainThreadId, provider_id(), | 258 message, |
246 message, | 259 sent_message_port_ids, |
247 sent_message_port_ids, | 260 new_routing_ids)); |
248 new_routing_ids)); | |
249 } | 261 } |
250 | 262 |
251 void ServiceWorkerProviderHost::Focus(const FocusCallback& callback) { | 263 void ServiceWorkerProviderHost::Focus(const FocusCallback& callback) { |
252 BrowserThread::PostTask( | 264 BrowserThread::PostTask( |
253 BrowserThread::UI, FROM_HERE, | 265 BrowserThread::UI, FROM_HERE, |
254 base::Bind(&FocusOnUIThread, | 266 base::Bind(&FocusOnUIThread, |
255 render_process_id_, | 267 render_process_id_, |
256 render_frame_id_, | 268 render_frame_id_, |
257 callback)); | 269 callback)); |
258 } | 270 } |
259 | 271 |
260 void ServiceWorkerProviderHost::GetClientInfo( | 272 void ServiceWorkerProviderHost::GetClientInfo( |
261 int embedded_worker_id, | 273 int embedded_worker_id, |
262 int request_id) { | 274 int request_id) { |
263 dispatcher_host_->Send(new ServiceWorkerMsg_GetClientInfo( | 275 Send(new ServiceWorkerMsg_GetClientInfo( |
264 kDocumentMainThreadId, embedded_worker_id, request_id, provider_id())); | 276 kDocumentMainThreadId, embedded_worker_id, request_id, provider_id())); |
265 } | 277 } |
266 | 278 |
267 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( | 279 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( |
268 const GURL& pattern) { | 280 const GURL& pattern) { |
269 associated_patterns_.push_back(pattern); | 281 associated_patterns_.push_back(pattern); |
270 IncreaseProcessReference(pattern); | 282 IncreaseProcessReference(pattern); |
271 } | 283 } |
272 | 284 |
273 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { | 285 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { |
274 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 286 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
| 287 DCHECK_NE(MSG_ROUTING_NONE, render_frame_id_); |
| 288 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
275 | 289 |
276 for (const GURL& pattern : associated_patterns_) | 290 for (const GURL& pattern : associated_patterns_) |
277 DecreaseProcessReference(pattern); | 291 DecreaseProcessReference(pattern); |
278 | 292 |
279 if (associated_registration_.get()) { | 293 if (associated_registration_.get()) { |
280 DecreaseProcessReference(associated_registration_->pattern()); | 294 DecreaseProcessReference(associated_registration_->pattern()); |
281 if (dispatcher_host_) { | 295 if (dispatcher_host_) { |
282 dispatcher_host_->Send(new ServiceWorkerMsg_DisassociateRegistration( | 296 Send(new ServiceWorkerMsg_DisassociateRegistration( |
283 kDocumentMainThreadId, provider_id())); | 297 render_thread_id_, provider_id())); |
284 } | 298 } |
285 } | 299 } |
286 | 300 |
287 render_process_id_ = ChildProcessHost::kInvalidUniqueID; | 301 render_process_id_ = ChildProcessHost::kInvalidUniqueID; |
288 render_frame_id_ = MSG_ROUTING_NONE; | 302 render_frame_id_ = MSG_ROUTING_NONE; |
| 303 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
289 provider_id_ = kInvalidServiceWorkerProviderId; | 304 provider_id_ = kInvalidServiceWorkerProviderId; |
290 dispatcher_host_ = nullptr; | 305 dispatcher_host_ = nullptr; |
291 } | 306 } |
292 | 307 |
293 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( | 308 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( |
294 int new_process_id, | 309 int new_process_id, |
295 int new_frame_id, | 310 int new_frame_id, |
296 int new_provider_id, | 311 int new_provider_id, |
297 ServiceWorkerDispatcherHost* new_dispatcher_host) { | 312 ServiceWorkerDispatcherHost* new_dispatcher_host) { |
298 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); | 313 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); |
299 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); | 314 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); |
| 315 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); |
300 | 316 |
301 render_process_id_ = new_process_id; | 317 render_process_id_ = new_process_id; |
302 render_frame_id_ = new_frame_id; | 318 render_frame_id_ = new_frame_id; |
| 319 render_thread_id_ = kDocumentMainThreadId; |
303 provider_id_ = new_provider_id; | 320 provider_id_ = new_provider_id; |
304 dispatcher_host_ = new_dispatcher_host; | 321 dispatcher_host_ = new_dispatcher_host; |
305 | 322 |
306 for (const GURL& pattern : associated_patterns_) | 323 for (const GURL& pattern : associated_patterns_) |
307 IncreaseProcessReference(pattern); | 324 IncreaseProcessReference(pattern); |
308 | 325 |
309 if (associated_registration_.get()) { | 326 if (associated_registration_.get()) { |
310 IncreaseProcessReference(associated_registration_->pattern()); | 327 IncreaseProcessReference(associated_registration_->pattern()); |
311 SendAssociateRegistrationMessage(); | 328 SendAssociateRegistrationMessage(); |
312 if (dispatcher_host_ && associated_registration_->active_version()) { | 329 if (dispatcher_host_ && associated_registration_->active_version()) { |
313 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 330 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
314 kDocumentMainThreadId, provider_id(), | 331 render_thread_id_, provider_id(), |
315 CreateAndRegisterServiceWorkerHandle( | 332 CreateAndRegisterServiceWorkerHandle( |
316 associated_registration_->active_version()), | 333 associated_registration_->active_version()), |
317 false /* shouldNotifyControllerChange */)); | 334 false /* shouldNotifyControllerChange */)); |
318 } | 335 } |
319 } | 336 } |
320 } | 337 } |
321 | 338 |
322 void ServiceWorkerProviderHost::SendUpdateFoundMessage( | 339 void ServiceWorkerProviderHost::SendUpdateFoundMessage( |
323 const ServiceWorkerRegistrationObjectInfo& object_info) { | 340 const ServiceWorkerRegistrationObjectInfo& object_info) { |
324 if (!dispatcher_host_) | 341 if (!dispatcher_host_) |
325 return; // Could be nullptr in some tests. | 342 return; // Could be nullptr in some tests. |
326 | 343 |
327 // TODO(nhiroki): Queue the message if a receiver's thread is not ready yet | 344 if (!IsReadyToSendMessages()) { |
328 // (http://crbug.com/437677). | 345 queued_events_.push_back( |
329 dispatcher_host_->Send(new ServiceWorkerMsg_UpdateFound( | 346 base::Bind(&ServiceWorkerProviderHost::SendUpdateFoundMessage, |
330 kDocumentMainThreadId, object_info)); | 347 AsWeakPtr(), object_info)); |
| 348 return; |
| 349 } |
| 350 |
| 351 Send(new ServiceWorkerMsg_UpdateFound(render_thread_id_, object_info)); |
331 } | 352 } |
332 | 353 |
333 void ServiceWorkerProviderHost::SendSetVersionAttributesMessage( | 354 void ServiceWorkerProviderHost::SendSetVersionAttributesMessage( |
334 int registration_handle_id, | 355 int registration_handle_id, |
335 ChangedVersionAttributesMask changed_mask, | 356 ChangedVersionAttributesMask changed_mask, |
336 ServiceWorkerVersion* installing_version, | 357 ServiceWorkerVersion* installing_version, |
337 ServiceWorkerVersion* waiting_version, | 358 ServiceWorkerVersion* waiting_version, |
338 ServiceWorkerVersion* active_version) { | 359 ServiceWorkerVersion* active_version) { |
339 if (!dispatcher_host_) | 360 if (!dispatcher_host_) |
340 return; // Could be nullptr in some tests. | 361 return; // Could be nullptr in some tests. |
341 if (!changed_mask.changed()) | 362 if (!changed_mask.changed()) |
342 return; | 363 return; |
343 | 364 |
| 365 if (!IsReadyToSendMessages()) { |
| 366 queued_events_.push_back( |
| 367 base::Bind(&ServiceWorkerProviderHost::SendSetVersionAttributesMessage, |
| 368 AsWeakPtr(), registration_handle_id, changed_mask, |
| 369 make_scoped_refptr(installing_version), |
| 370 make_scoped_refptr(waiting_version), |
| 371 make_scoped_refptr(active_version))); |
| 372 return; |
| 373 } |
| 374 |
344 ServiceWorkerVersionAttributes attrs; | 375 ServiceWorkerVersionAttributes attrs; |
345 if (changed_mask.installing_changed()) | 376 if (changed_mask.installing_changed()) |
346 attrs.installing = CreateAndRegisterServiceWorkerHandle(installing_version); | 377 attrs.installing = CreateAndRegisterServiceWorkerHandle(installing_version); |
347 if (changed_mask.waiting_changed()) | 378 if (changed_mask.waiting_changed()) |
348 attrs.waiting = CreateAndRegisterServiceWorkerHandle(waiting_version); | 379 attrs.waiting = CreateAndRegisterServiceWorkerHandle(waiting_version); |
349 if (changed_mask.active_changed()) | 380 if (changed_mask.active_changed()) |
350 attrs.active = CreateAndRegisterServiceWorkerHandle(active_version); | 381 attrs.active = CreateAndRegisterServiceWorkerHandle(active_version); |
351 | 382 |
352 // TODO(nhiroki): Queue the message if a receiver's thread is not ready yet | 383 Send(new ServiceWorkerMsg_SetVersionAttributes( |
353 // (http://crbug.com/437677). | 384 render_thread_id_, provider_id_, registration_handle_id, |
354 dispatcher_host_->Send(new ServiceWorkerMsg_SetVersionAttributes( | |
355 kDocumentMainThreadId, provider_id_, registration_handle_id, | |
356 changed_mask.changed(), attrs)); | 385 changed_mask.changed(), attrs)); |
357 } | 386 } |
358 | 387 |
359 void ServiceWorkerProviderHost::SendServiceWorkerStateChangedMessage( | 388 void ServiceWorkerProviderHost::SendServiceWorkerStateChangedMessage( |
360 int worker_handle_id, | 389 int worker_handle_id, |
361 blink::WebServiceWorkerState state) { | 390 blink::WebServiceWorkerState state) { |
362 if (!dispatcher_host_) | 391 if (!dispatcher_host_) |
363 return; | 392 return; |
364 | 393 |
365 // TODO(nhiroki): Queue the message if a receiver's thread is not ready yet | 394 if (!IsReadyToSendMessages()) { |
366 // (http://crbug.com/437677). | 395 queued_events_.push_back(base::Bind( |
367 dispatcher_host_->Send(new ServiceWorkerMsg_ServiceWorkerStateChanged( | 396 &ServiceWorkerProviderHost::SendServiceWorkerStateChangedMessage, |
368 kDocumentMainThreadId, worker_handle_id, state)); | 397 AsWeakPtr(), worker_handle_id, state)); |
| 398 return; |
| 399 } |
| 400 |
| 401 Send(new ServiceWorkerMsg_ServiceWorkerStateChanged( |
| 402 render_thread_id_, worker_handle_id, state)); |
| 403 } |
| 404 |
| 405 void ServiceWorkerProviderHost::SetReadyToSendMessagesToWorker( |
| 406 int render_thread_id) { |
| 407 DCHECK(!IsReadyToSendMessages()); |
| 408 render_thread_id_ = render_thread_id; |
| 409 |
| 410 for (const auto& event : queued_events_) |
| 411 event.Run(); |
| 412 queued_events_.clear(); |
369 } | 413 } |
370 | 414 |
371 void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() { | 415 void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() { |
372 if (!dispatcher_host_) | 416 if (!dispatcher_host_) |
373 return; | 417 return; |
374 | 418 |
375 ServiceWorkerRegistrationHandle* handle = | 419 ServiceWorkerRegistrationHandle* handle = |
376 dispatcher_host_->GetOrCreateRegistrationHandle( | 420 dispatcher_host_->GetOrCreateRegistrationHandle( |
377 AsWeakPtr(), associated_registration_.get()); | 421 AsWeakPtr(), associated_registration_.get()); |
378 | 422 |
379 ServiceWorkerVersionAttributes attrs; | 423 ServiceWorkerVersionAttributes attrs; |
380 attrs.installing = CreateAndRegisterServiceWorkerHandle( | 424 attrs.installing = CreateAndRegisterServiceWorkerHandle( |
381 associated_registration_->installing_version()); | 425 associated_registration_->installing_version()); |
382 attrs.waiting = CreateAndRegisterServiceWorkerHandle( | 426 attrs.waiting = CreateAndRegisterServiceWorkerHandle( |
383 associated_registration_->waiting_version()); | 427 associated_registration_->waiting_version()); |
384 attrs.active = CreateAndRegisterServiceWorkerHandle( | 428 attrs.active = CreateAndRegisterServiceWorkerHandle( |
385 associated_registration_->active_version()); | 429 associated_registration_->active_version()); |
386 | 430 |
| 431 // Association message should be sent only for the document context. |
| 432 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); |
387 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | 433 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( |
388 kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs)); | 434 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
389 } | 435 } |
390 | 436 |
391 void ServiceWorkerProviderHost::IncreaseProcessReference( | 437 void ServiceWorkerProviderHost::IncreaseProcessReference( |
392 const GURL& pattern) { | 438 const GURL& pattern) { |
393 if (context_ && context_->process_manager()) { | 439 if (context_ && context_->process_manager()) { |
394 context_->process_manager()->AddProcessReferenceToPattern( | 440 context_->process_manager()->AddProcessReferenceToPattern( |
395 pattern, render_process_id_); | 441 pattern, render_process_id_); |
396 } | 442 } |
397 } | 443 } |
398 | 444 |
399 void ServiceWorkerProviderHost::DecreaseProcessReference( | 445 void ServiceWorkerProviderHost::DecreaseProcessReference( |
400 const GURL& pattern) { | 446 const GURL& pattern) { |
401 if (context_ && context_->process_manager()) { | 447 if (context_ && context_->process_manager()) { |
402 context_->process_manager()->RemoveProcessReferenceFromPattern( | 448 context_->process_manager()->RemoveProcessReferenceFromPattern( |
403 pattern, render_process_id_); | 449 pattern, render_process_id_); |
404 } | 450 } |
405 } | 451 } |
406 | 452 |
| 453 bool ServiceWorkerProviderHost::IsReadyToSendMessages() const { |
| 454 return render_thread_id_ != kInvalidEmbeddedWorkerThreadId; |
| 455 } |
| 456 |
407 bool ServiceWorkerProviderHost::IsContextAlive() { | 457 bool ServiceWorkerProviderHost::IsContextAlive() { |
408 return context_ != NULL; | 458 return context_ != NULL; |
409 } | 459 } |
410 | 460 |
| 461 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
| 462 DCHECK(dispatcher_host_); |
| 463 DCHECK(IsReadyToSendMessages()); |
| 464 dispatcher_host_->Send(message); |
| 465 } |
| 466 |
411 } // namespace content | 467 } // namespace content |
OLD | NEW |