| 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/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (previous_version.get()) | 175 if (previous_version.get()) |
| 176 previous_version->RemoveControllee(this); | 176 previous_version->RemoveControllee(this); |
| 177 | 177 |
| 178 if (!dispatcher_host_) | 178 if (!dispatcher_host_) |
| 179 return; // Could be NULL in some tests. | 179 return; // Could be NULL in some tests. |
| 180 | 180 |
| 181 bool should_notify_controllerchange = | 181 bool should_notify_controllerchange = |
| 182 is_claiming_ || (previous_version && version && version->skip_waiting()); | 182 is_claiming_ || (previous_version && version && version->skip_waiting()); |
| 183 | 183 |
| 184 // SetController message should be sent only for controllees. | 184 // SetController message should be sent only for controllees. |
| 185 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); | 185 DCHECK(IsProviderForClient()); |
| 186 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 186 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 187 render_thread_id_, provider_id(), | 187 render_thread_id_, provider_id(), |
| 188 CreateAndRegisterServiceWorkerHandle(version), | 188 CreateAndRegisterServiceWorkerHandle(version), |
| 189 should_notify_controllerchange)); | 189 should_notify_controllerchange)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 192 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
| 193 if (!context_) | 193 if (!context_) |
| 194 return true; // System is shutting down. | 194 return true; // System is shutting down. |
| 195 if (active_version()) | 195 if (active_version()) |
| 196 return false; // Unexpected bad message. | 196 return false; // Unexpected bad message. |
| 197 | 197 |
| 198 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); | 198 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); |
| 199 if (!live_version) | 199 if (!live_version) |
| 200 return true; // Was deleted before it got started. | 200 return true; // Was deleted before it got started. |
| 201 | 201 |
| 202 ServiceWorkerVersionInfo info = live_version->GetInfo(); | 202 ServiceWorkerVersionInfo info = live_version->GetInfo(); |
| 203 if (info.running_status != ServiceWorkerVersion::STARTING || | 203 if (info.running_status != ServiceWorkerVersion::STARTING || |
| 204 info.process_id != render_process_id_) { | 204 info.process_id != render_process_id_) { |
| 205 // If we aren't trying to start this version in our process | 205 // If we aren't trying to start this version in our process |
| 206 // something is amiss. | 206 // something is amiss. |
| 207 return false; | 207 return false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 running_hosted_version_ = live_version; | 210 running_hosted_version_ = live_version; |
| 211 return true; | 211 return true; |
| 212 } | 212 } |
| 213 | 213 |
| 214 bool ServiceWorkerProviderHost::IsProviderForClient() const { |
| 215 switch (provider_type_) { |
| 216 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: |
| 217 case SERVICE_WORKER_PROVIDER_FOR_WORKER: |
| 218 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: |
| 219 return true; |
| 220 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: |
| 221 case SERVICE_WORKER_PROVIDER_UNKNOWN: |
| 222 return false; |
| 223 } |
| 224 NOTREACHED() << provider_type_; |
| 225 return false; |
| 226 } |
| 227 |
| 214 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type() | 228 blink::WebServiceWorkerClientType ServiceWorkerProviderHost::client_type() |
| 215 const { | 229 const { |
| 216 switch (provider_type_) { | 230 switch (provider_type_) { |
| 217 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: | 231 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: |
| 218 return blink::WebServiceWorkerClientTypeWindow; | 232 return blink::WebServiceWorkerClientTypeWindow; |
| 219 case SERVICE_WORKER_PROVIDER_FOR_WORKER: | 233 case SERVICE_WORKER_PROVIDER_FOR_WORKER: |
| 220 return blink::WebServiceWorkerClientTypeWorker; | 234 return blink::WebServiceWorkerClientTypeWorker; |
| 221 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: | 235 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: |
| 222 return blink::WebServiceWorkerClientTypeSharedWorker; | 236 return blink::WebServiceWorkerClientTypeSharedWorker; |
| 223 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: | 237 case SERVICE_WORKER_PROVIDER_FOR_CONTROLLER: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 241 queued_events_.clear(); | 255 queued_events_.clear(); |
| 242 if (!associated_registration_.get()) | 256 if (!associated_registration_.get()) |
| 243 return; | 257 return; |
| 244 associated_registration_ = NULL; | 258 associated_registration_ = NULL; |
| 245 SetControllerVersionAttribute(NULL); | 259 SetControllerVersionAttribute(NULL); |
| 246 | 260 |
| 247 if (!dispatcher_host_) | 261 if (!dispatcher_host_) |
| 248 return; | 262 return; |
| 249 | 263 |
| 250 // Disassociation message should be sent only for controllees. | 264 // Disassociation message should be sent only for controllees. |
| 251 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); | 265 DCHECK(IsProviderForClient()); |
| 252 Send(new ServiceWorkerMsg_DisassociateRegistration( | 266 Send(new ServiceWorkerMsg_DisassociateRegistration( |
| 253 render_thread_id_, provider_id())); | 267 render_thread_id_, provider_id())); |
| 254 } | 268 } |
| 255 | 269 |
| 256 void ServiceWorkerProviderHost::AddMatchingRegistration( | 270 void ServiceWorkerProviderHost::AddMatchingRegistration( |
| 257 ServiceWorkerRegistration* registration) { | 271 ServiceWorkerRegistration* registration) { |
| 258 DCHECK(ServiceWorkerUtils::ScopeMatches( | 272 DCHECK(ServiceWorkerUtils::ScopeMatches( |
| 259 registration->pattern(), document_url_)); | 273 registration->pattern(), document_url_)); |
| 260 size_t key = registration->pattern().spec().size(); | 274 size_t key = registration->pattern().spec().size(); |
| 261 if (ContainsKey(matching_registrations_, key)) | 275 if (ContainsKey(matching_registrations_, key)) |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 592 |
| 579 ServiceWorkerVersionAttributes attrs; | 593 ServiceWorkerVersionAttributes attrs; |
| 580 attrs.installing = CreateAndRegisterServiceWorkerHandle( | 594 attrs.installing = CreateAndRegisterServiceWorkerHandle( |
| 581 associated_registration_->installing_version()); | 595 associated_registration_->installing_version()); |
| 582 attrs.waiting = CreateAndRegisterServiceWorkerHandle( | 596 attrs.waiting = CreateAndRegisterServiceWorkerHandle( |
| 583 associated_registration_->waiting_version()); | 597 associated_registration_->waiting_version()); |
| 584 attrs.active = CreateAndRegisterServiceWorkerHandle( | 598 attrs.active = CreateAndRegisterServiceWorkerHandle( |
| 585 associated_registration_->active_version()); | 599 associated_registration_->active_version()); |
| 586 | 600 |
| 587 // Association message should be sent only for controllees. | 601 // Association message should be sent only for controllees. |
| 588 DCHECK_NE(SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, provider_type_); | 602 DCHECK(IsProviderForClient()); |
| 589 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | 603 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( |
| 590 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); | 604 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
| 591 } | 605 } |
| 592 | 606 |
| 593 void ServiceWorkerProviderHost::IncreaseProcessReference( | 607 void ServiceWorkerProviderHost::IncreaseProcessReference( |
| 594 const GURL& pattern) { | 608 const GURL& pattern) { |
| 595 if (context_ && context_->process_manager()) { | 609 if (context_ && context_->process_manager()) { |
| 596 context_->process_manager()->AddProcessReferenceToPattern( | 610 context_->process_manager()->AddProcessReferenceToPattern( |
| 597 pattern, render_process_id_); | 611 pattern, render_process_id_); |
| 598 } | 612 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 628 return context_ != NULL; | 642 return context_ != NULL; |
| 629 } | 643 } |
| 630 | 644 |
| 631 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { | 645 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { |
| 632 DCHECK(dispatcher_host_); | 646 DCHECK(dispatcher_host_); |
| 633 DCHECK(IsReadyToSendMessages()); | 647 DCHECK(IsReadyToSendMessages()); |
| 634 dispatcher_host_->Send(message); | 648 dispatcher_host_->Send(message); |
| 635 } | 649 } |
| 636 | 650 |
| 637 } // namespace content | 651 } // namespace content |
| OLD | NEW |