| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 96 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| 97 if (context_) | 97 if (context_) |
| 98 context_->UnregisterProviderHostByClientID(client_uuid_); | 98 context_->UnregisterProviderHostByClientID(client_uuid_); |
| 99 | 99 |
| 100 // Clear docurl so the deferred activation of a waiting worker | 100 // Clear docurl so the deferred activation of a waiting worker |
| 101 // won't associate the new version with a provider being destroyed. | 101 // won't associate the new version with a provider being destroyed. |
| 102 document_url_ = GURL(); | 102 document_url_ = GURL(); |
| 103 if (controlling_version_.get()) | 103 if (controlling_version_.get()) |
| 104 controlling_version_->RemoveControllee(this); | 104 controlling_version_->RemoveControllee(this); |
| 105 | 105 |
| 106 for (auto& key_registration : matching_registrations_) { | 106 RemoveAllMatchingRegistrations(); |
| 107 DecreaseProcessReference(key_registration.second->pattern()); | |
| 108 key_registration.second->RemoveListener(this); | |
| 109 } | |
| 110 | 107 |
| 111 for (const GURL& pattern : associated_patterns_) | 108 for (const GURL& pattern : associated_patterns_) |
| 112 DecreaseProcessReference(pattern); | 109 DecreaseProcessReference(pattern); |
| 113 } | 110 } |
| 114 | 111 |
| 115 int ServiceWorkerProviderHost::frame_id() const { | 112 int ServiceWorkerProviderHost::frame_id() const { |
| 116 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) | 113 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) |
| 117 return route_id_; | 114 return route_id_; |
| 118 return MSG_ROUTING_NONE; | 115 return MSG_ROUTING_NONE; |
| 119 } | 116 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return; | 172 return; |
| 176 ServiceWorkerVersion* active_version = registration->active_version(); | 173 ServiceWorkerVersion* active_version = registration->active_version(); |
| 177 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); | 174 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); |
| 178 SetControllerVersionAttribute(active_version, | 175 SetControllerVersionAttribute(active_version, |
| 179 true /* notify_controllerchange */); | 176 true /* notify_controllerchange */); |
| 180 } | 177 } |
| 181 | 178 |
| 182 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 179 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| 183 DCHECK(!url.has_ref()); | 180 DCHECK(!url.has_ref()); |
| 184 document_url_ = url; | 181 document_url_ = url; |
| 182 if (IsProviderForClient()) |
| 183 SyncMatchingRegistrations(); |
| 185 } | 184 } |
| 186 | 185 |
| 187 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 186 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
| 188 topmost_frame_url_ = url; | 187 topmost_frame_url_ = url; |
| 189 } | 188 } |
| 190 | 189 |
| 191 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 190 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
| 192 ServiceWorkerVersion* version, | 191 ServiceWorkerVersion* version, |
| 193 bool notify_controllerchange) { | 192 bool notify_controllerchange) { |
| 194 CHECK(!version || IsContextSecureForServiceWorker()); | 193 CHECK(!version || IsContextSecureForServiceWorker()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 296 |
| 298 void ServiceWorkerProviderHost::RemoveMatchingRegistration( | 297 void ServiceWorkerProviderHost::RemoveMatchingRegistration( |
| 299 ServiceWorkerRegistration* registration) { | 298 ServiceWorkerRegistration* registration) { |
| 300 size_t key = registration->pattern().spec().size(); | 299 size_t key = registration->pattern().spec().size(); |
| 301 DCHECK(ContainsKey(matching_registrations_, key)); | 300 DCHECK(ContainsKey(matching_registrations_, key)); |
| 302 DecreaseProcessReference(registration->pattern()); | 301 DecreaseProcessReference(registration->pattern()); |
| 303 registration->RemoveListener(this); | 302 registration->RemoveListener(this); |
| 304 matching_registrations_.erase(key); | 303 matching_registrations_.erase(key); |
| 305 } | 304 } |
| 306 | 305 |
| 307 void ServiceWorkerProviderHost::AddAllMatchingRegistrations() { | |
| 308 DCHECK(context_); | |
| 309 const std::map<int64_t, ServiceWorkerRegistration*>& registrations = | |
| 310 context_->GetLiveRegistrations(); | |
| 311 for (const auto& key_registration : registrations) { | |
| 312 ServiceWorkerRegistration* registration = key_registration.second; | |
| 313 if (!registration->is_uninstalled() && | |
| 314 ServiceWorkerUtils::ScopeMatches(registration->pattern(), | |
| 315 document_url_)) | |
| 316 AddMatchingRegistration(registration); | |
| 317 } | |
| 318 } | |
| 319 | |
| 320 ServiceWorkerRegistration* | 306 ServiceWorkerRegistration* |
| 321 ServiceWorkerProviderHost::MatchRegistration() const { | 307 ServiceWorkerProviderHost::MatchRegistration() const { |
| 322 ServiceWorkerRegistrationMap::const_reverse_iterator it = | 308 ServiceWorkerRegistrationMap::const_reverse_iterator it = |
| 323 matching_registrations_.rbegin(); | 309 matching_registrations_.rbegin(); |
| 324 for (; it != matching_registrations_.rend(); ++it) { | 310 for (; it != matching_registrations_.rend(); ++it) { |
| 325 if (it->second->is_uninstalled()) | 311 if (it->second->is_uninstalled()) |
| 326 continue; | 312 continue; |
| 327 if (it->second->is_uninstalling()) | 313 if (it->second->is_uninstalling()) |
| 328 return nullptr; | 314 return nullptr; |
| 329 return it->second.get(); | 315 return it->second.get(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 associated_registration_->waiting_version()); | 578 associated_registration_->waiting_version()); |
| 593 attrs.active = GetOrCreateServiceWorkerHandle( | 579 attrs.active = GetOrCreateServiceWorkerHandle( |
| 594 associated_registration_->active_version()); | 580 associated_registration_->active_version()); |
| 595 | 581 |
| 596 // Association message should be sent only for controllees. | 582 // Association message should be sent only for controllees. |
| 597 DCHECK(IsProviderForClient()); | 583 DCHECK(IsProviderForClient()); |
| 598 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | 584 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( |
| 599 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); | 585 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
| 600 } | 586 } |
| 601 | 587 |
| 588 void ServiceWorkerProviderHost::SyncMatchingRegistrations() { |
| 589 DCHECK(context_); |
| 590 RemoveAllMatchingRegistrations(); |
| 591 const auto& registrations = context_->GetLiveRegistrations(); |
| 592 for (const auto& key_registration : registrations) { |
| 593 ServiceWorkerRegistration* registration = key_registration.second; |
| 594 if (!registration->is_uninstalled() && |
| 595 ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| 596 document_url_)) |
| 597 AddMatchingRegistration(registration); |
| 598 } |
| 599 } |
| 600 |
| 601 void ServiceWorkerProviderHost::RemoveAllMatchingRegistrations() { |
| 602 for (const auto& it : matching_registrations_) { |
| 603 ServiceWorkerRegistration* registration = it.second.get(); |
| 604 DecreaseProcessReference(registration->pattern()); |
| 605 registration->RemoveListener(this); |
| 606 } |
| 607 matching_registrations_.clear(); |
| 608 } |
| 609 |
| 602 void ServiceWorkerProviderHost::IncreaseProcessReference( | 610 void ServiceWorkerProviderHost::IncreaseProcessReference( |
| 603 const GURL& pattern) { | 611 const GURL& pattern) { |
| 604 if (context_ && context_->process_manager()) { | 612 if (context_ && context_->process_manager()) { |
| 605 context_->process_manager()->AddProcessReferenceToPattern( | 613 context_->process_manager()->AddProcessReferenceToPattern( |
| 606 pattern, render_process_id_); | 614 pattern, render_process_id_); |
| 607 } | 615 } |
| 608 } | 616 } |
| 609 | 617 |
| 610 void ServiceWorkerProviderHost::DecreaseProcessReference( | 618 void ServiceWorkerProviderHost::DecreaseProcessReference( |
| 611 const GURL& pattern) { | 619 const GURL& pattern) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 671 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 664 render_thread_id_, provider_id(), | 672 render_thread_id_, provider_id(), |
| 665 GetOrCreateServiceWorkerHandle( | 673 GetOrCreateServiceWorkerHandle( |
| 666 associated_registration_->active_version()), | 674 associated_registration_->active_version()), |
| 667 false /* shouldNotifyControllerChange */)); | 675 false /* shouldNotifyControllerChange */)); |
| 668 } | 676 } |
| 669 } | 677 } |
| 670 } | 678 } |
| 671 | 679 |
| 672 } // namespace content | 680 } // namespace content |
| OLD | NEW |