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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "content/browser/message_port_message_filter.h" | 8 #include "content/browser/message_port_message_filter.h" |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_context_request_handler. h" | 10 #include "content/browser/service_worker/service_worker_context_request_handler. h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 if (active_version != active_version_.get()) { | 93 if (active_version != active_version_.get()) { |
| 94 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; | 94 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; |
| 95 if (previous_version.get()) | 95 if (previous_version.get()) |
| 96 previous_version->RemovePotentialControllee(this); | 96 previous_version->RemovePotentialControllee(this); |
| 97 if (active_version) | 97 if (active_version) |
| 98 active_version->AddPotentialControllee(this); | 98 active_version->AddPotentialControllee(this); |
| 99 active_version_ = active_version; | 99 active_version_ = active_version; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 103 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
|
michaeln
2014/09/09 02:22:02
if this this method remains public, can you move i
| |
| 104 ServiceWorkerVersion* version) { | 104 ServiceWorkerVersion* version) { |
| 105 if (version == controlling_version_.get()) | 105 if (version == controlling_version_.get()) |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; | 108 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
| 109 controlling_version_ = version; | 109 controlling_version_ = version; |
| 110 if (version) | 110 if (version) |
| 111 version->AddControllee(this); | 111 version->AddControllee(this); |
| 112 if (previous_version.get()) | 112 if (previous_version.get()) |
| 113 previous_version->RemoveControllee(this); | 113 previous_version->RemoveControllee(this); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 running_hosted_version_ = live_version; | 140 running_hosted_version_ = live_version; |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void ServiceWorkerProviderHost::AssociateRegistration( | 144 void ServiceWorkerProviderHost::AssociateRegistration( |
| 145 ServiceWorkerRegistration* registration) { | 145 ServiceWorkerRegistration* registration) { |
| 146 DCHECK(CanAssociateRegistration(registration)); | 146 DCHECK(CanAssociateRegistration(registration)); |
| 147 | |
| 148 if (dispatcher_host_) { | |
| 149 ServiceWorkerRegistrationHandle* handle = | |
| 150 dispatcher_host_->GetOrCreateRegistrationHandle( | |
| 151 provider_id(), registration); | |
| 152 | |
| 153 ServiceWorkerVersionAttributes attrs; | |
| 154 attrs.installing = handle->CreateServiceWorkerHandleAndPass( | |
| 155 registration->installing_version()); | |
| 156 attrs.waiting = handle->CreateServiceWorkerHandleAndPass( | |
| 157 registration->waiting_version()); | |
| 158 attrs.active = handle->CreateServiceWorkerHandleAndPass( | |
| 159 registration->active_version()); | |
| 160 | |
| 161 dispatcher_host_->Send(new ServiceWorkerMsg_AssociateRegistration( | |
| 162 kDocumentMainThreadId, provider_id(), handle->GetObjectInfo(), attrs)); | |
|
nasko
2014/09/10 01:15:56
nit: Is this expected to change in the immediate f
nhiroki
2014/09/10 01:50:47
Good point. I think we don't have any plan to chan
nasko
2014/09/10 04:15:10
Fixing in another CL is fine. Please file a bug so
nhiroki
2014/09/10 05:28:47
I took a deeper look and found that this is not al
| |
| 163 } | |
| 164 | |
| 147 associated_registration_ = registration; | 165 associated_registration_ = registration; |
| 148 registration->AddListener(this); | 166 associated_registration_->AddListener(this); |
| 149 UpdatePotentialControllees(registration->installing_version(), | 167 UpdatePotentialControllees(registration->installing_version(), |
| 150 registration->waiting_version(), | 168 registration->waiting_version(), |
| 151 registration->active_version()); | 169 registration->active_version()); |
| 152 SetControllerVersionAttribute(registration->active_version()); | |
| 153 } | 170 } |
| 154 | 171 |
| 155 void ServiceWorkerProviderHost::UnassociateRegistration() { | 172 void ServiceWorkerProviderHost::UnassociateRegistration() { |
| 156 if (!associated_registration_.get()) | 173 if (!associated_registration_.get()) |
| 157 return; | 174 return; |
| 175 UpdatePotentialControllees(NULL, NULL, NULL); | |
| 176 SetControllerVersionAttribute(NULL); | |
|
michaeln
2014/09/09 02:22:02
does the change in order of operations matter here
nhiroki
2014/09/09 08:49:08
Just to make consistent with AssociateRegistration
| |
| 158 associated_registration_->RemoveListener(this); | 177 associated_registration_->RemoveListener(this); |
| 159 associated_registration_ = NULL; | 178 associated_registration_ = NULL; |
| 160 UpdatePotentialControllees(NULL, NULL, NULL); | 179 |
| 161 SetControllerVersionAttribute(NULL); | 180 if (dispatcher_host_) { |
| 181 dispatcher_host_->Send(new ServiceWorkerMsg_UnassociateRegistration( | |
| 182 kDocumentMainThreadId, provider_id())); | |
| 183 } | |
| 162 } | 184 } |
| 163 | 185 |
| 164 scoped_ptr<ServiceWorkerRequestHandler> | 186 scoped_ptr<ServiceWorkerRequestHandler> |
| 165 ServiceWorkerProviderHost::CreateRequestHandler( | 187 ServiceWorkerProviderHost::CreateRequestHandler( |
| 166 ResourceType resource_type, | 188 ResourceType resource_type, |
| 167 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 189 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 168 scoped_refptr<ResourceRequestBody> body) { | 190 scoped_refptr<ResourceRequestBody> body) { |
| 169 if (IsHostToRunningServiceWorker()) { | 191 if (IsHostToRunningServiceWorker()) { |
| 170 return scoped_ptr<ServiceWorkerRequestHandler>( | 192 return scoped_ptr<ServiceWorkerRequestHandler>( |
| 171 new ServiceWorkerContextRequestHandler( | 193 new ServiceWorkerContextRequestHandler( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | 246 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
| 225 } | 247 } |
| 226 return info; | 248 return info; |
| 227 } | 249 } |
| 228 | 250 |
| 229 bool ServiceWorkerProviderHost::IsContextAlive() { | 251 bool ServiceWorkerProviderHost::IsContextAlive() { |
| 230 return context_ != NULL; | 252 return context_ != NULL; |
| 231 } | 253 } |
| 232 | 254 |
| 233 } // namespace content | 255 } // namespace content |
| OLD | NEW |