diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-20 23:17:09 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-20 23:17:09 +0000 |
commit | 3362262e25c76beabd31a5e7e3e2cfedfe1f5ac1 (patch) | |
tree | a4a7d0678c37a6661b08a31911fd209531a3bd75 /chrome/worker/webworkerclient_proxy.cc | |
parent | 30c473ac6ffeabd6ba09b3710323817636f30719 (diff) | |
download | chromium_src-3362262e25c76beabd31a5e7e3e2cfedfe1f5ac1.zip chromium_src-3362262e25c76beabd31a5e7e3e2cfedfe1f5ac1.tar.gz chromium_src-3362262e25c76beabd31a5e7e3e2cfedfe1f5ac1.tar.bz2 |
Fix threading and ownership issues in WebWorkerClientProxy.
Review URL: http://codereview.chromium.org/42469
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/worker/webworkerclient_proxy.cc')
-rw-r--r-- | chrome/worker/webworkerclient_proxy.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/chrome/worker/webworkerclient_proxy.cc b/chrome/worker/webworkerclient_proxy.cc index 7b351b0..6cc3d9b 100644 --- a/chrome/worker/webworkerclient_proxy.cc +++ b/chrome/worker/webworkerclient_proxy.cc @@ -15,6 +15,7 @@ WebWorkerClientProxy::WebWorkerClientProxy(const GURL& url, int route_id) : url_(url), route_id_(route_id), ALLOW_THIS_IN_INITIALIZER_LIST(impl_(WebWorker::Create(this))) { + AddRef(); WorkerThread::current()->AddRoute(route_id_, this); WorkerProcess::current()->AddRefProcess(); } @@ -60,22 +61,33 @@ void WebWorkerClientProxy::ReportPendingActivity(bool has_pending_activity) { void WebWorkerClientProxy::WorkerContextDestroyed() { Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_)); + impl_ = NULL; + + WorkerThread::current()->message_loop()->ReleaseSoon(FROM_HERE, this); } bool WebWorkerClientProxy::Send(IPC::Message* message) { + if (MessageLoop::current() != WorkerThread::current()->message_loop()) { + WorkerThread::current()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(this, &WebWorkerClientProxy::Send, message)); + return true; + } + return WorkerThread::current()->Send(message); } void WebWorkerClientProxy::OnMessageReceived(const IPC::Message& message) { - WebWorker* worker = impl_.get(); + if (!impl_) + return; + IPC_BEGIN_MESSAGE_MAP(WebWorkerClientProxy, message) - IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, worker, + IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, impl_, WebWorker::StartWorkerContext) - IPC_MESSAGE_FORWARD(WorkerMsg_TerminateWorkerContext, worker, + IPC_MESSAGE_FORWARD(WorkerMsg_TerminateWorkerContext, impl_, WebWorker::TerminateWorkerContext) - IPC_MESSAGE_FORWARD(WorkerMsg_PostMessageToWorkerContext, worker, + IPC_MESSAGE_FORWARD(WorkerMsg_PostMessageToWorkerContext, impl_, WebWorker::PostMessageToWorkerContext) - IPC_MESSAGE_FORWARD(WorkerMsg_WorkerObjectDestroyed, worker, + IPC_MESSAGE_FORWARD(WorkerMsg_WorkerObjectDestroyed, impl_, WebWorker::WorkerObjectDestroyed) IPC_END_MESSAGE_MAP() } |