| OLD | NEW |
| 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. | |
| 13 WebKitThread::WebKitThread() { | 12 WebKitThread::WebKitThread() { |
| 14 // The thread is started lazily by InitializeThread() on the IO thread. | |
| 15 } | 13 } |
| 16 | 14 |
| 17 // This happens on the UI thread after the IO thread has been shut down. | 15 // This happens on the UI thread after the IO thread has been shut down. |
| 18 WebKitThread::~WebKitThread() { | 16 WebKitThread::~WebKitThread() { |
| 19 // We can't just check CurrentlyOn(ChromeThread::UI) because in unit tests, | 17 // 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 | 18 // 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 | 19 // no ChromeThread object. Can't check that CurrentlyOn is not IO since |
| 22 // some unit tests set that ChromeThread for other checks. | 20 // some unit tests set that ChromeThread for other checks. |
| 23 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 21 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 24 } | 22 } |
| 25 | 23 |
| 26 void WebKitThread::EnsureInitialized() { | 24 void WebKitThread::Initialize() { |
| 27 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 25 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 28 if (webkit_thread_.get()) | 26 DCHECK(!webkit_thread_.get()); |
| 27 |
| 28 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { |
| 29 // TODO(jorlow): This thread should be used (and started) in single process |
| 30 // mode rather than following different code paths. |
| 29 return; | 31 return; |
| 30 InitializeThread(); | 32 } |
| 33 |
| 34 webkit_thread_.reset(new InternalWebKitThread); |
| 35 bool started = webkit_thread_->Start(); |
| 36 DCHECK(started); |
| 31 } | 37 } |
| 32 | 38 |
| 33 WebKitThread::InternalWebKitThread::InternalWebKitThread() | 39 WebKitThread::InternalWebKitThread::InternalWebKitThread() |
| 34 : ChromeThread(ChromeThread::WEBKIT) { | 40 : ChromeThread(ChromeThread::WEBKIT) { |
| 35 } | 41 } |
| 36 | 42 |
| 37 WebKitThread::InternalWebKitThread::~InternalWebKitThread() { | 43 WebKitThread::InternalWebKitThread::~InternalWebKitThread() { |
| 38 Stop(); | 44 Stop(); |
| 39 } | 45 } |
| 40 | 46 |
| 41 void WebKitThread::InternalWebKitThread::Init() { | 47 void WebKitThread::InternalWebKitThread::Init() { |
| 42 DCHECK(!webkit_client_.get()); | 48 DCHECK(!webkit_client_.get()); |
| 43 webkit_client_.reset(new BrowserWebKitClientImpl); | 49 webkit_client_.reset(new BrowserWebKitClientImpl); |
| 44 WebKit::initialize(webkit_client_.get()); | 50 WebKit::initialize(webkit_client_.get()); |
| 45 // If possible, post initialization tasks to this thread (rather than doing | 51 // 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. | 52 // them now) so we don't block the UI thread any longer than we have to. |
| 47 } | 53 } |
| 48 | 54 |
| 49 void WebKitThread::InternalWebKitThread::CleanUp() { | 55 void WebKitThread::InternalWebKitThread::CleanUp() { |
| 50 DCHECK(webkit_client_.get()); | 56 DCHECK(webkit_client_.get()); |
| 51 WebKit::shutdown(); | 57 WebKit::shutdown(); |
| 52 } | 58 } |
| 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 } | |
| OLD | NEW |