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/renderer/service_worker/embedded_worker_context_client.h" | 5 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 worker_task_runner_ = new WorkerThreadTaskRunner( | 173 worker_task_runner_ = new WorkerThreadTaskRunner( |
174 WorkerTaskRunner::Instance()->CurrentWorkerId()); | 174 WorkerTaskRunner::Instance()->CurrentWorkerId()); |
175 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | 175 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); |
176 // g_worker_client_tls.Pointer()->Get() could return NULL if this context | 176 // g_worker_client_tls.Pointer()->Get() could return NULL if this context |
177 // gets deleted before workerContextStarted() is called. | 177 // gets deleted before workerContextStarted() is called. |
178 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 178 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
179 DCHECK(!script_context_); | 179 DCHECK(!script_context_); |
180 g_worker_client_tls.Pointer()->Set(this); | 180 g_worker_client_tls.Pointer()->Set(this); |
181 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); | 181 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); |
182 | 182 |
183 // This can be nullptr on EmbeddedWorkerBrowserTests. | 183 // This can be false on EmbeddedWorkerBrowserTests. |
184 // TODO(nhiroki): Remove this workaround. |registration()| should always be | 184 // TODO(nhiroki): Remove this workaround. |IsAssociatedWithRegistration()| |
185 // valid other than the test because the registration association message | 185 // should always return true other than the test because the registration |
186 // arrives before starting the worker context. | 186 // association message arrives before starting the worker context. |
187 if (provider_context_->registration()) | 187 if (provider_context_->IsAssociatedWithRegistration()) |
188 SetRegistrationInServiceWorkerGlobalScope(); | 188 SetRegistrationInServiceWorkerGlobalScope(); |
189 | 189 |
190 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( | 190 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( |
191 embedded_worker_id_, | 191 embedded_worker_id_, |
192 WorkerTaskRunner::Instance()->CurrentWorkerId())); | 192 WorkerTaskRunner::Instance()->CurrentWorkerId())); |
193 | 193 |
194 // Schedule a task to send back WorkerStarted asynchronously, | 194 // Schedule a task to send back WorkerStarted asynchronously, |
195 // so that at the time we send it we can be sure that the worker | 195 // so that at the time we send it we can be sure that the worker |
196 // script has been evaluated and worker run loop has been started. | 196 // script has been evaluated and worker run loop has been started. |
197 worker_task_runner_->PostTask( | 197 worker_task_runner_->PostTask( |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 416 |
417 void EmbeddedWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope() { | 417 void EmbeddedWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope() { |
418 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 418 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
419 DCHECK(provider_context_); | 419 DCHECK(provider_context_); |
420 DCHECK(script_context_); | 420 DCHECK(script_context_); |
421 | 421 |
422 ServiceWorkerDispatcher* dispatcher = | 422 ServiceWorkerDispatcher* dispatcher = |
423 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 423 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
424 thread_safe_sender()); | 424 thread_safe_sender()); |
425 | 425 |
426 // Register a registration with the dispatcher living on the worker thread. | 426 ServiceWorkerRegistrationObjectInfo info; |
427 DCHECK(provider_context_->registration()); | 427 ServiceWorkerVersionAttributes attrs; |
428 provider_context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs); | |
429 | |
430 // Register a registrationi and its version attributes with the dispatcher | |
nhiroki
2015/01/28 05:54:58
registrationi -> registration
I'll fix this later
nhiroki
2015/01/28 07:42:27
Done.
| |
431 // living on the worker thread. | |
428 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( | 432 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( |
429 dispatcher->CreateServiceWorkerRegistration( | 433 dispatcher->CreateServiceWorkerRegistration(info, false)); |
430 provider_context_->registration()->info(), false)); | |
431 | |
432 // Register workers with the dispatcher living on the worker thread. | |
433 ServiceWorkerVersionAttributes attrs = | |
434 provider_context_->GetVersionAttributes(); | |
435 registration->SetInstalling( | 434 registration->SetInstalling( |
436 dispatcher->GetServiceWorker(attrs.installing, false)); | 435 dispatcher->GetServiceWorker(attrs.installing, false)); |
437 registration->SetWaiting( | 436 registration->SetWaiting( |
438 dispatcher->GetServiceWorker(attrs.waiting, false)); | 437 dispatcher->GetServiceWorker(attrs.waiting, false)); |
439 registration->SetActive( | 438 registration->SetActive( |
440 dispatcher->GetServiceWorker(attrs.active, false)); | 439 dispatcher->GetServiceWorker(attrs.active, false)); |
441 | 440 |
442 script_context_->SetRegistrationInServiceWorkerGlobalScope( | 441 script_context_->SetRegistrationInServiceWorkerGlobalScope( |
443 registration.Pass()); | 442 registration.Pass()); |
444 } | 443 } |
445 | 444 |
446 } // namespace content | 445 } // namespace content |
OLD | NEW |