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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void EmbeddedWorkerContextClient::getClients( | 124 void EmbeddedWorkerContextClient::getClients( |
125 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 125 blink::WebServiceWorkerClientsCallbacks* callbacks) { |
126 DCHECK(script_context_); | 126 DCHECK(script_context_); |
127 script_context_->GetClientDocuments(callbacks); | 127 script_context_->GetClientDocuments(callbacks); |
128 } | 128 } |
129 | 129 |
130 void EmbeddedWorkerContextClient::workerContextFailedToStart() { | 130 void EmbeddedWorkerContextClient::workerContextFailedToStart() { |
131 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); | 131 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); |
132 DCHECK(!script_context_); | 132 DCHECK(!script_context_); |
133 | 133 |
| 134 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoadFailed(embedded_worker_id_)); |
| 135 |
134 RenderThreadImpl::current()->embedded_worker_dispatcher()-> | 136 RenderThreadImpl::current()->embedded_worker_dispatcher()-> |
135 WorkerContextDestroyed(embedded_worker_id_); | 137 WorkerContextDestroyed(embedded_worker_id_); |
136 } | 138 } |
137 | 139 |
138 void EmbeddedWorkerContextClient::workerContextStarted( | 140 void EmbeddedWorkerContextClient::workerContextStarted( |
139 blink::WebServiceWorkerContextProxy* proxy) { | 141 blink::WebServiceWorkerContextProxy* proxy) { |
140 DCHECK(!worker_task_runner_); | 142 DCHECK(!worker_task_runner_); |
141 worker_task_runner_ = new WorkerThreadTaskRunner( | 143 worker_task_runner_ = new WorkerThreadTaskRunner( |
142 WorkerTaskRunner::Instance()->CurrentWorkerId()); | 144 WorkerTaskRunner::Instance()->CurrentWorkerId()); |
143 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | 145 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); |
144 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 146 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
145 DCHECK(!script_context_); | 147 DCHECK(!script_context_); |
146 g_worker_client_tls.Pointer()->Set(this); | 148 g_worker_client_tls.Pointer()->Set(this); |
147 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); | 149 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); |
148 | 150 |
| 151 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded(embedded_worker_id_)); |
| 152 |
149 // Schedule a task to send back WorkerStarted asynchronously, | 153 // Schedule a task to send back WorkerStarted asynchronously, |
150 // so that at the time we send it we can be sure that the worker | 154 // so that at the time we send it we can be sure that the worker |
151 // script has been evaluated and worker run loop has been started. | 155 // script has been evaluated and worker run loop has been started. |
152 worker_task_runner_->PostTask( | 156 worker_task_runner_->PostTask( |
153 FROM_HERE, | 157 FROM_HERE, |
154 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, | 158 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, |
155 weak_factory_.GetWeakPtr())); | 159 weak_factory_.GetWeakPtr())); |
156 } | 160 } |
157 | 161 |
158 void EmbeddedWorkerContextClient::willDestroyWorkerContext() { | 162 void EmbeddedWorkerContextClient::willDestroyWorkerContext() { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 281 } |
278 | 282 |
279 void EmbeddedWorkerContextClient::SendWorkerStarted() { | 283 void EmbeddedWorkerContextClient::SendWorkerStarted() { |
280 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 284 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
281 Send(new EmbeddedWorkerHostMsg_WorkerStarted( | 285 Send(new EmbeddedWorkerHostMsg_WorkerStarted( |
282 WorkerTaskRunner::Instance()->CurrentWorkerId(), | 286 WorkerTaskRunner::Instance()->CurrentWorkerId(), |
283 embedded_worker_id_)); | 287 embedded_worker_id_)); |
284 } | 288 } |
285 | 289 |
286 } // namespace content | 290 } // namespace content |
OLD | NEW |