OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/worker/worker_thread.h" | 5 #include "chrome/worker/worker_thread.h" |
6 | 6 |
| 7 #include "base/lazy_instance.h" |
| 8 #include "base/thread_local.h" |
7 #include "chrome/common/worker_messages.h" | 9 #include "chrome/common/worker_messages.h" |
8 #include "chrome/worker/webworkerclient_proxy.h" | 10 #include "chrome/worker/webworkerclient_proxy.h" |
9 #include "chrome/worker/worker_webkitclient_impl.h" | 11 #include "chrome/worker/worker_webkitclient_impl.h" |
10 #include "webkit/api/public/WebKit.h" | 12 #include "webkit/api/public/WebKit.h" |
11 | 13 |
| 14 static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( |
| 15 base::LINKER_INITIALIZED); |
| 16 |
| 17 |
12 WorkerThread::WorkerThread() | 18 WorkerThread::WorkerThread() |
13 : ChildThread(base::Thread::Options(MessageLoop::TYPE_DEFAULT, | 19 : ChildThread(base::Thread::Options(MessageLoop::TYPE_DEFAULT, |
14 kV8StackSize)) { | 20 kV8StackSize)) { |
15 } | 21 } |
16 | 22 |
17 WorkerThread::~WorkerThread() { | 23 WorkerThread::~WorkerThread() { |
18 } | 24 } |
19 | 25 |
| 26 WorkerThread* WorkerThread::current() { |
| 27 return lazy_tls.Pointer()->Get(); |
| 28 } |
| 29 |
20 void WorkerThread::Init() { | 30 void WorkerThread::Init() { |
| 31 lazy_tls.Pointer()->Set(this); |
21 ChildThread::Init(); | 32 ChildThread::Init(); |
22 webkit_client_.reset(new WorkerWebKitClientImpl); | 33 webkit_client_.reset(new WorkerWebKitClientImpl); |
23 WebKit::initialize(webkit_client_.get()); | 34 WebKit::initialize(webkit_client_.get()); |
24 | 35 |
25 // Enable the worker so that the nested worker can be created. | 36 // Enable the worker so that the nested worker can be created. |
26 WebKit::enableWebWorkers(); | 37 WebKit::enableWebWorkers(); |
27 } | 38 } |
28 | 39 |
29 void WorkerThread::CleanUp() { | 40 void WorkerThread::CleanUp() { |
30 // Shutdown in reverse of the initialization order. | 41 // Shutdown in reverse of the initialization order. |
31 | 42 |
32 if (webkit_client_.get()) { | 43 if (webkit_client_.get()) { |
33 WebKit::shutdown(); | 44 WebKit::shutdown(); |
34 webkit_client_.reset(); | 45 webkit_client_.reset(); |
35 } | 46 } |
36 | 47 |
37 ChildThread::CleanUp(); | 48 ChildThread::CleanUp(); |
| 49 lazy_tls.Pointer()->Set(NULL); |
38 } | 50 } |
39 | 51 |
40 void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { | 52 void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { |
41 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) | 53 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) |
42 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) | 54 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) |
43 IPC_END_MESSAGE_MAP() | 55 IPC_END_MESSAGE_MAP() |
44 } | 56 } |
45 | 57 |
46 void WorkerThread::OnCreateWorker(const GURL& url, int route_id) { | 58 void WorkerThread::OnCreateWorker(const GURL& url, int route_id) { |
47 // WebWorkerClientProxy owns itself. | 59 // WebWorkerClientProxy owns itself. |
48 WebWorkerClientProxy* worker = new WebWorkerClientProxy(url, route_id); | 60 WebWorkerClientProxy* worker = new WebWorkerClientProxy(url, route_id); |
49 } | 61 } |
OLD | NEW |