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

Side by Side Diff: chrome/browser/in_process_webkit/webkit_thread.cc

Issue 306032: Simplify threading in browser thread by making only ChromeThread deal with di... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a few more simplifications Created 11 years, 2 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. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/browser/in_process_webkit/webkit_thread.h" 5 #include "chrome/browser/in_process_webkit/webkit_thread.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/in_process_webkit/browser_webkitclient_impl.h" 8 #include "chrome/browser/in_process_webkit/browser_webkitclient_impl.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "webkit/api/public/WebKit.h" 10 #include "webkit/api/public/WebKit.h"
11 11
12 // This happens on the UI thread before the IO thread has been shut down. 12 // This happens on the UI thread before the IO thread has been shut down.
13 WebKitThread::WebKitThread() 13 WebKitThread::WebKitThread() {
14 : io_message_loop_(ChromeThread::GetMessageLoop(ChromeThread::IO)) {
15 // The thread is started lazily by InitializeThread() on the IO thread. 14 // The thread is started lazily by InitializeThread() on the IO thread.
16 } 15 }
17 16
18 // This happens on the UI thread after the IO thread has been shut down. 17 // This happens on the UI thread after the IO thread has been shut down.
19 WebKitThread::~WebKitThread() { 18 WebKitThread::~WebKitThread() {
20 // There's no good way to see if we're on the UI thread. 19 // We can't just check CurrentlyOn(ChromeThread::UI) because in unit tests,
20 // MessageLoop::Current is sometimes NULL and other times valid and there's
21 // no ChromeThread object. Can't check that CurrentlyOn is not IO since
22 // some unit tests set that ChromeThread for other checks.
21 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 23 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
22 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::IO));
jorlow 2009/10/27 21:37:25 Why did you remove this?
23 DCHECK(!io_message_loop_);
24 } 24 }
25 25
26 void WebKitThread::Shutdown() { 26 void WebKitThread::EnsureInitialized() {
27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
28 DCHECK(io_message_loop_); 28 if (webkit_thread_.get())
29 29 return;
30 AutoLock lock(io_message_loop_lock_); 30 InitializeThread();
31 io_message_loop_ = NULL;
32 }
33
34 bool WebKitThread::PostIOThreadTask(
35 const tracked_objects::Location& from_here, Task* task) {
36 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
37 {
38 AutoLock lock(io_message_loop_lock_);
39 if (io_message_loop_) {
40 io_message_loop_->PostTask(from_here, task);
41 return true;
42 }
43 }
44 delete task;
45 return false;
46 } 31 }
47 32
48 WebKitThread::InternalWebKitThread::InternalWebKitThread() 33 WebKitThread::InternalWebKitThread::InternalWebKitThread()
49 : ChromeThread(ChromeThread::WEBKIT) { 34 : ChromeThread(ChromeThread::WEBKIT) {
50 } 35 }
51 36
52 WebKitThread::InternalWebKitThread::~InternalWebKitThread() { 37 WebKitThread::InternalWebKitThread::~InternalWebKitThread() {
53 } 38 }
54 39
55 void WebKitThread::InternalWebKitThread::Init() { 40 void WebKitThread::InternalWebKitThread::Init() {
56 DCHECK(!webkit_client_.get()); 41 DCHECK(!webkit_client_.get());
57 webkit_client_.reset(new BrowserWebKitClientImpl); 42 webkit_client_.reset(new BrowserWebKitClientImpl);
58 WebKit::initialize(webkit_client_.get()); 43 WebKit::initialize(webkit_client_.get());
59 // If possible, post initialization tasks to this thread (rather than doing 44 // If possible, post initialization tasks to this thread (rather than doing
60 // them now) so we don't block the IO thread any longer than we have to. 45 // them now) so we don't block the IO thread any longer than we have to.
61 } 46 }
62 47
63 void WebKitThread::InternalWebKitThread::CleanUp() { 48 void WebKitThread::InternalWebKitThread::CleanUp() {
64 DCHECK(webkit_client_.get()); 49 DCHECK(webkit_client_.get());
65 WebKit::shutdown(); 50 WebKit::shutdown();
66 } 51 }
67 52
68 MessageLoop* WebKitThread::InitializeThread() { 53 MessageLoop* WebKitThread::InitializeThread() {
69 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) 54 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
70 return NULL; 55 return NULL;
71 56
72 DCHECK(io_message_loop_);
73 DCHECK(!webkit_thread_.get()); 57 DCHECK(!webkit_thread_.get());
74 webkit_thread_.reset(new InternalWebKitThread); 58 webkit_thread_.reset(new InternalWebKitThread);
75 bool started = webkit_thread_->Start(); 59 bool started = webkit_thread_->Start();
76 DCHECK(started); 60 DCHECK(started);
77 return webkit_thread_->message_loop(); 61 return webkit_thread_->message_loop();
78 } 62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698