| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/in_process_webkit/webkit_thread.h" | 5 #include "content/browser/in_process_webkit/webkit_thread.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/in_process_webkit/browser_webkitplatformsupport_impl.h
" | 8 #include "content/browser/in_process_webkit/browser_webkitplatformsupport_impl.h
" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 12 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
| 13 | 13 |
| 14 using content::BrowserThread; | 14 using content::BrowserThread; |
| 15 | 15 |
| 16 // Must be private so that we can carefully control its lifetime. Cannot be |
| 17 // anonymous as it is forward-declared in the .h. |
| 18 class InternalWebKitThread : public content::BrowserThreadImpl { |
| 19 public: |
| 20 InternalWebKitThread(); |
| 21 virtual ~InternalWebKitThread(); |
| 22 // Does the actual initialization and shutdown of WebKit. |
| 23 void AsyncInit(); |
| 24 |
| 25 virtual void Init(); |
| 26 virtual void CleanUp(); |
| 27 |
| 28 private: |
| 29 // The WebKitPlatformSupport implementation. Only access on WebKit thread. |
| 30 scoped_ptr<BrowserWebKitPlatformSupportImpl> webkit_platform_support_; |
| 31 }; |
| 32 |
| 33 // Only used as a parameter in a task sent to itself, so ref-counting |
| 34 // is not needed. |
| 35 DISABLE_RUNNABLE_METHOD_REFCOUNT(InternalWebKitThread); |
| 36 |
| 16 WebKitThread::WebKitThread() { | 37 WebKitThread::WebKitThread() { |
| 17 } | 38 } |
| 18 | 39 |
| 19 // This happens on the UI thread after the IO thread has been shut down. | 40 // This happens on the UI thread after the IO thread has been shut down. |
| 20 WebKitThread::~WebKitThread() { | 41 WebKitThread::~WebKitThread() { |
| 21 // We can't just check CurrentlyOn(BrowserThread::UI) because in unit tests, | 42 // We can't just check CurrentlyOn(BrowserThread::UI) because in unit tests, |
| 22 // MessageLoop::Current is sometimes NULL and other times valid and there's | 43 // MessageLoop::Current is sometimes NULL and other times valid and there's |
| 23 // no BrowserThread object. Can't check that CurrentlyOn is not IO since | 44 // no BrowserThread object. Can't check that CurrentlyOn is not IO since |
| 24 // some unit tests set that BrowserThread for other checks. | 45 // some unit tests set that BrowserThread for other checks. |
| 25 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 46 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 26 } | 47 } |
| 27 | 48 |
| 28 void WebKitThread::Initialize() { | 49 void WebKitThread::Initialize() { |
| 29 DCHECK(!webkit_thread_.get()); | 50 DCHECK(!webkit_thread_.get()); |
| 30 | 51 |
| 31 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | 52 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { |
| 32 // TODO(jorlow): We need a better story for single process mode. | 53 // TODO(jorlow): We need a better story for single process mode. |
| 33 return; | 54 return; |
| 34 } | 55 } |
| 35 | 56 |
| 36 webkit_thread_.reset(new InternalWebKitThread); | 57 webkit_thread_.reset(new InternalWebKitThread); |
| 37 bool started = webkit_thread_->Start(); | 58 bool started = webkit_thread_->Start(); |
| 38 DCHECK(started); | 59 DCHECK(started); |
| 60 BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 61 webkit_thread_.get(), |
| 62 &InternalWebKitThread::AsyncInit)); |
| 39 } | 63 } |
| 40 | 64 |
| 41 WebKitThread::InternalWebKitThread::InternalWebKitThread() | 65 InternalWebKitThread::InternalWebKitThread() |
| 42 : content::BrowserThreadImpl(BrowserThread::WEBKIT) { | 66 : content::BrowserThreadImpl(BrowserThread::WEBKIT) { |
| 43 } | 67 } |
| 44 | 68 |
| 45 WebKitThread::InternalWebKitThread::~InternalWebKitThread() { | 69 InternalWebKitThread::~InternalWebKitThread() { |
| 46 Stop(); | 70 Stop(); |
| 47 } | 71 } |
| 48 | 72 |
| 49 void WebKitThread::InternalWebKitThread::Init() { | 73 void InternalWebKitThread::AsyncInit() { |
| 50 DCHECK(!webkit_platform_support_.get()); | 74 DCHECK(!webkit_platform_support_.get()); |
| 51 webkit_platform_support_.reset(new BrowserWebKitPlatformSupportImpl); | 75 webkit_platform_support_.reset(new BrowserWebKitPlatformSupportImpl); |
| 52 WebKit::initializeWithoutV8(webkit_platform_support_.get()); | 76 WebKit::initializeWithoutV8(webkit_platform_support_.get()); |
| 53 webkit_glue::EnableWebCoreLogChannels( | 77 webkit_glue::EnableWebCoreLogChannels( |
| 54 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 78 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 55 switches::kWebCoreLogChannels)); | 79 switches::kWebCoreLogChannels)); |
| 56 // Exercise WebSecurityOrigin to get its underlying statics initialized. | 80 // Exercise WebSecurityOrigin to get its underlying statics initialized. |
| 57 // TODO(michaeln): remove this when the following is landed. | 81 // TODO(michaeln): remove this when the following is landed. |
| 58 // https://bugs.webkit.org/show_bug.cgi?id=61145 | 82 // https://bugs.webkit.org/show_bug.cgi?id=61145 |
| 59 WebKit::WebSecurityOrigin::create(GURL("http://chromium.org")); | 83 WebKit::WebSecurityOrigin::create(GURL("http://chromium.org")); |
| 60 | |
| 61 // If possible, post initialization tasks to this thread (rather than doing | |
| 62 // them now) so we don't block the UI thread any longer than we have to. | |
| 63 } | 84 } |
| 64 | 85 |
| 65 void WebKitThread::InternalWebKitThread::CleanUp() { | 86 void InternalWebKitThread::Init() { |
| 87 // Any work done here blocks the caller; as WebKit::initialize... takes time |
| 88 // to complete we do it in the cutom async variant above instead. |
| 89 } |
| 90 |
| 91 void InternalWebKitThread::CleanUp() { |
| 66 DCHECK(webkit_platform_support_.get()); | 92 DCHECK(webkit_platform_support_.get()); |
| 67 WebKit::shutdown(); | 93 WebKit::shutdown(); |
| 68 } | 94 } |
| OLD | NEW |