Chromium Code Reviews| 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 RemoveAllMatchingRegistration(); |
| 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 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.
| |
| 185 } | 183 } |
| 186 | 184 |
| 187 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 185 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
| 188 topmost_frame_url_ = url; | 186 topmost_frame_url_ = url; |
| 189 } | 187 } |
| 190 | 188 |
| 191 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 189 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
| 192 ServiceWorkerVersion* version, | 190 ServiceWorkerVersion* version, |
| 193 bool notify_controllerchange) { | 191 bool notify_controllerchange) { |
| 194 CHECK(!version || IsContextSecureForServiceWorker()); | 192 CHECK(!version || IsContextSecureForServiceWorker()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 | 297 |
| 300 void ServiceWorkerProviderHost::RemoveMatchingRegistration( | 298 void ServiceWorkerProviderHost::RemoveMatchingRegistration( |
| 301 ServiceWorkerRegistration* registration) { | 299 ServiceWorkerRegistration* registration) { |
| 302 size_t key = registration->pattern().spec().size(); | 300 size_t key = registration->pattern().spec().size(); |
| 303 DCHECK(base::ContainsKey(matching_registrations_, key)); | 301 DCHECK(base::ContainsKey(matching_registrations_, key)); |
| 304 DecreaseProcessReference(registration->pattern()); | 302 DecreaseProcessReference(registration->pattern()); |
| 305 registration->RemoveListener(this); | 303 registration->RemoveListener(this); |
| 306 matching_registrations_.erase(key); | 304 matching_registrations_.erase(key); |
| 307 } | 305 } |
| 308 | 306 |
| 309 void ServiceWorkerProviderHost::AddAllMatchingRegistrations() { | |
| 310 DCHECK(context_); | |
| 311 const std::map<int64_t, ServiceWorkerRegistration*>& registrations = | |
| 312 context_->GetLiveRegistrations(); | |
| 313 for (const auto& key_registration : registrations) { | |
| 314 ServiceWorkerRegistration* registration = key_registration.second; | |
| 315 if (!registration->is_uninstalled() && | |
| 316 ServiceWorkerUtils::ScopeMatches(registration->pattern(), | |
| 317 document_url_)) | |
| 318 AddMatchingRegistration(registration); | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 ServiceWorkerRegistration* | 307 ServiceWorkerRegistration* |
| 323 ServiceWorkerProviderHost::MatchRegistration() const { | 308 ServiceWorkerProviderHost::MatchRegistration() const { |
| 324 ServiceWorkerRegistrationMap::const_reverse_iterator it = | 309 ServiceWorkerRegistrationMap::const_reverse_iterator it = |
| 325 matching_registrations_.rbegin(); | 310 matching_registrations_.rbegin(); |
| 326 for (; it != matching_registrations_.rend(); ++it) { | 311 for (; it != matching_registrations_.rend(); ++it) { |
| 327 if (it->second->is_uninstalled()) | 312 if (it->second->is_uninstalled()) |
| 328 continue; | 313 continue; |
| 329 if (it->second->is_uninstalling()) | 314 if (it->second->is_uninstalling()) |
| 330 return nullptr; | 315 return nullptr; |
| 331 return it->second.get(); | 316 return it->second.get(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 associated_registration_->waiting_version()); | 579 associated_registration_->waiting_version()); |
| 595 attrs.active = GetOrCreateServiceWorkerHandle( | 580 attrs.active = GetOrCreateServiceWorkerHandle( |
| 596 associated_registration_->active_version()); | 581 associated_registration_->active_version()); |
| 597 | 582 |
| 598 // Association message should be sent only for controllees. | 583 // Association message should be sent only for controllees. |
| 599 DCHECK(IsProviderForClient()); | 584 DCHECK(IsProviderForClient()); |
| 600 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | 585 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( |
| 601 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); | 586 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
| 602 } | 587 } |
| 603 | 588 |
| 589 void ServiceWorkerProviderHost::SyncMatchingRegistrations() { | |
| 590 DCHECK(context_); | |
| 591 RemoveAllMatchingRegistration(); | |
| 592 const auto& registrations = context_->GetLiveRegistrations(); | |
| 593 for (const auto& key_registration : registrations) { | |
| 594 ServiceWorkerRegistration* registration = key_registration.second; | |
| 595 if (!registration->is_uninstalled() && | |
| 596 ServiceWorkerUtils::ScopeMatches(registration->pattern(), | |
| 597 document_url_)) | |
| 598 AddMatchingRegistration(registration); | |
| 599 } | |
| 600 } | |
| 601 | |
| 602 void ServiceWorkerProviderHost::RemoveAllMatchingRegistration() { | |
| 603 for (const auto& it : matching_registrations_) { | |
| 604 ServiceWorkerRegistration* registration = it.second.get(); | |
| 605 DecreaseProcessReference(registration->pattern()); | |
| 606 registration->RemoveListener(this); | |
| 607 } | |
| 608 matching_registrations_.clear(); | |
| 609 } | |
| 610 | |
| 604 void ServiceWorkerProviderHost::IncreaseProcessReference( | 611 void ServiceWorkerProviderHost::IncreaseProcessReference( |
| 605 const GURL& pattern) { | 612 const GURL& pattern) { |
| 606 if (context_ && context_->process_manager()) { | 613 if (context_ && context_->process_manager()) { |
| 607 context_->process_manager()->AddProcessReferenceToPattern( | 614 context_->process_manager()->AddProcessReferenceToPattern( |
| 608 pattern, render_process_id_); | 615 pattern, render_process_id_); |
| 609 } | 616 } |
| 610 } | 617 } |
| 611 | 618 |
| 612 void ServiceWorkerProviderHost::DecreaseProcessReference( | 619 void ServiceWorkerProviderHost::DecreaseProcessReference( |
| 613 const GURL& pattern) { | 620 const GURL& pattern) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 672 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 666 render_thread_id_, provider_id(), | 673 render_thread_id_, provider_id(), |
| 667 GetOrCreateServiceWorkerHandle( | 674 GetOrCreateServiceWorkerHandle( |
| 668 associated_registration_->active_version()), | 675 associated_registration_->active_version()), |
| 669 false /* shouldNotifyControllerChange */)); | 676 false /* shouldNotifyControllerChange */)); |
| 670 } | 677 } |
| 671 } | 678 } |
| 672 } | 679 } |
| 673 | 680 |
| 674 } // namespace content | 681 } // namespace content |
| OLD | NEW |