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

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

Issue 402049: Revert my last... (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. 12 // This happens on the UI thread before the IO thread has been shut down.
13 WebKitThread::WebKitThread() { 13 WebKitThread::WebKitThread() {
14 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { 14 // The thread is started lazily by InitializeThread() on the IO thread.
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);
23 } 15 }
24 16
25 // 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.
26 WebKitThread::~WebKitThread() { 18 WebKitThread::~WebKitThread() {
27 // We can't just check CurrentlyOn(ChromeThread::UI) because in unit tests, 19 // We can't just check CurrentlyOn(ChromeThread::UI) because in unit tests,
28 // MessageLoop::Current is sometimes NULL and other times valid and there's 20 // MessageLoop::Current is sometimes NULL and other times valid and there's
29 // no ChromeThread object. Can't check that CurrentlyOn is not IO since 21 // no ChromeThread object. Can't check that CurrentlyOn is not IO since
30 // some unit tests set that ChromeThread for other checks. 22 // some unit tests set that ChromeThread for other checks.
31 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 23 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
32 } 24 }
33 25
26 void WebKitThread::EnsureInitialized() {
27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
28 if (webkit_thread_.get())
29 return;
30 InitializeThread();
31 }
32
34 WebKitThread::InternalWebKitThread::InternalWebKitThread() 33 WebKitThread::InternalWebKitThread::InternalWebKitThread()
35 : ChromeThread(ChromeThread::WEBKIT) { 34 : ChromeThread(ChromeThread::WEBKIT) {
36 } 35 }
37 36
38 WebKitThread::InternalWebKitThread::~InternalWebKitThread() { 37 WebKitThread::InternalWebKitThread::~InternalWebKitThread() {
39 Stop(); 38 Stop();
40 } 39 }
41 40
42 void WebKitThread::InternalWebKitThread::Init() { 41 void WebKitThread::InternalWebKitThread::Init() {
43 DCHECK(!webkit_client_.get()); 42 DCHECK(!webkit_client_.get());
44 webkit_client_.reset(new BrowserWebKitClientImpl); 43 webkit_client_.reset(new BrowserWebKitClientImpl);
45 WebKit::initialize(webkit_client_.get()); 44 WebKit::initialize(webkit_client_.get());
46 // If possible, post initialization tasks to this thread (rather than doing 45 // If possible, post initialization tasks to this thread (rather than doing
47 // them now) so we don't block the UI thread any longer than we have to. 46 // them now) so we don't block the IO thread any longer than we have to.
48 } 47 }
49 48
50 void WebKitThread::InternalWebKitThread::CleanUp() { 49 void WebKitThread::InternalWebKitThread::CleanUp() {
51 DCHECK(webkit_client_.get()); 50 DCHECK(webkit_client_.get());
52 WebKit::shutdown(); 51 WebKit::shutdown();
53 } 52 }
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