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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 worker_task_runner_ = new WorkerThreadTaskRunner( | 158 worker_task_runner_ = new WorkerThreadTaskRunner( |
159 WorkerTaskRunner::Instance()->CurrentWorkerId()); | 159 WorkerTaskRunner::Instance()->CurrentWorkerId()); |
160 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | 160 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); |
161 // g_worker_client_tls.Pointer()->Get() could return NULL if this context | 161 // g_worker_client_tls.Pointer()->Get() could return NULL if this context |
162 // gets deleted before workerContextStarted() is called. | 162 // gets deleted before workerContextStarted() is called. |
163 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 163 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
164 DCHECK(!script_context_); | 164 DCHECK(!script_context_); |
165 g_worker_client_tls.Pointer()->Set(this); | 165 g_worker_client_tls.Pointer()->Set(this); |
166 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); | 166 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); |
167 | 167 |
168 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded(embedded_worker_id_)); | 168 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( |
| 169 embedded_worker_id_, |
| 170 WorkerTaskRunner::Instance()->CurrentWorkerId())); |
169 | 171 |
170 // Schedule a task to send back WorkerStarted asynchronously, | 172 // Schedule a task to send back WorkerStarted asynchronously, |
171 // so that at the time we send it we can be sure that the worker | 173 // so that at the time we send it we can be sure that the worker |
172 // script has been evaluated and worker run loop has been started. | 174 // script has been evaluated and worker run loop has been started. |
173 worker_task_runner_->PostTask( | 175 worker_task_runner_->PostTask( |
174 FROM_HERE, | 176 FROM_HERE, |
175 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, | 177 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, |
176 weak_factory_.GetWeakPtr())); | 178 weak_factory_.GetWeakPtr())); |
177 } | 179 } |
178 | 180 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 int embedded_worker_id, | 323 int embedded_worker_id, |
322 const IPC::Message& message) { | 324 const IPC::Message& message) { |
323 if (!script_context_) | 325 if (!script_context_) |
324 return; | 326 return; |
325 DCHECK_EQ(embedded_worker_id_, embedded_worker_id); | 327 DCHECK_EQ(embedded_worker_id_, embedded_worker_id); |
326 script_context_->OnMessageReceived(message); | 328 script_context_->OnMessageReceived(message); |
327 } | 329 } |
328 | 330 |
329 void EmbeddedWorkerContextClient::SendWorkerStarted() { | 331 void EmbeddedWorkerContextClient::SendWorkerStarted() { |
330 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 332 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
331 Send(new EmbeddedWorkerHostMsg_WorkerStarted( | 333 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); |
332 WorkerTaskRunner::Instance()->CurrentWorkerId(), | |
333 embedded_worker_id_)); | |
334 } | 334 } |
335 | 335 |
336 } // namespace content | 336 } // namespace content |
OLD | NEW |