diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:30:30 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:30:30 +0000 |
commit | 94f9a0f686619656ca4ff2b6511179dc2132cc5d (patch) | |
tree | 26051806295528d68b4e5e65a0f39eaac18f7a24 | |
parent | 1b5d23dfa22d8858dc9ab35d373fcf328aadbcba (diff) | |
download | chromium_src-94f9a0f686619656ca4ff2b6511179dc2132cc5d.zip chromium_src-94f9a0f686619656ca4ff2b6511179dc2132cc5d.tar.gz chromium_src-94f9a0f686619656ca4ff2b6511179dc2132cc5d.tar.bz2 |
Switch child threads so that current() only works on the correct thread and the correct process.
Review URL: http://codereview.chromium.org/126086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18409 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/plugin/plugin_thread.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 11 | ||||
-rw-r--r-- | chrome/renderer/render_thread_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/worker/worker_thread.cc | 12 | ||||
-rw-r--r-- | chrome/worker/worker_thread.h | 4 | ||||
-rw-r--r-- | webkit/glue/webworker_impl.cc | 2 |
6 files changed, 32 insertions, 10 deletions
diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc index 08c96c9..cb92de4 100644 --- a/chrome/plugin/plugin_thread.cc +++ b/chrome/plugin/plugin_thread.cc @@ -12,7 +12,9 @@ #endif #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/process_util.h" +#include "base/thread_local.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_plugin_lib.h" #include "chrome/common/chrome_switches.h" @@ -26,6 +28,8 @@ #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/webkit_glue.h" +static base::LazyInstance<base::ThreadLocalPointer<PluginThread> > lazy_tls( + base::LINKER_INITIALIZED); PluginThread::PluginThread() : ChildThread(base::Thread::Options(MessageLoop::TYPE_UI, 0)), @@ -38,8 +42,7 @@ PluginThread::~PluginThread() { } PluginThread* PluginThread::current() { - DCHECK(IsPluginProcess()); - return static_cast<PluginThread*>(ChildThread::current()); + return lazy_tls.Pointer()->Get(); } void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { @@ -50,6 +53,7 @@ void PluginThread::OnControlMessageReceived(const IPC::Message& msg) { } void PluginThread::Init() { + lazy_tls.Pointer()->Set(this); ChildThread::Init(); PatchNPNFunctions(); @@ -95,6 +99,7 @@ void PluginThread::CleanUp() { // in some of the above cleanup. // See http://code.google.com/p/chromium/issues/detail?id=8980 ChildThread::CleanUp(); + lazy_tls.Pointer()->Set(NULL); } void PluginThread::OnCreateChannel(int process_id, bool off_the_record) { diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 1f72aed..e615a49 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -8,8 +8,10 @@ #include <vector> #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/shared_memory.h" #include "base/stats_table.h" +#include "base/thread_local.h" #include "chrome/common/app_cache/app_cache_context_impl.h" #include "chrome/common/app_cache/app_cache_dispatcher.h" #include "chrome/common/chrome_switches.h" @@ -57,6 +59,9 @@ using WebKit::WebString; static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; +static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( + base::LINKER_INITIALIZED); + //----------------------------------------------------------------------------- // Methods below are only called on the owner's thread: @@ -81,8 +86,7 @@ RenderThread::~RenderThread() { } RenderThread* RenderThread::current() { - DCHECK(!IsPluginProcess()); - return static_cast<RenderThread*>(ChildThread::current()); + return lazy_tls.Pointer()->Get(); } void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { @@ -128,6 +132,7 @@ class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { #endif void RenderThread::Init() { + lazy_tls.Pointer()->Set(this); #if defined(OS_WIN) // If you are running plugins in this thread you need COM active but in // the normal case you don't. @@ -172,8 +177,8 @@ void RenderThread::CleanUp() { } notification_service_.reset(); - ChildThread::CleanUp(); + lazy_tls.Pointer()->Set(NULL); // TODO(port) #if defined(OS_WIN) diff --git a/chrome/renderer/render_thread_unittest.cc b/chrome/renderer/render_thread_unittest.cc index 7ad8175..bb2e297 100644 --- a/chrome/renderer/render_thread_unittest.cc +++ b/chrome/renderer/render_thread_unittest.cc @@ -40,7 +40,9 @@ class RenderThreadTest : public testing::Test { }; TEST_F(RenderThreadTest, TestGlobal) { - ASSERT_TRUE(RenderThread::current()); + // Can't reach the RenderThread object on other threads, since it's not + // thread-safe! + ASSERT_FALSE(RenderThread::current()); } TEST_F(RenderThreadTest, TestVisitedMsg) { diff --git a/chrome/worker/worker_thread.cc b/chrome/worker/worker_thread.cc index 8f3aebf..a6db89d 100644 --- a/chrome/worker/worker_thread.cc +++ b/chrome/worker/worker_thread.cc @@ -4,11 +4,17 @@ #include "chrome/worker/worker_thread.h" +#include "base/lazy_instance.h" +#include "base/thread_local.h" #include "chrome/common/worker_messages.h" #include "chrome/worker/webworkerclient_proxy.h" #include "chrome/worker/worker_webkitclient_impl.h" #include "webkit/api/public/WebKit.h" +static base::LazyInstance<base::ThreadLocalPointer<WorkerThread> > lazy_tls( + base::LINKER_INITIALIZED); + + WorkerThread::WorkerThread() : ChildThread(base::Thread::Options(MessageLoop::TYPE_DEFAULT, kV8StackSize)) { @@ -17,7 +23,12 @@ WorkerThread::WorkerThread() WorkerThread::~WorkerThread() { } +WorkerThread* WorkerThread::current() { + return lazy_tls.Pointer()->Get(); +} + void WorkerThread::Init() { + lazy_tls.Pointer()->Set(this); ChildThread::Init(); webkit_client_.reset(new WorkerWebKitClientImpl); WebKit::initialize(webkit_client_.get()); @@ -35,6 +46,7 @@ void WorkerThread::CleanUp() { } ChildThread::CleanUp(); + lazy_tls.Pointer()->Set(NULL); } void WorkerThread::OnControlMessageReceived(const IPC::Message& msg) { diff --git a/chrome/worker/worker_thread.h b/chrome/worker/worker_thread.h index c7f9a09..6bea33c 100644 --- a/chrome/worker/worker_thread.h +++ b/chrome/worker/worker_thread.h @@ -17,9 +17,7 @@ class WorkerThread : public ChildThread { ~WorkerThread(); // Returns the one worker thread. - static WorkerThread* current() { - return static_cast<WorkerThread*>(ChildThread::current()); - } + static WorkerThread* current(); private: virtual void OnControlMessageReceived(const IPC::Message& msg); diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index 9d155ed..bee7f44 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -72,7 +72,7 @@ void WebWorkerImpl::PostMessageToWorkerContextTask( static_cast<WebCore::WorkerContext*>(context); worker_context->dispatchMessage(message); - this_ptr->client_->confirmMessageFromWorkerObject( + this_ptr->confirmMessageFromWorkerObject( worker_context->hasPendingActivity()); } |