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 23 matching lines...) Expand all Loading... | |
| 34 // won't associate the new version with a provider being destroyed. | 34 // won't associate the new version with a provider being destroyed. |
| 35 document_url_ = GURL(); | 35 document_url_ = GURL(); |
| 36 if (controlling_version_) | 36 if (controlling_version_) |
| 37 controlling_version_->RemoveControllee(this); | 37 controlling_version_->RemoveControllee(this); |
| 38 if (active_version_) | 38 if (active_version_) |
| 39 active_version_->RemovePotentialControllee(this); | 39 active_version_->RemovePotentialControllee(this); |
| 40 if (waiting_version_) | 40 if (waiting_version_) |
| 41 waiting_version_->RemovePotentialControllee(this); | 41 waiting_version_->RemovePotentialControllee(this); |
| 42 if (installing_version_) | 42 if (installing_version_) |
| 43 installing_version_->RemovePotentialControllee(this); | 43 installing_version_->RemovePotentialControllee(this); |
| 44 if (associated_registration_) | |
| 45 associated_registration_->RemoveListener(this); | |
| 46 } | |
| 47 | |
| 48 void ServiceWorkerProviderHost::OnVersionAttributesChanged( | |
| 49 ServiceWorkerRegistration* registration, | |
| 50 ChangedVersionAttributesMask changed_mask, | |
| 51 const ServiceWorkerRegistrationInfo& info) { | |
| 52 if (changed_mask.installing_changed()) | |
| 53 SetInstallingVersion(registration->installing_version()); | |
| 54 if (changed_mask.waiting_changed()) | |
| 55 SetWaitingVersion(registration->waiting_version()); | |
| 56 if (changed_mask.active_changed()) | |
| 57 SetActiveVersion(registration->active_version()); | |
| 58 } | |
| 59 | |
| 60 void ServiceWorkerProviderHost::OnRegistrationDeleted( | |
| 61 ServiceWorkerRegistration* registration) { | |
| 62 DCHECK(associated_registration_); | |
| 63 DCHECK_EQ(registration->id(), associated_registration_->id()); | |
| 64 associated_registration_->RemoveListener(this); | |
| 65 associated_registration_ = NULL; | |
| 44 } | 66 } |
| 45 | 67 |
| 46 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { | 68 void ServiceWorkerProviderHost::SetDocumentUrl(const GURL& url) { |
| 47 DCHECK(!url.has_ref()); | 69 DCHECK(!url.has_ref()); |
| 48 document_url_ = url; | 70 document_url_ = url; |
| 49 } | 71 } |
| 50 | 72 |
| 51 void ServiceWorkerProviderHost::SetControllerVersion( | 73 void ServiceWorkerProviderHost::SetControllerVersion( |
| 52 ServiceWorkerVersion* version) { | 74 ServiceWorkerVersion* version) { |
| 53 DCHECK(CanAssociateVersion(version)); | 75 DCHECK(CanAssociateVersion(version)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 info.process_id != process_id_) { | 174 info.process_id != process_id_) { |
| 153 // If we aren't trying to start this version in our process | 175 // If we aren't trying to start this version in our process |
| 154 // something is amiss. | 176 // something is amiss. |
| 155 return false; | 177 return false; |
| 156 } | 178 } |
| 157 | 179 |
| 158 running_hosted_version_ = live_version; | 180 running_hosted_version_ = live_version; |
| 159 return true; | 181 return true; |
| 160 } | 182 } |
| 161 | 183 |
| 184 void ServiceWorkerProviderHost::SetRegistration( | |
| 185 ServiceWorkerRegistration* registration) { | |
| 186 DCHECK(CanAssociateRegistration(registration)); | |
| 187 if (associated_registration_) | |
| 188 associated_registration_->RemoveListener(this); | |
| 189 associated_registration_ = registration; | |
| 190 | |
| 191 if (!registration) { | |
| 192 SetActiveVersion(NULL); | |
| 193 SetInstallingVersion(NULL); | |
| 194 SetWaitingVersion(NULL); | |
| 195 return; | |
| 196 } | |
| 197 | |
| 198 registration->AddListener(this); | |
| 199 SetActiveVersion(registration->active_version()); | |
| 200 SetInstallingVersion(registration->installing_version()); | |
| 201 SetWaitingVersion(registration->waiting_version()); | |
| 202 } | |
| 203 | |
| 162 scoped_ptr<ServiceWorkerRequestHandler> | 204 scoped_ptr<ServiceWorkerRequestHandler> |
| 163 ServiceWorkerProviderHost::CreateRequestHandler( | 205 ServiceWorkerProviderHost::CreateRequestHandler( |
| 164 ResourceType resource_type, | 206 ResourceType resource_type, |
| 165 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context) { | 207 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context) { |
| 166 if (IsHostToRunningServiceWorker()) { | 208 if (IsHostToRunningServiceWorker()) { |
| 167 return scoped_ptr<ServiceWorkerRequestHandler>( | 209 return scoped_ptr<ServiceWorkerRequestHandler>( |
| 168 new ServiceWorkerContextRequestHandler( | 210 new ServiceWorkerContextRequestHandler( |
| 169 context_, AsWeakPtr(), blob_storage_context, resource_type)); | 211 context_, AsWeakPtr(), blob_storage_context, resource_type)); |
| 170 } | 212 } |
| 171 if (ServiceWorkerUtils::IsMainResourceType(resource_type) || | 213 if (ServiceWorkerUtils::IsMainResourceType(resource_type) || |
| 172 active_version()) { | 214 active_version()) { |
| 173 return scoped_ptr<ServiceWorkerRequestHandler>( | 215 return scoped_ptr<ServiceWorkerRequestHandler>( |
| 174 new ServiceWorkerControlleeRequestHandler( | 216 new ServiceWorkerControlleeRequestHandler( |
| 175 context_, AsWeakPtr(), blob_storage_context, resource_type)); | 217 context_, AsWeakPtr(), blob_storage_context, resource_type)); |
| 176 } | 218 } |
| 177 return scoped_ptr<ServiceWorkerRequestHandler>(); | 219 return scoped_ptr<ServiceWorkerRequestHandler>(); |
| 178 } | 220 } |
| 179 | 221 |
| 180 bool ServiceWorkerProviderHost::CanAssociateVersion( | 222 bool ServiceWorkerProviderHost::CanAssociateVersion( |
|
michaeln
2014/08/07 01:34:35
i think this check gets simplified to version->reg
nhiroki
2014/08/07 02:57:27
Acknowledged. I'll make a separate CL for this cle
| |
| 181 ServiceWorkerVersion* version) { | 223 ServiceWorkerVersion* version) { |
| 182 if (!context_) | 224 if (!context_) |
| 183 return false; | 225 return false; |
| 184 if (running_hosted_version_) | 226 if (running_hosted_version_) |
| 185 return false; | 227 return false; |
| 186 if (!version) | 228 if (!version) |
| 187 return true; | 229 return true; |
| 188 | 230 |
| 189 ServiceWorkerVersion* already_associated_version = NULL; | 231 ServiceWorkerVersion* already_associated_version = NULL; |
| 190 if (controlling_version_) | 232 if (controlling_version_) |
| 191 already_associated_version = controlling_version_; | 233 already_associated_version = controlling_version_; |
| 192 if (active_version_) | 234 if (active_version_) |
| 193 already_associated_version = active_version_; | 235 already_associated_version = active_version_; |
| 194 else if (waiting_version_) | 236 else if (waiting_version_) |
| 195 already_associated_version = waiting_version_; | 237 already_associated_version = waiting_version_; |
| 196 else if (installing_version_) | 238 else if (installing_version_) |
| 197 already_associated_version = installing_version_; | 239 already_associated_version = installing_version_; |
| 198 | 240 |
| 199 return !already_associated_version || | 241 return !already_associated_version || |
| 200 already_associated_version->registration_id() == | 242 already_associated_version->registration_id() == |
| 201 version->registration_id(); | 243 version->registration_id(); |
| 202 } | 244 } |
| 203 | 245 |
| 246 bool ServiceWorkerProviderHost::CanAssociateRegistration( | |
| 247 ServiceWorkerRegistration* registration) { | |
| 248 if (!context_) | |
| 249 return false; | |
|
michaeln
2014/08/07 01:34:35
also if (running_hosted_version_) return false;
nhiroki
2014/08/07 02:57:27
Done.
| |
| 250 if (!registration) | |
|
michaeln
2014/08/07 01:34:35
seems like NULL should not be valid inputs to this
nhiroki
2014/08/07 02:57:27
Done.
| |
| 251 return true; | |
| 252 if (associated_registration_) | |
| 253 return false; | |
| 254 return true; | |
| 255 } | |
| 256 | |
| 204 void ServiceWorkerProviderHost::PostMessage( | 257 void ServiceWorkerProviderHost::PostMessage( |
| 205 const base::string16& message, | 258 const base::string16& message, |
| 206 const std::vector<int>& sent_message_port_ids) { | 259 const std::vector<int>& sent_message_port_ids) { |
| 207 if (!dispatcher_host_) | 260 if (!dispatcher_host_) |
| 208 return; // Could be NULL in some tests. | 261 return; // Could be NULL in some tests. |
| 209 | 262 |
| 210 std::vector<int> new_routing_ids; | 263 std::vector<int> new_routing_ids; |
| 211 dispatcher_host_->message_port_message_filter()-> | 264 dispatcher_host_->message_port_message_filter()-> |
| 212 UpdateMessagePortsWithNewRoutes(sent_message_port_ids, | 265 UpdateMessagePortsWithNewRoutes(sent_message_port_ids, |
| 213 &new_routing_ids); | 266 &new_routing_ids); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 231 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | 284 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
| 232 } | 285 } |
| 233 return info; | 286 return info; |
| 234 } | 287 } |
| 235 | 288 |
| 236 bool ServiceWorkerProviderHost::IsContextAlive() { | 289 bool ServiceWorkerProviderHost::IsContextAlive() { |
| 237 return context_ != NULL; | 290 return context_ != NULL; |
| 238 } | 291 } |
| 239 | 292 |
| 240 } // namespace content | 293 } // namespace content |
| OLD | NEW |