Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: chrome/worker/worker_thread.cc

Issue 155944: Switch the first thread in a child process to be the main thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 7 #include "base/lazy_instance.h"
8 #include "base/thread_local.h" 8 #include "base/thread_local.h"
9 #include "chrome/common/worker_messages.h" 9 #include "chrome/common/worker_messages.h"
10 #include "chrome/worker/webworkerclient_proxy.h" 10 #include "chrome/worker/webworkerclient_proxy.h"
11 #include "chrome/worker/worker_webkitclient_impl.h" 11 #include "chrome/worker/worker_webkitclient_impl.h"
12 #include "webkit/api/public/WebKit.h" 12 #include "webkit/api/public/WebKit.h"
13 13
14 static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( 14 static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls(
15 base::LINKER_INITIALIZED); 15 base::LINKER_INITIALIZED);
16 16
17 17
18 WorkerThread::WorkerThread() 18 WorkerThread::WorkerThread() {
19 : ChildThread(base::Thread::Options(MessageLoop::TYPE_DEFAULT, 19 lazy_tls.Pointer()->Set(this);
20 kV8StackSize)) { 20 webkit_client_.reset(new WorkerWebKitClientImpl);
21 WebKit::initialize(webkit_client_.get());
21 } 22 }
22 23
23 WorkerThread::~WorkerThread() { 24 WorkerThread::~WorkerThread() {
25 // Shutdown in reverse of the initialization order.
26 WebKit::shutdown();
27 lazy_tls.Pointer()->Set(NULL);
24 } 28 }
25 29
26 WorkerThread* WorkerThread::current() { 30 WorkerThread* WorkerThread::current() {
27 return lazy_tls.Pointer()->Get(); 31 return lazy_tls.Pointer()->Get();
28 } 32 }
29 33
30 void WorkerThread::Init() {
31 lazy_tls.Pointer()->Set(this);
32 ChildThread::Init();
33 webkit_client_.reset(new WorkerWebKitClientImpl);
34 WebKit::initialize(webkit_client_.get());
35 }
36
37 void WorkerThread::CleanUp() {
38 // Shutdown in reverse of the initialization order.
39
40 if (webkit_client_.get()) {
41 WebKit::shutdown();
42 webkit_client_.reset();
43 }
44
45 ChildThread::CleanUp();
46 lazy_tls.Pointer()->Set(NULL);
47 }
48
49 void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { 34 void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) {
50 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg) 35 IPC_BEGIN_MESSAGE_MAP(WorkerThread, msg)
51 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker) 36 IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateWorker)
52 IPC_END_MESSAGE_MAP() 37 IPC_END_MESSAGE_MAP()
53 } 38 }
54 39
55 void WorkerThread::OnCreateWorker(const GURL& url, int route_id) { 40 void WorkerThread::OnCreateWorker(const GURL& url, int route_id) {
56 // WebWorkerClientProxy owns itself. 41 // WebWorkerClientProxy owns itself.
57 new WebWorkerClientProxy(url, route_id); 42 new WebWorkerClientProxy(url, route_id);
58 } 43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698