Chromium Code Reviews| Index: content/browser/service_worker/service_worker_provider_host.cc |
| diff --git a/content/browser/service_worker/service_worker_provider_host.cc b/content/browser/service_worker/service_worker_provider_host.cc |
| index 67b10a78ecc5f67db3558614ad66363396779441..5ea68b516ac8113ce501b76f8d0727fb3faea0f8 100644 |
| --- a/content/browser/service_worker/service_worker_provider_host.cc |
| +++ b/content/browser/service_worker/service_worker_provider_host.cc |
| @@ -103,10 +103,7 @@ ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
| if (controlling_version_.get()) |
| controlling_version_->RemoveControllee(this); |
| - for (auto& key_registration : matching_registrations_) { |
| - DecreaseProcessReference(key_registration.second->pattern()); |
| - key_registration.second->RemoveListener(this); |
| - } |
| + RemoveAllMatchingRegistration(); |
| for (const GURL& pattern : associated_patterns_) |
| DecreaseProcessReference(pattern); |
| @@ -182,6 +179,7 @@ void ServiceWorkerProviderHost::OnSkippedWaiting( |
| void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| DCHECK(!url.has_ref()); |
| document_url_ = url; |
| + SyncMatchingRegistrations(); |
|
nhiroki
2016/08/22 06:35:49
We may not have to sync up matching registrations
shimazu
2016/08/22 09:29:40
Done.
|
| } |
| void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
| @@ -306,19 +304,6 @@ void ServiceWorkerProviderHost::RemoveMatchingRegistration( |
| matching_registrations_.erase(key); |
| } |
| -void ServiceWorkerProviderHost::AddAllMatchingRegistrations() { |
| - DCHECK(context_); |
| - const std::map<int64_t, ServiceWorkerRegistration*>& registrations = |
| - context_->GetLiveRegistrations(); |
| - for (const auto& key_registration : registrations) { |
| - ServiceWorkerRegistration* registration = key_registration.second; |
| - if (!registration->is_uninstalled() && |
| - ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| - document_url_)) |
| - AddMatchingRegistration(registration); |
| - } |
| -} |
| - |
| ServiceWorkerRegistration* |
| ServiceWorkerProviderHost::MatchRegistration() const { |
| ServiceWorkerRegistrationMap::const_reverse_iterator it = |
| @@ -601,6 +586,28 @@ void ServiceWorkerProviderHost::SendAssociateRegistrationMessage() { |
| render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
| } |
| +void ServiceWorkerProviderHost::SyncMatchingRegistrations() { |
| + DCHECK(context_); |
| + RemoveAllMatchingRegistration(); |
| + const auto& registrations = context_->GetLiveRegistrations(); |
| + for (const auto& key_registration : registrations) { |
| + ServiceWorkerRegistration* registration = key_registration.second; |
| + if (!registration->is_uninstalled() && |
| + ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
| + document_url_)) |
| + AddMatchingRegistration(registration); |
| + } |
| +} |
| + |
| +void ServiceWorkerProviderHost::RemoveAllMatchingRegistration() { |
| + for (const auto& it : matching_registrations_) { |
| + ServiceWorkerRegistration* registration = it.second.get(); |
| + DecreaseProcessReference(registration->pattern()); |
| + registration->RemoveListener(this); |
| + } |
| + matching_registrations_.clear(); |
| +} |
| + |
| void ServiceWorkerProviderHost::IncreaseProcessReference( |
| const GURL& pattern) { |
| if (context_ && context_->process_manager()) { |