| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 for (const GURL& pattern : associated_patterns_) | 74 for (const GURL& pattern : associated_patterns_) |
| 75 DecreaseProcessReference(pattern); | 75 DecreaseProcessReference(pattern); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ServiceWorkerProviderHost::OnRegistrationFailed( | 78 void ServiceWorkerProviderHost::OnRegistrationFailed( |
| 79 ServiceWorkerRegistration* registration) { | 79 ServiceWorkerRegistration* registration) { |
| 80 DCHECK_EQ(associated_registration_.get(), registration); | 80 DCHECK_EQ(associated_registration_.get(), registration); |
| 81 DisassociateRegistration(); | 81 DisassociateRegistration(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ServiceWorkerProviderHost::OnSkippedWaiting( |
| 85 ServiceWorkerRegistration* registration) { |
| 86 DCHECK_EQ(associated_registration_.get(), registration); |
| 87 ServiceWorkerVersion* active_version = registration->active_version(); |
| 88 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); |
| 89 SetControllerVersionAttribute(active_version); |
| 90 } |
| 91 |
| 84 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 92 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| 85 DCHECK(!url.has_ref()); | 93 DCHECK(!url.has_ref()); |
| 86 document_url_ = url; | 94 document_url_ = url; |
| 87 } | 95 } |
| 88 | 96 |
| 89 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 97 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
| 90 topmost_frame_url_ = url; | 98 topmost_frame_url_ = url; |
| 91 } | 99 } |
| 92 | 100 |
| 93 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 101 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
| 94 ServiceWorkerVersion* version) { | 102 ServiceWorkerVersion* version) { |
| 95 if (version == controlling_version_.get()) | 103 if (version == controlling_version_.get()) |
| 96 return; | 104 return; |
| 97 | 105 |
| 98 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; | 106 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
| 99 controlling_version_ = version; | 107 controlling_version_ = version; |
| 100 if (version) | 108 if (version) |
| 101 version->AddControllee(this); | 109 version->AddControllee(this); |
| 102 if (previous_version.get()) | 110 if (previous_version.get()) |
| 103 previous_version->RemoveControllee(this); | 111 previous_version->RemoveControllee(this); |
| 104 | 112 |
| 105 if (!dispatcher_host_) | 113 if (!dispatcher_host_) |
| 106 return; // Could be NULL in some tests. | 114 return; // Could be NULL in some tests. |
| 107 | 115 |
| 116 bool should_notify_controllerchange = |
| 117 previous_version && version && version->skip_waiting(); |
| 118 |
| 108 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 119 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 109 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); | 120 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version), |
| 121 should_notify_controllerchange)); |
| 110 } | 122 } |
| 111 | 123 |
| 112 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 124 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
| 113 if (!context_) | 125 if (!context_) |
| 114 return true; // System is shutting down. | 126 return true; // System is shutting down. |
| 115 if (active_version()) | 127 if (active_version()) |
| 116 return false; // Unexpected bad message. | 128 return false; // Unexpected bad message. |
| 117 | 129 |
| 118 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); | 130 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); |
| 119 if (!live_version) | 131 if (!live_version) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 282 |
| 271 for (const GURL& pattern : associated_patterns_) | 283 for (const GURL& pattern : associated_patterns_) |
| 272 IncreaseProcessReference(pattern); | 284 IncreaseProcessReference(pattern); |
| 273 | 285 |
| 274 if (associated_registration_.get()) { | 286 if (associated_registration_.get()) { |
| 275 IncreaseProcessReference(associated_registration_->pattern()); | 287 IncreaseProcessReference(associated_registration_->pattern()); |
| 276 SendAssociateRegistrationMessage(); | 288 SendAssociateRegistrationMessage(); |
| 277 if (dispatcher_host_ && associated_registration_->active_version()) { | 289 if (dispatcher_host_ && associated_registration_->active_version()) { |
| 278 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 290 dispatcher_host_->Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 279 kDocumentMainThreadId, provider_id(), | 291 kDocumentMainThreadId, provider_id(), |
| 280 CreateHandleAndPass(associated_registration_->active_version()))); | 292 CreateHandleAndPass(associated_registration_->active_version()), |
| 293 false /* shouldNotifyControllerChange */)); |
| 281 } | 294 } |
| 282 } | 295 } |
| 283 } | 296 } |
| 284 | 297 |
| 285 void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() { | 298 void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() { |
| 286 if (!dispatcher_host_) | 299 if (!dispatcher_host_) |
| 287 return; | 300 return; |
| 288 | 301 |
| 289 ServiceWorkerRegistrationHandle* handle = | 302 ServiceWorkerRegistrationHandle* handle = |
| 290 dispatcher_host_->GetOrCreateRegistrationHandle( | 303 dispatcher_host_->GetOrCreateRegistrationHandle( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 context_->process_manager()->RemoveProcessReferenceFromPattern( | 345 context_->process_manager()->RemoveProcessReferenceFromPattern( |
| 333 pattern, render_process_id_); | 346 pattern, render_process_id_); |
| 334 } | 347 } |
| 335 } | 348 } |
| 336 | 349 |
| 337 bool ServiceWorkerProviderHost::IsContextAlive() { | 350 bool ServiceWorkerProviderHost::IsContextAlive() { |
| 338 return context_ != NULL; | 351 return context_ != NULL; |
| 339 } | 352 } |
| 340 | 353 |
| 341 } // namespace content | 354 } // namespace content |
| OLD | NEW |