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