| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 ServiceWorkerDispatcherHost* dispatcher_host) | 75 ServiceWorkerDispatcherHost* dispatcher_host) |
| 76 : client_uuid_(base::GenerateGUID()), | 76 : client_uuid_(base::GenerateGUID()), |
| 77 render_process_id_(render_process_id), | 77 render_process_id_(render_process_id), |
| 78 route_id_(route_id), | 78 route_id_(route_id), |
| 79 render_thread_id_(kDocumentMainThreadId), | 79 render_thread_id_(kDocumentMainThreadId), |
| 80 provider_id_(provider_id), | 80 provider_id_(provider_id), |
| 81 provider_type_(provider_type), | 81 provider_type_(provider_type), |
| 82 parent_frame_security_level_(parent_frame_security_level), | 82 parent_frame_security_level_(parent_frame_security_level), |
| 83 context_(context), | 83 context_(context), |
| 84 dispatcher_host_(dispatcher_host), | 84 dispatcher_host_(dispatcher_host), |
| 85 allow_association_(true) { | 85 allow_association_(true), |
| 86 controller_was_deleted_(false) { |
| 86 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 87 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
| 87 | 88 |
| 88 // PlzNavigate | 89 // PlzNavigate |
| 89 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | 90 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
| 90 IsBrowserSideNavigationEnabled()); | 91 IsBrowserSideNavigationEnabled()); |
| 91 | 92 |
| 92 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 93 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
| 93 // Actual thread id is set when the service worker context gets started. | 94 // Actual thread id is set when the service worker context gets started. |
| 94 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; | 95 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; |
| 95 } | 96 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 void ServiceWorkerProviderHost::OnSkippedWaiting( | 168 void ServiceWorkerProviderHost::OnSkippedWaiting( |
| 168 ServiceWorkerRegistration* registration) { | 169 ServiceWorkerRegistration* registration) { |
| 169 if (associated_registration_ != registration) | 170 if (associated_registration_ != registration) |
| 170 return; | 171 return; |
| 171 // A client is "using" a registration if it is controlled by the active | 172 // A client is "using" a registration if it is controlled by the active |
| 172 // worker of the registration. skipWaiting doesn't cause a client to start | 173 // worker of the registration. skipWaiting doesn't cause a client to start |
| 173 // using the registration. | 174 // using the registration. |
| 174 if (!controlling_version_) | 175 if (!controlling_version_) |
| 175 return; | 176 return; |
| 176 ServiceWorkerVersion* active_version = registration->active_version(); | 177 ServiceWorkerVersion* active_version = registration->active_version(); |
| 178 // TODO(falken): Change to DCHECK once https://crbug.com/655910 is |
| 179 // resolved. |
| 180 CHECK(active_version); |
| 177 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); | 181 DCHECK_EQ(active_version->status(), ServiceWorkerVersion::ACTIVATING); |
| 178 SetControllerVersionAttribute(active_version, | 182 SetControllerVersionAttribute(active_version, |
| 179 true /* notify_controllerchange */); | 183 true /* notify_controllerchange */); |
| 180 } | 184 } |
| 181 | 185 |
| 182 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 186 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| 183 DCHECK(!url.has_ref()); | 187 DCHECK(!url.has_ref()); |
| 184 document_url_ = url; | 188 document_url_ = url; |
| 185 if (IsProviderForClient()) | 189 if (IsProviderForClient()) |
| 186 SyncMatchingRegistrations(); | 190 SyncMatchingRegistrations(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 for (; it != matching_registrations_.rend(); ++it) { | 317 for (; it != matching_registrations_.rend(); ++it) { |
| 314 if (it->second->is_uninstalled()) | 318 if (it->second->is_uninstalled()) |
| 315 continue; | 319 continue; |
| 316 if (it->second->is_uninstalling()) | 320 if (it->second->is_uninstalling()) |
| 317 return nullptr; | 321 return nullptr; |
| 318 return it->second.get(); | 322 return it->second.get(); |
| 319 } | 323 } |
| 320 return nullptr; | 324 return nullptr; |
| 321 } | 325 } |
| 322 | 326 |
| 323 void ServiceWorkerProviderHost::NotifyControllerLost() { | 327 void ServiceWorkerProviderHost::NotifyControllerLost(bool was_deleted) { |
| 328 if (was_deleted) |
| 329 controller_was_deleted_ = true; |
| 324 SetControllerVersionAttribute(nullptr, true /* notify_controllerchange */); | 330 SetControllerVersionAttribute(nullptr, true /* notify_controllerchange */); |
| 325 } | 331 } |
| 326 | 332 |
| 327 std::unique_ptr<ServiceWorkerRequestHandler> | 333 std::unique_ptr<ServiceWorkerRequestHandler> |
| 328 ServiceWorkerProviderHost::CreateRequestHandler( | 334 ServiceWorkerProviderHost::CreateRequestHandler( |
| 329 FetchRequestMode request_mode, | 335 FetchRequestMode request_mode, |
| 330 FetchCredentialsMode credentials_mode, | 336 FetchCredentialsMode credentials_mode, |
| 331 FetchRedirectMode redirect_mode, | 337 FetchRedirectMode redirect_mode, |
| 332 ResourceType resource_type, | 338 ResourceType resource_type, |
| 333 RequestContextType request_context_type, | 339 RequestContextType request_context_type, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 410 } |
| 405 | 411 |
| 406 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( | 412 void ServiceWorkerProviderHost::AddScopedProcessReferenceToPattern( |
| 407 const GURL& pattern) { | 413 const GURL& pattern) { |
| 408 associated_patterns_.push_back(pattern); | 414 associated_patterns_.push_back(pattern); |
| 409 IncreaseProcessReference(pattern); | 415 IncreaseProcessReference(pattern); |
| 410 } | 416 } |
| 411 | 417 |
| 412 void ServiceWorkerProviderHost::ClaimedByRegistration( | 418 void ServiceWorkerProviderHost::ClaimedByRegistration( |
| 413 ServiceWorkerRegistration* registration) { | 419 ServiceWorkerRegistration* registration) { |
| 414 DCHECK(registration->active_version()); | 420 // TODO(falken): Change to DCHECK once https://crbug.com/655910 is resolved. |
| 421 CHECK(registration->active_version()); |
| 415 if (registration == associated_registration_) { | 422 if (registration == associated_registration_) { |
| 416 SetControllerVersionAttribute(registration->active_version(), | 423 SetControllerVersionAttribute(registration->active_version(), |
| 417 true /* notify_controllerchange */); | 424 true /* notify_controllerchange */); |
| 418 } else if (allow_association_) { | 425 } else if (allow_association_) { |
| 419 DisassociateRegistration(); | 426 DisassociateRegistration(); |
| 420 AssociateRegistration(registration, true /* notify_controllerchange */); | 427 AssociateRegistration(registration, true /* notify_controllerchange */); |
| 421 } | 428 } |
| 422 } | 429 } |
| 423 | 430 |
| 424 bool ServiceWorkerProviderHost::GetRegistrationForReady( | 431 bool ServiceWorkerProviderHost::GetRegistrationForReady( |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 681 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 675 render_thread_id_, provider_id(), | 682 render_thread_id_, provider_id(), |
| 676 GetOrCreateServiceWorkerHandle( | 683 GetOrCreateServiceWorkerHandle( |
| 677 associated_registration_->active_version()), | 684 associated_registration_->active_version()), |
| 678 false /* shouldNotifyControllerChange */)); | 685 false /* shouldNotifyControllerChange */)); |
| 679 } | 686 } |
| 680 } | 687 } |
| 681 } | 688 } |
| 682 | 689 |
| 683 } // namespace content | 690 } // namespace content |
| OLD | NEW |