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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 return; | 175 return; |
| 176 ServiceWorkerVersion* active_version = registration->active_version(); | 176 ServiceWorkerVersion* active_version = registration->active_version(); |
| 177 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); | 177 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); |
| 178 SetControllerVersionAttribute(active_version, | 178 SetControllerVersionAttribute(active_version, |
| 179 true /* notify_controllerchange */); | 179 true /* notify_controllerchange */); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 182 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| 183 DCHECK(!url.has_ref()); | 183 DCHECK(!url.has_ref()); |
| 184 document_url_ = url; | 184 document_url_ = url; |
| 185 SyncMatchingRegistrations(); | |
| 185 } | 186 } |
| 186 | 187 |
| 187 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 188 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
| 188 topmost_frame_url_ = url; | 189 topmost_frame_url_ = url; |
| 189 } | 190 } |
| 190 | 191 |
| 191 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 192 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
| 192 ServiceWorkerVersion* version, | 193 ServiceWorkerVersion* version, |
| 193 bool notify_controllerchange) { | 194 bool notify_controllerchange) { |
| 194 CHECK(!version || IsContextSecureForServiceWorker()); | 195 CHECK(!version || IsContextSecureForServiceWorker()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 | 300 |
| 300 void ServiceWorkerProviderHost::RemoveMatchingRegistration( | 301 void ServiceWorkerProviderHost::RemoveMatchingRegistration( |
| 301 ServiceWorkerRegistration* registration) { | 302 ServiceWorkerRegistration* registration) { |
| 302 size_t key = registration->pattern().spec().size(); | 303 size_t key = registration->pattern().spec().size(); |
| 303 DCHECK(base::ContainsKey(matching_registrations_, key)); | 304 DCHECK(base::ContainsKey(matching_registrations_, key)); |
| 304 DecreaseProcessReference(registration->pattern()); | 305 DecreaseProcessReference(registration->pattern()); |
| 305 registration->RemoveListener(this); | 306 registration->RemoveListener(this); |
| 306 matching_registrations_.erase(key); | 307 matching_registrations_.erase(key); |
| 307 } | 308 } |
| 308 | 309 |
| 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* | 310 ServiceWorkerRegistration* |
| 323 ServiceWorkerProviderHost::MatchRegistration() const { | 311 ServiceWorkerProviderHost::MatchRegistration() const { |
| 324 ServiceWorkerRegistrationMap::const_reverse_iterator it = | 312 ServiceWorkerRegistrationMap::const_reverse_iterator it = |
| 325 matching_registrations_.rbegin(); | 313 matching_registrations_.rbegin(); |
| 326 for (; it != matching_registrations_.rend(); ++it) { | 314 for (; it != matching_registrations_.rend(); ++it) { |
| 327 if (it->second->is_uninstalled()) | 315 if (it->second->is_uninstalled()) |
| 328 continue; | 316 continue; |
| 329 if (it->second->is_uninstalling()) | 317 if (it->second->is_uninstalling()) |
| 330 return nullptr; | 318 return nullptr; |
| 331 return it->second.get(); | 319 return it->second.get(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 associated_registration_->waiting_version()); | 582 associated_registration_->waiting_version()); |
| 595 attrs.active = GetOrCreateServiceWorkerHandle( | 583 attrs.active = GetOrCreateServiceWorkerHandle( |
| 596 associated_registration_->active_version()); | 584 associated_registration_->active_version()); |
| 597 | 585 |
| 598 // Association message should be sent only for controllees. | 586 // Association message should be sent only for controllees. |
| 599 DCHECK(IsProviderForClient()); | 587 DCHECK(IsProviderForClient()); |
| 600 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | 588 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( |
| 601 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); | 589 render_thread_id_, provider_id(), handle->GetObjectInfo(), attrs)); |
| 602 } | 590 } |
| 603 | 591 |
| 592 void ServiceWorkerProviderHost::SyncMatchingRegistrations() { | |
| 593 DCHECK(context_); | |
| 594 | |
| 595 for (const auto& it : matching_registrations_) { | |
| 596 auto* registration = it.second.get(); | |
|
nhiroki
2016/08/19 05:26:51
line 605 does not use auto*. Can you make them con
shimazu
2016/08/19 09:43:15
Done.
| |
| 597 DecreaseProcessReference(registration->pattern()); | |
| 598 registration->RemoveListener(this); | |
| 599 } | |
| 600 matching_registrations_.clear(); | |
|
nhiroki
2016/08/19 05:26:51
How about making...
void ServiceWorkerProviderHos
shimazu
2016/08/19 09:43:15
Done.
| |
| 601 | |
| 602 const std::map<int64_t, ServiceWorkerRegistration*>& registrations = | |
|
nhiroki
2016/08/19 05:26:51
const auto& ?
shimazu
2016/08/19 09:43:15
Done.
| |
| 603 context_->GetLiveRegistrations(); | |
| 604 for (const auto& key_registration : registrations) { | |
| 605 ServiceWorkerRegistration* registration = key_registration.second; | |
| 606 if (!registration->is_uninstalled() && | |
| 607 ServiceWorkerUtils::ScopeMatches(registration->pattern(), | |
| 608 document_url_)) | |
| 609 AddMatchingRegistration(registration); | |
| 610 } | |
| 611 } | |
| 612 | |
| 604 void ServiceWorkerProviderHost::IncreaseProcessReference( | 613 void ServiceWorkerProviderHost::IncreaseProcessReference( |
| 605 const GURL& pattern) { | 614 const GURL& pattern) { |
| 606 if (context_ && context_->process_manager()) { | 615 if (context_ && context_->process_manager()) { |
| 607 context_->process_manager()->AddProcessReferenceToPattern( | 616 context_->process_manager()->AddProcessReferenceToPattern( |
| 608 pattern, render_process_id_); | 617 pattern, render_process_id_); |
| 609 } | 618 } |
| 610 } | 619 } |
| 611 | 620 |
| 612 void ServiceWorkerProviderHost::DecreaseProcessReference( | 621 void ServiceWorkerProviderHost::DecreaseProcessReference( |
| 613 const GURL& pattern) { | 622 const GURL& pattern) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 674 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 666 render_thread_id_, provider_id(), | 675 render_thread_id_, provider_id(), |
| 667 GetOrCreateServiceWorkerHandle( | 676 GetOrCreateServiceWorkerHandle( |
| 668 associated_registration_->active_version()), | 677 associated_registration_->active_version()), |
| 669 false /* shouldNotifyControllerChange */)); | 678 false /* shouldNotifyControllerChange */)); |
| 670 } | 679 } |
| 671 } | 680 } |
| 672 } | 681 } |
| 673 | 682 |
| 674 } // namespace content | 683 } // namespace content |
| OLD | NEW |