| 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/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/child/child_thread_impl.h" | 11 #include "content/child/child_thread_impl.h" |
| 12 #include "content/child/service_worker/service_worker_handle_reference.h" | 12 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 13 #include "content/child/service_worker/service_worker_message_sender.h" |
| 13 #include "content/child/service_worker/service_worker_provider_context.h" | 14 #include "content/child/service_worker/service_worker_provider_context.h" |
| 14 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 15 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 15 #include "content/child/service_worker/web_service_worker_impl.h" | 16 #include "content/child/service_worker/web_service_worker_impl.h" |
| 16 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 17 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 17 #include "content/child/thread_safe_sender.h" | 18 #include "content/child/thread_safe_sender.h" |
| 18 #include "content/child/webmessageportchannel_impl.h" | 19 #include "content/child/webmessageportchannel_impl.h" |
| 19 #include "content/common/service_worker/service_worker_messages.h" | 20 #include "content/common/service_worker/service_worker_messages.h" |
| 20 #include "content/common/service_worker/service_worker_types.h" | 21 #include "content/common/service_worker/service_worker_types.h" |
| 21 #include "content/public/common/url_utils.h" | 22 #include "content/public/common/url_utils.h" |
| 22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerClientsInfo.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 ServiceWorkerDispatcher* const kHasBeenDeleted = | 39 ServiceWorkerDispatcher* const kHasBeenDeleted = |
| 39 reinterpret_cast<ServiceWorkerDispatcher*>(0x1); | 40 reinterpret_cast<ServiceWorkerDispatcher*>(0x1); |
| 40 | 41 |
| 41 int CurrentWorkerId() { | 42 int CurrentWorkerId() { |
| 42 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 43 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 } // namespace | 46 } // namespace |
| 46 | 47 |
| 47 ServiceWorkerDispatcher::ServiceWorkerDispatcher( | 48 ServiceWorkerDispatcher::ServiceWorkerDispatcher( |
| 48 ThreadSafeSender* thread_safe_sender) | 49 ServiceWorkerMessageSender* sender) |
| 49 : thread_safe_sender_(thread_safe_sender) { | 50 : sender_(sender) { |
| 50 g_dispatcher_tls.Pointer()->Set(this); | 51 g_dispatcher_tls.Pointer()->Set(this); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { | 54 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { |
| 54 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 55 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { | 58 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 58 bool handled = true; | 59 bool handled = true; |
| 59 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) | 60 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 OnUpdateFound) | 85 OnUpdateFound) |
| 85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 86 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
| 86 OnSetControllerServiceWorker) | 87 OnSetControllerServiceWorker) |
| 87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 88 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
| 88 OnPostMessage) | 89 OnPostMessage) |
| 89 IPC_MESSAGE_UNHANDLED(handled = false) | 90 IPC_MESSAGE_UNHANDLED(handled = false) |
| 90 IPC_END_MESSAGE_MAP() | 91 IPC_END_MESSAGE_MAP() |
| 91 DCHECK(handled) << "Unhandled message:" << msg.type(); | 92 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { | |
| 95 return thread_safe_sender_->Send(msg); | |
| 96 } | |
| 97 | |
| 98 void ServiceWorkerDispatcher::RegisterServiceWorker( | 95 void ServiceWorkerDispatcher::RegisterServiceWorker( |
| 99 int provider_id, | 96 int provider_id, |
| 100 const GURL& pattern, | 97 const GURL& pattern, |
| 101 const GURL& script_url, | 98 const GURL& script_url, |
| 102 WebServiceWorkerRegistrationCallbacks* callbacks) { | 99 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 103 DCHECK(callbacks); | 100 DCHECK(callbacks); |
| 104 | 101 |
| 105 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || | 102 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || |
| 106 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 103 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 107 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 104 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
| 108 owned_callbacks(callbacks); | 105 owned_callbacks(callbacks); |
| 109 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 106 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
| 110 error_message += "The provided scriptURL or scope is too long."; | 107 error_message += "The provided scriptURL or scope is too long."; |
| 111 scoped_ptr<WebServiceWorkerError> error( | 108 scoped_ptr<WebServiceWorkerError> error( |
| 112 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 109 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 113 blink::WebString::fromUTF8(error_message))); | 110 blink::WebString::fromUTF8(error_message))); |
| 114 callbacks->onError(error.release()); | 111 callbacks->onError(error.release()); |
| 115 return; | 112 return; |
| 116 } | 113 } |
| 117 | 114 |
| 118 int request_id = pending_registration_callbacks_.Add(callbacks); | 115 int request_id = pending_registration_callbacks_.Add(callbacks); |
| 119 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 116 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
| 120 "ServiceWorkerDispatcher::RegisterServiceWorker", | 117 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 121 request_id, | 118 request_id, |
| 122 "Scope", pattern.spec(), | 119 "Scope", pattern.spec(), |
| 123 "Script URL", script_url.spec()); | 120 "Script URL", script_url.spec()); |
| 124 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 121 sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
| 125 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 122 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
| 126 } | 123 } |
| 127 | 124 |
| 128 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 125 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| 129 int provider_id, | 126 int provider_id, |
| 130 const GURL& pattern, | 127 const GURL& pattern, |
| 131 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 128 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
| 132 DCHECK(callbacks); | 129 DCHECK(callbacks); |
| 133 | 130 |
| 134 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | 131 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 135 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> | 132 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> |
| 136 owned_callbacks(callbacks); | 133 owned_callbacks(callbacks); |
| 137 std::string error_message(kServiceWorkerUnregisterErrorPrefix); | 134 std::string error_message(kServiceWorkerUnregisterErrorPrefix); |
| 138 error_message += "The provided scope is too long."; | 135 error_message += "The provided scope is too long."; |
| 139 scoped_ptr<WebServiceWorkerError> error( | 136 scoped_ptr<WebServiceWorkerError> error( |
| 140 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 137 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 141 blink::WebString::fromUTF8(error_message))); | 138 blink::WebString::fromUTF8(error_message))); |
| 142 callbacks->onError(error.release()); | 139 callbacks->onError(error.release()); |
| 143 return; | 140 return; |
| 144 } | 141 } |
| 145 | 142 |
| 146 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 143 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
| 147 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 144 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 148 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 145 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 149 request_id, | 146 request_id, |
| 150 "Scope", pattern.spec()); | 147 "Scope", pattern.spec()); |
| 151 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 148 sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
| 152 CurrentWorkerId(), request_id, provider_id, pattern)); | 149 CurrentWorkerId(), request_id, provider_id, pattern)); |
| 153 } | 150 } |
| 154 | 151 |
| 155 void ServiceWorkerDispatcher::GetRegistration( | 152 void ServiceWorkerDispatcher::GetRegistration( |
| 156 int provider_id, | 153 int provider_id, |
| 157 const GURL& document_url, | 154 const GURL& document_url, |
| 158 WebServiceWorkerRegistrationCallbacks* callbacks) { | 155 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 159 DCHECK(callbacks); | 156 DCHECK(callbacks); |
| 160 | 157 |
| 161 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 158 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 162 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 159 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
| 163 owned_callbacks(callbacks); | 160 owned_callbacks(callbacks); |
| 164 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 161 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
| 165 error_message += "The provided documentURL is too long."; | 162 error_message += "The provided documentURL is too long."; |
| 166 scoped_ptr<WebServiceWorkerError> error( | 163 scoped_ptr<WebServiceWorkerError> error( |
| 167 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 164 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 168 blink::WebString::fromUTF8(error_message))); | 165 blink::WebString::fromUTF8(error_message))); |
| 169 callbacks->onError(error.release()); | 166 callbacks->onError(error.release()); |
| 170 return; | 167 return; |
| 171 } | 168 } |
| 172 | 169 |
| 173 int request_id = pending_get_registration_callbacks_.Add(callbacks); | 170 int request_id = pending_get_registration_callbacks_.Add(callbacks); |
| 174 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 171 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 175 "ServiceWorkerDispatcher::GetRegistration", | 172 "ServiceWorkerDispatcher::GetRegistration", |
| 176 request_id, | 173 request_id, |
| 177 "Document URL", document_url.spec()); | 174 "Document URL", document_url.spec()); |
| 178 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 175 sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
| 179 CurrentWorkerId(), request_id, provider_id, document_url)); | 176 CurrentWorkerId(), request_id, provider_id, document_url)); |
| 180 } | 177 } |
| 181 | 178 |
| 182 void ServiceWorkerDispatcher::GetRegistrationForReady( | 179 void ServiceWorkerDispatcher::GetRegistrationForReady( |
| 183 int provider_id, | 180 int provider_id, |
| 184 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { | 181 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { |
| 185 int request_id = get_for_ready_callbacks_.Add(callbacks); | 182 int request_id = get_for_ready_callbacks_.Add(callbacks); |
| 186 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 183 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 187 "ServiceWorkerDispatcher::GetRegistrationForReady", | 184 "ServiceWorkerDispatcher::GetRegistrationForReady", |
| 188 request_id); | 185 request_id); |
| 189 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( | 186 sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( |
| 190 CurrentWorkerId(), request_id, provider_id)); | 187 CurrentWorkerId(), request_id, provider_id)); |
| 191 } | 188 } |
| 192 | 189 |
| 193 void ServiceWorkerDispatcher::AddProviderContext( | 190 void ServiceWorkerDispatcher::AddProviderContext( |
| 194 ServiceWorkerProviderContext* provider_context) { | 191 ServiceWorkerProviderContext* provider_context) { |
| 195 DCHECK(provider_context); | 192 DCHECK(provider_context); |
| 196 int provider_id = provider_context->provider_id(); | 193 int provider_id = provider_context->provider_id(); |
| 197 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 194 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
| 198 provider_contexts_[provider_id] = provider_context; | 195 provider_contexts_[provider_id] = provider_context; |
| 199 } | 196 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 } | 215 } |
| 219 | 216 |
| 220 void ServiceWorkerDispatcher::RemoveProviderClient(int provider_id) { | 217 void ServiceWorkerDispatcher::RemoveProviderClient(int provider_id) { |
| 221 // This could be possibly called multiple times to ensure termination. | 218 // This could be possibly called multiple times to ensure termination. |
| 222 if (ContainsKey(provider_clients_, provider_id)) | 219 if (ContainsKey(provider_clients_, provider_id)) |
| 223 provider_clients_.erase(provider_id); | 220 provider_clients_.erase(provider_id); |
| 224 } | 221 } |
| 225 | 222 |
| 226 ServiceWorkerDispatcher* | 223 ServiceWorkerDispatcher* |
| 227 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 224 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 228 ThreadSafeSender* thread_safe_sender) { | 225 ServiceWorkerMessageSender* sender) { |
| 229 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { | 226 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) { |
| 230 NOTREACHED() << "Re-instantiating TLS ServiceWorkerDispatcher."; | 227 NOTREACHED() << "Re-instantiating TLS ServiceWorkerDispatcher."; |
| 231 g_dispatcher_tls.Pointer()->Set(NULL); | 228 g_dispatcher_tls.Pointer()->Set(NULL); |
| 232 } | 229 } |
| 233 if (g_dispatcher_tls.Pointer()->Get()) | 230 if (g_dispatcher_tls.Pointer()->Get()) |
| 234 return g_dispatcher_tls.Pointer()->Get(); | 231 return g_dispatcher_tls.Pointer()->Get(); |
| 235 | 232 |
| 236 ServiceWorkerDispatcher* dispatcher = | 233 ServiceWorkerDispatcher* dispatcher = |
| 237 new ServiceWorkerDispatcher(thread_safe_sender); | 234 new ServiceWorkerDispatcher(sender); |
| 238 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) | 235 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
| 239 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); | 236 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); |
| 240 return dispatcher; | 237 return dispatcher; |
| 241 } | 238 } |
| 242 | 239 |
| 243 ServiceWorkerDispatcher* ServiceWorkerDispatcher::GetThreadSpecificInstance() { | 240 ServiceWorkerDispatcher* ServiceWorkerDispatcher::GetThreadSpecificInstance() { |
| 244 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) | 241 if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) |
| 245 return NULL; | 242 return NULL; |
| 246 return g_dispatcher_tls.Pointer()->Get(); | 243 return g_dispatcher_tls.Pointer()->Get(); |
| 247 } | 244 } |
| 248 | 245 |
| 249 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { | 246 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { |
| 250 delete this; | 247 delete this; |
| 251 } | 248 } |
| 252 | 249 |
| 253 WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker( | 250 WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker( |
| 254 const ServiceWorkerObjectInfo& info, | 251 const ServiceWorkerObjectInfo& info, |
| 255 bool adopt_handle) { | 252 bool adopt_handle) { |
| 256 if (info.handle_id == kInvalidServiceWorkerHandleId) | 253 if (info.handle_id == kInvalidServiceWorkerHandleId) |
| 257 return NULL; | 254 return NULL; |
| 258 | 255 |
| 259 WorkerObjectMap::iterator existing_worker = | 256 WorkerObjectMap::iterator existing_worker = |
| 260 service_workers_.find(info.handle_id); | 257 service_workers_.find(info.handle_id); |
| 261 | 258 |
| 262 if (existing_worker != service_workers_.end()) { | 259 if (existing_worker != service_workers_.end()) { |
| 263 if (adopt_handle) { | 260 if (adopt_handle) { |
| 264 // We are instructed to adopt a handle but we already have one, so | 261 // We are instructed to adopt a handle but we already have one, so |
| 265 // adopt and destroy a handle ref. | 262 // adopt and destroy a handle ref. |
| 266 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 263 ServiceWorkerHandleReference::Adopt(info, sender_.get()); |
| 267 } | 264 } |
| 268 return existing_worker->second; | 265 return existing_worker->second; |
| 269 } | 266 } |
| 270 | 267 |
| 271 scoped_ptr<ServiceWorkerHandleReference> handle_ref = | 268 scoped_ptr<ServiceWorkerHandleReference> handle_ref = |
| 272 adopt_handle | 269 adopt_handle |
| 273 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()) | 270 ? ServiceWorkerHandleReference::Adopt(info, sender_.get()) |
| 274 : ServiceWorkerHandleReference::Create(info, | 271 : ServiceWorkerHandleReference::Create(info, sender_.get()); |
| 275 thread_safe_sender_.get()); | |
| 276 // WebServiceWorkerImpl constructor calls AddServiceWorker. | 272 // WebServiceWorkerImpl constructor calls AddServiceWorker. |
| 277 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_.get()); | 273 return new WebServiceWorkerImpl(handle_ref.Pass(), sender_.get()); |
| 278 } | 274 } |
| 279 | 275 |
| 280 WebServiceWorkerRegistrationImpl* | 276 WebServiceWorkerRegistrationImpl* |
| 281 ServiceWorkerDispatcher::FindServiceWorkerRegistration( | 277 ServiceWorkerDispatcher::FindServiceWorkerRegistration( |
| 282 const ServiceWorkerRegistrationObjectInfo& info, | 278 const ServiceWorkerRegistrationObjectInfo& info, |
| 283 bool adopt_handle) { | 279 bool adopt_handle) { |
| 284 RegistrationObjectMap::iterator registration = | 280 RegistrationObjectMap::iterator registration = |
| 285 registrations_.find(info.handle_id); | 281 registrations_.find(info.handle_id); |
| 286 if (registration == registrations_.end()) | 282 if (registration == registrations_.end()) |
| 287 return NULL; | 283 return NULL; |
| 288 if (adopt_handle) { | 284 if (adopt_handle) { |
| 289 // We are instructed to adopt a handle but we already have one, so | 285 // We are instructed to adopt a handle but we already have one, so |
| 290 // adopt and destroy a handle ref. | 286 // adopt and destroy a handle ref. |
| 291 ServiceWorkerRegistrationHandleReference::Adopt( | 287 ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get()); |
| 292 info, thread_safe_sender_.get()); | |
| 293 } | 288 } |
| 294 return registration->second; | 289 return registration->second; |
| 295 } | 290 } |
| 296 | 291 |
| 297 WebServiceWorkerRegistrationImpl* | 292 WebServiceWorkerRegistrationImpl* |
| 298 ServiceWorkerDispatcher::CreateServiceWorkerRegistration( | 293 ServiceWorkerDispatcher::CreateServiceWorkerRegistration( |
| 299 const ServiceWorkerRegistrationObjectInfo& info, | 294 const ServiceWorkerRegistrationObjectInfo& info, |
| 300 bool adopt_handle) { | 295 bool adopt_handle) { |
| 301 DCHECK(!FindServiceWorkerRegistration(info, adopt_handle)); | 296 DCHECK(!FindServiceWorkerRegistration(info, adopt_handle)); |
| 302 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) | 297 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) |
| 303 return NULL; | 298 return NULL; |
| 304 | 299 |
| 305 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = | 300 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = |
| 306 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( | 301 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( |
| 307 info, thread_safe_sender_.get()) | 302 info, sender_.get()) |
| 308 : ServiceWorkerRegistrationHandleReference::Create( | 303 : ServiceWorkerRegistrationHandleReference::Create( |
| 309 info, thread_safe_sender_.get()); | 304 info, sender_.get()); |
| 310 | 305 |
| 311 // WebServiceWorkerRegistrationImpl constructor calls | 306 // WebServiceWorkerRegistrationImpl constructor calls |
| 312 // AddServiceWorkerRegistration. | 307 // AddServiceWorkerRegistration. |
| 313 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); | 308 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); |
| 314 } | 309 } |
| 315 | 310 |
| 316 // We can assume that this message handler is called before the worker context | 311 // We can assume that this message handler is called before the worker context |
| 317 // starts because script loading happens after this association. | 312 // starts because script loading happens after this association. |
| 318 // TODO(nhiroki): This association information could be pushed into | 313 // TODO(nhiroki): This association information could be pushed into |
| 319 // EmbeddedWorkerMsg_StartWorker message and handed over to the worker thread | 314 // EmbeddedWorkerMsg_StartWorker message and handed over to the worker thread |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 WebServiceWorkerRegistrationImpl* registration = | 686 WebServiceWorkerRegistrationImpl* registration = |
| 692 FindServiceWorkerRegistration(info, true); | 687 FindServiceWorkerRegistration(info, true); |
| 693 if (!registration) { | 688 if (!registration) { |
| 694 registration = CreateServiceWorkerRegistration(info, true); | 689 registration = CreateServiceWorkerRegistration(info, true); |
| 695 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); | 690 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); |
| 696 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); | 691 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); |
| 697 registration->SetActive(GetServiceWorker(attrs.active, true)); | 692 registration->SetActive(GetServiceWorker(attrs.active, true)); |
| 698 } else { | 693 } else { |
| 699 // |registration| must already have version attributes, so adopt and destroy | 694 // |registration| must already have version attributes, so adopt and destroy |
| 700 // handle refs for them. | 695 // handle refs for them. |
| 701 ServiceWorkerHandleReference::Adopt( | 696 ServiceWorkerHandleReference::Adopt(attrs.installing, sender_.get()); |
| 702 attrs.installing, thread_safe_sender_.get()); | 697 ServiceWorkerHandleReference::Adopt(attrs.waiting, sender_.get()); |
| 703 ServiceWorkerHandleReference::Adopt( | 698 ServiceWorkerHandleReference::Adopt(attrs.active, sender_.get()); |
| 704 attrs.waiting, thread_safe_sender_.get()); | |
| 705 ServiceWorkerHandleReference::Adopt( | |
| 706 attrs.active, thread_safe_sender_.get()); | |
| 707 } | 699 } |
| 708 return registration; | 700 return registration; |
| 709 } | 701 } |
| 710 | 702 |
| 711 } // namespace content | 703 } // namespace content |
| OLD | NEW |