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

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

Issue 405007: Always start the WebKit thread.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/in_process_webkit/webkit_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "third_party/WebKit/WebKit/chromium/public/WebKit.h" 10 #include "third_party/WebKit/WebKit/chromium/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.
13 WebKitThread::WebKitThread() { 13 WebKitThread::WebKitThread() {
14 // The thread is started lazily by InitializeThread() on the IO thread. 14 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
15 // TODO(jorlow): This thread should be used (and started) in single process
16 // mode rather than following different code paths.
17 return;
18 }
19
20 webkit_thread_.reset(new InternalWebKitThread);
21 bool started = webkit_thread_->Start();
22 DCHECK(started);
15 } 23 }
16 24
17 // This happens on the UI thread after the IO thread has been shut down. 25 // This happens on the UI thread after the IO thread has been shut down.
18 WebKitThread::~WebKitThread() { 26 WebKitThread::~WebKitThread() {
19 // We can't just check CurrentlyOn(ChromeThread::UI) because in unit tests, 27 // 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 28 // 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 29 // no ChromeThread object. Can't check that CurrentlyOn is not IO since
22 // some unit tests set that ChromeThread for other checks. 30 // some unit tests set that ChromeThread for other checks.
23 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 31 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
24 } 32 }
25 33
26 void WebKitThread::EnsureInitialized() {
27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
28 if (webkit_thread_.get())
29 return;
30 InitializeThread();
31 }
32
33 WebKitThread::InternalWebKitThread::InternalWebKitThread() 34 WebKitThread::InternalWebKitThread::InternalWebKitThread()
34 : ChromeThread(ChromeThread::WEBKIT) { 35 : ChromeThread(ChromeThread::WEBKIT) {
35 } 36 }
36 37
37 WebKitThread::InternalWebKitThread::~InternalWebKitThread() { 38 WebKitThread::InternalWebKitThread::~InternalWebKitThread() {
38 Stop(); 39 Stop();
39 } 40 }
40 41
41 void WebKitThread::InternalWebKitThread::Init() { 42 void WebKitThread::InternalWebKitThread::Init() {
42 DCHECK(!webkit_client_.get()); 43 DCHECK(!webkit_client_.get());
43 webkit_client_.reset(new BrowserWebKitClientImpl); 44 webkit_client_.reset(new BrowserWebKitClientImpl);
44 WebKit::initialize(webkit_client_.get()); 45 WebKit::initialize(webkit_client_.get());
45 // If possible, post initialization tasks to this thread (rather than doing 46 // If possible, post initialization tasks to this thread (rather than doing
46 // them now) so we don't block the IO thread any longer than we have to. 47 // them now) so we don't block the UI thread any longer than we have to.
47 } 48 }
48 49
49 void WebKitThread::InternalWebKitThread::CleanUp() { 50 void WebKitThread::InternalWebKitThread::CleanUp() {
50 DCHECK(webkit_client_.get()); 51 DCHECK(webkit_client_.get());
51 WebKit::shutdown(); 52 WebKit::shutdown();
52 } 53 }
53
54 MessageLoop* WebKitThread::InitializeThread() {
55 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
56 return NULL;
57
58 DCHECK(!webkit_thread_.get());
59 webkit_thread_.reset(new InternalWebKitThread);
60 bool started = webkit_thread_->Start();
61 DCHECK(started);
62 return webkit_thread_->message_loop();
63 }
OLDNEW
« no previous file with comments | « chrome/browser/in_process_webkit/webkit_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698