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/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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 g_worker_client_tls.Pointer()->Set(this); | 201 g_worker_client_tls.Pointer()->Set(this); |
| 202 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); | 202 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); |
| 203 | 203 |
| 204 SetRegistrationInServiceWorkerGlobalScope(); | 204 SetRegistrationInServiceWorkerGlobalScope(); |
| 205 | 205 |
| 206 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( | 206 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( |
| 207 embedded_worker_id_, | 207 embedded_worker_id_, |
| 208 WorkerTaskRunner::Instance()->CurrentWorkerId(), | 208 WorkerTaskRunner::Instance()->CurrentWorkerId(), |
| 209 provider_context_->provider_id())); | 209 provider_context_->provider_id())); |
| 210 | 210 |
| 211 // Schedule a task to send back WorkerStarted asynchronously, | |
| 212 // so that at the time we send it we can be sure that the worker | |
| 213 // script has been evaluated and worker run loop has been started. | |
| 214 worker_task_runner_->PostTask( | |
| 215 FROM_HERE, | |
| 216 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, | |
| 217 weak_factory_.GetWeakPtr())); | |
| 218 TRACE_EVENT_ASYNC_STEP_INTO0( | 211 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 219 "ServiceWorker", | 212 "ServiceWorker", |
| 220 "EmbeddedWorkerContextClient::StartingWorkerContext", | 213 "EmbeddedWorkerContextClient::StartingWorkerContext", |
| 221 this, | 214 this, |
| 222 "ExecuteScript"); | 215 "ExecuteScript"); |
| 223 } | 216 } |
| 224 | 217 |
| 225 void EmbeddedWorkerContextClient::didEvaluateWorkerScript(bool success) { | 218 void EmbeddedWorkerContextClient::didEvaluateWorkerScript(bool success) { |
| 226 Send(new EmbeddedWorkerHostMsg_WorkerScriptEvaluated( | 219 Send(new EmbeddedWorkerHostMsg_WorkerScriptEvaluated( |
| 227 embedded_worker_id_, success)); | 220 embedded_worker_id_, success)); |
| 221 | |
| 222 // Schedule a task to send back WorkerStarted asynchronously, | |
| 223 // so that at the time we send it we can be sure that the | |
| 224 // worker run loop has been started. | |
| 225 worker_task_runner_->PostTask( | |
| 226 FROM_HERE, base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, | |
| 227 weak_factory_.GetWeakPtr())); | |
|
kinuko
2015/03/02 03:19:33
Did you need to move this method? Could you explai
falken
2015/03/02 04:19:17
It's just a cleanup. It was pretty confusing to re
kinuko
2015/03/02 06:13:19
I see. We probably don't need to call the SendWork
falken
2015/03/02 06:33:16
Yes I think the only reason we'd send async is if
| |
| 228 } | 228 } |
| 229 | 229 |
| 230 void EmbeddedWorkerContextClient::willDestroyWorkerContext() { | 230 void EmbeddedWorkerContextClient::willDestroyWorkerContext() { |
| 231 // At this point OnWorkerRunLoopStopped is already called, so | 231 // At this point OnWorkerRunLoopStopped is already called, so |
| 232 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 232 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
| 233 // (while we're still on the worker thread). | 233 // (while we're still on the worker thread). |
| 234 script_context_.reset(); | 234 script_context_.reset(); |
| 235 | 235 |
| 236 // This also lets the message filter stop dispatching messages to | 236 // This also lets the message filter stop dispatching messages to |
| 237 // this client. | 237 // this client. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 registration->SetWaiting( | 467 registration->SetWaiting( |
| 468 dispatcher->GetServiceWorker(attrs.waiting, false)); | 468 dispatcher->GetServiceWorker(attrs.waiting, false)); |
| 469 registration->SetActive( | 469 registration->SetActive( |
| 470 dispatcher->GetServiceWorker(attrs.active, false)); | 470 dispatcher->GetServiceWorker(attrs.active, false)); |
| 471 | 471 |
| 472 script_context_->SetRegistrationInServiceWorkerGlobalScope( | 472 script_context_->SetRegistrationInServiceWorkerGlobalScope( |
| 473 registration.Pass()); | 473 registration.Pass()); |
| 474 } | 474 } |
| 475 | 475 |
| 476 } // namespace content | 476 } // namespace content |
| OLD | NEW |