summaryrefslogtreecommitdiffstats
path: root/chrome/worker
diff options
context:
space:
mode:
authordimich@google.com <dimich@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 23:50:53 +0000
committerdimich@google.com <dimich@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 23:50:53 +0000
commitf11030094e99bcb61555dc3bb4c157703dc1d7ea (patch)
tree5f2001f74906cc33a10bb3d6fc3154a26774b47e /chrome/worker
parent0070eab07191eaed49b945da7db9ba8e687612a5 (diff)
downloadchromium_src-f11030094e99bcb61555dc3bb4c157703dc1d7ea.zip
chromium_src-f11030094e99bcb61555dc3bb4c157703dc1d7ea.tar.gz
chromium_src-f11030094e99bcb61555dc3bb4c157703dc1d7ea.tar.bz2
Make sure the workers are given a chance to terminate their thread when the IPC channel fails.
Usually, the ChildThread::OnChannelError() simply kills the message loop. we want to give workers an opportunity to get out of their threads to avoid crashes when main thread destroys globals. BUG=35963 TEST=WorkerTest.StressJSExecution Review URL: http://codereview.chromium.org/647064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/worker')
-rw-r--r--chrome/worker/websharedworker_stub.cc4
-rw-r--r--chrome/worker/websharedworker_stub.h1
-rw-r--r--chrome/worker/webworker_stub.cc4
-rw-r--r--chrome/worker/webworker_stub.h1
-rw-r--r--chrome/worker/webworker_stub_base.cc10
-rw-r--r--chrome/worker/worker_thread.cc19
-rw-r--r--chrome/worker/worker_thread.h11
-rw-r--r--chrome/worker/worker_uitest.cc4
8 files changed, 50 insertions, 4 deletions
diff --git a/chrome/worker/websharedworker_stub.cc b/chrome/worker/websharedworker_stub.cc
index 7c9646e..232f842 100644
--- a/chrome/worker/websharedworker_stub.cc
+++ b/chrome/worker/websharedworker_stub.cc
@@ -34,6 +34,10 @@ void WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) {
IPC_END_MESSAGE_MAP()
}
+void WebSharedWorkerStub::OnChannelError() {
+ OnTerminateWorkerContext();
+}
+
void WebSharedWorkerStub::OnStartWorkerContext(
const GURL& url, const string16& user_agent, const string16& source_code) {
// Ignore multiple attempts to start this worker (can happen if two pages
diff --git a/chrome/worker/websharedworker_stub.h b/chrome/worker/websharedworker_stub.h
index b12cd99..37ab640 100644
--- a/chrome/worker/websharedworker_stub.h
+++ b/chrome/worker/websharedworker_stub.h
@@ -21,6 +21,7 @@ class WebSharedWorkerStub : public WebWorkerStubBase {
// IPC::Channel::Listener implementation.
virtual void OnMessageReceived(const IPC::Message& message);
+ virtual void OnChannelError();
private:
virtual ~WebSharedWorkerStub();
diff --git a/chrome/worker/webworker_stub.cc b/chrome/worker/webworker_stub.cc
index 33a9b60..142adcf 100644
--- a/chrome/worker/webworker_stub.cc
+++ b/chrome/worker/webworker_stub.cc
@@ -48,6 +48,10 @@ WebWorkerStub::~WebWorkerStub() {
impl_->clientDestroyed();
}
+void WebWorkerStub::OnChannelError() {
+ OnTerminateWorkerContext();
+}
+
void WebWorkerStub::OnMessageReceived(const IPC::Message& message) {
if (!impl_)
return;
diff --git a/chrome/worker/webworker_stub.h b/chrome/worker/webworker_stub.h
index 59a46f1..dab69d0 100644
--- a/chrome/worker/webworker_stub.h
+++ b/chrome/worker/webworker_stub.h
@@ -21,6 +21,7 @@ class WebWorkerStub : public WebWorkerStubBase {
// IPC::Channel::Listener implementation.
virtual void OnMessageReceived(const IPC::Message& message);
+ virtual void OnChannelError();
private:
virtual ~WebWorkerStub();
diff --git a/chrome/worker/webworker_stub_base.cc b/chrome/worker/webworker_stub_base.cc
index 8ea2a15..b999f44 100644
--- a/chrome/worker/webworker_stub_base.cc
+++ b/chrome/worker/webworker_stub_base.cc
@@ -12,13 +12,19 @@ WebWorkerStubBase::WebWorkerStubBase(int route_id)
: route_id_(route_id),
ALLOW_THIS_IN_INITIALIZER_LIST(client_(route_id, this)) {
+ WorkerThread* workerThread = WorkerThread::current();
+ DCHECK(workerThread);
+ workerThread->AddWorkerStub(this);
// Start processing incoming IPCs for this worker.
- WorkerThread::current()->AddRoute(route_id_, this);
+ workerThread->AddRoute(route_id_, this);
ChildProcess::current()->AddRefProcess();
}
WebWorkerStubBase::~WebWorkerStubBase() {
- WorkerThread::current()->RemoveRoute(route_id_);
+ WorkerThread* workerThread = WorkerThread::current();
+ DCHECK(workerThread);
+ workerThread->RemoveWorkerStub(this);
+ workerThread->RemoveRoute(route_id_);
ChildProcess::current()->ReleaseProcess();
}
diff --git a/chrome/worker/worker_thread.cc b/chrome/worker/worker_thread.cc
index ac8a1c7..0591902 100644
--- a/chrome/worker/worker_thread.cc
+++ b/chrome/worker/worker_thread.cc
@@ -62,3 +62,22 @@ void WorkerThread::OnCreateWorker(const GURL& url,
else
new WebWorkerStub(url, route_id);
}
+
+// The browser process is likely dead. Terminate all workers.
+void WorkerThread::OnChannelError() {
+ set_on_channel_error_called(true);
+
+ for (WorkerStubsList::iterator it = worker_stubs_.begin();
+ it != worker_stubs_.end(); ++it) {
+ (*it)->OnChannelError();
+ }
+}
+
+void WorkerThread::RemoveWorkerStub(WebWorkerStubBase* stub) {
+ worker_stubs_.erase(stub);
+}
+
+void WorkerThread::AddWorkerStub(WebWorkerStubBase* stub) {
+ worker_stubs_.insert(stub);
+}
+
diff --git a/chrome/worker/worker_thread.h b/chrome/worker/worker_thread.h
index 040f0db..0a0feae 100644
--- a/chrome/worker/worker_thread.h
+++ b/chrome/worker/worker_thread.h
@@ -5,9 +5,12 @@
#ifndef CHROME_WORKER_WORKER_THREAD_H_
#define CHROME_WORKER_WORKER_THREAD_H_
+#include <set>
+
#include "chrome/common/child_thread.h"
class GURL;
+class WebWorkerStubBase;
class WorkerWebKitClientImpl;
class WorkerThread : public ChildThread {
@@ -18,14 +21,22 @@ class WorkerThread : public ChildThread {
// Returns the one worker thread.
static WorkerThread* current();
+ // Invoked from stub constructors/destructors. Stubs own themselves.
+ void AddWorkerStub(WebWorkerStubBase* stub);
+ void RemoveWorkerStub(WebWorkerStubBase* stub);
+
private:
virtual void OnControlMessageReceived(const IPC::Message& msg);
+ virtual void OnChannelError();
void OnCreateWorker(
const GURL& url, bool is_shared, const string16& name, int route_id);
scoped_ptr<WorkerWebKitClientImpl> webkit_client_;
+ typedef std::set<WebWorkerStubBase*> WorkerStubsList;
+ WorkerStubsList worker_stubs_;
+
DISALLOW_COPY_AND_ASSIGN(WorkerThread);
};
diff --git a/chrome/worker/worker_uitest.cc b/chrome/worker/worker_uitest.cc
index fe6c6ba..b19ebd2 100644
--- a/chrome/worker/worker_uitest.cc
+++ b/chrome/worker/worker_uitest.cc
@@ -180,8 +180,8 @@ TEST_F(WorkerTest, SharedWorkerHttpAuth) {
}
-// All kinds of crashes on Linux and Mac http://crbug.com/22898
-#if defined(OS_LINUX) || defined(OS_MACOSX)
+// http://crbug.com/35963
+#if defined(OS_LINUX)
#define StressJSExecution DISABLED_StressJSExecution
#endif