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/debug/trace_event.h" | |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/pickle.h" | 13 #include "base/pickle.h" |
| 13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
| 16 #include "content/child/request_extra_data.h" | 17 #include "content/child/request_extra_data.h" |
| 17 #include "content/child/service_worker/service_worker_network_provider.h" | 18 #include "content/child/service_worker/service_worker_network_provider.h" |
| 18 #include "content/child/thread_safe_sender.h" | 19 #include "content/child/thread_safe_sender.h" |
| 19 #include "content/child/worker_task_runner.h" | 20 #include "content/child/worker_task_runner.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 const GURL& script_url, | 93 const GURL& script_url, |
| 93 int worker_devtools_agent_route_id) | 94 int worker_devtools_agent_route_id) |
| 94 : embedded_worker_id_(embedded_worker_id), | 95 : embedded_worker_id_(embedded_worker_id), |
| 95 service_worker_version_id_(service_worker_version_id), | 96 service_worker_version_id_(service_worker_version_id), |
| 96 service_worker_scope_(service_worker_scope), | 97 service_worker_scope_(service_worker_scope), |
| 97 script_url_(script_url), | 98 script_url_(script_url), |
| 98 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), | 99 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), |
| 99 sender_(ChildThread::current()->thread_safe_sender()), | 100 sender_(ChildThread::current()->thread_safe_sender()), |
| 100 main_thread_proxy_(base::MessageLoopProxy::current()), | 101 main_thread_proxy_(base::MessageLoopProxy::current()), |
| 101 weak_factory_(this) { | 102 weak_factory_(this) { |
| 103 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | |
| 104 "EmbeddedWorkerContextClient", | |
| 105 this, | |
| 106 "Info", | |
| 107 "Major component are the load time of SW script " | |
|
horo
2014/09/05 11:02:32
I think we don't need this info.
shimazu
2014/09/08 07:04:46
Done.
| |
| 108 "and preparation of execution environments."); | |
| 109 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | |
| 110 "EmbeddedWorkerContextClient", | |
| 111 this, | |
| 112 "PrepareWorker"); | |
| 102 } | 113 } |
| 103 | 114 |
| 104 EmbeddedWorkerContextClient::~EmbeddedWorkerContextClient() { | 115 EmbeddedWorkerContextClient::~EmbeddedWorkerContextClient() { |
| 105 } | 116 } |
| 106 | 117 |
| 107 bool EmbeddedWorkerContextClient::OnMessageReceived( | 118 bool EmbeddedWorkerContextClient::OnMessageReceived( |
| 108 const IPC::Message& msg) { | 119 const IPC::Message& msg) { |
| 109 bool handled = true; | 120 bool handled = true; |
| 110 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerContextClient, msg) | 121 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerContextClient, msg) |
| 111 IPC_MESSAGE_HANDLER(EmbeddedWorkerContextMsg_MessageToWorker, | 122 IPC_MESSAGE_HANDLER(EmbeddedWorkerContextMsg_MessageToWorker, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 embedded_worker_id_, | 180 embedded_worker_id_, |
| 170 WorkerTaskRunner::Instance()->CurrentWorkerId())); | 181 WorkerTaskRunner::Instance()->CurrentWorkerId())); |
| 171 | 182 |
| 172 // Schedule a task to send back WorkerStarted asynchronously, | 183 // Schedule a task to send back WorkerStarted asynchronously, |
| 173 // so that at the time we send it we can be sure that the worker | 184 // so that at the time we send it we can be sure that the worker |
| 174 // script has been evaluated and worker run loop has been started. | 185 // script has been evaluated and worker run loop has been started. |
| 175 worker_task_runner_->PostTask( | 186 worker_task_runner_->PostTask( |
| 176 FROM_HERE, | 187 FROM_HERE, |
| 177 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, | 188 base::Bind(&EmbeddedWorkerContextClient::SendWorkerStarted, |
| 178 weak_factory_.GetWeakPtr())); | 189 weak_factory_.GetWeakPtr())); |
| 190 TRACE_EVENT_ASYNC_STEP_INTO1( | |
| 191 "ServiceWorker", | |
| 192 "EmbeddedWorkerContextClient", | |
| 193 this, | |
| 194 "ExecuteScript", | |
| 195 "Info", "Major component is the execution time of SW script."); | |
|
horo
2014/09/05 11:02:32
I think we don't need this info.
shimazu
2014/09/08 07:04:46
Done.
| |
| 179 } | 196 } |
| 180 | 197 |
| 181 void EmbeddedWorkerContextClient::willDestroyWorkerContext() { | 198 void EmbeddedWorkerContextClient::willDestroyWorkerContext() { |
| 182 // At this point OnWorkerRunLoopStopped is already called, so | 199 // At this point OnWorkerRunLoopStopped is already called, so |
| 183 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 200 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
| 184 // (while we're still on the worker thread). | 201 // (while we're still on the worker thread). |
| 185 script_context_.reset(); | 202 script_context_.reset(); |
| 186 | 203 |
| 187 // This also lets the message filter stop dispatching messages to | 204 // This also lets the message filter stop dispatching messages to |
| 188 // this client. | 205 // this client. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 int embedded_worker_id, | 340 int embedded_worker_id, |
| 324 const IPC::Message& message) { | 341 const IPC::Message& message) { |
| 325 if (!script_context_) | 342 if (!script_context_) |
| 326 return; | 343 return; |
| 327 DCHECK_EQ(embedded_worker_id_, embedded_worker_id); | 344 DCHECK_EQ(embedded_worker_id_, embedded_worker_id); |
| 328 script_context_->OnMessageReceived(message); | 345 script_context_->OnMessageReceived(message); |
| 329 } | 346 } |
| 330 | 347 |
| 331 void EmbeddedWorkerContextClient::SendWorkerStarted() { | 348 void EmbeddedWorkerContextClient::SendWorkerStarted() { |
| 332 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 349 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 350 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
| 351 "EmbeddedWorkerContextClient", | |
|
horo
2014/09/05 11:02:32
EmbeddedWorkerContextClien will keep alive after t
shimazu
2014/09/08 07:04:46
I think this should contain the class name for und
| |
| 352 this); | |
| 333 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); | 353 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); |
| 334 } | 354 } |
| 335 | 355 |
| 336 } // namespace content | 356 } // namespace content |
| OLD | NEW |