diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 21:33:33 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 21:33:33 +0000 |
commit | 5fb67f4f7e9a3b21b6e4eb06e4ab730f7decca79 (patch) | |
tree | ee9195cbd8058b19820819717e4b4ad3ad1b8a50 /chrome/worker | |
parent | bf3ec7355013aa824eca19a0362638771defd4e7 (diff) | |
download | chromium_src-5fb67f4f7e9a3b21b6e4eb06e4ab730f7decca79.zip chromium_src-5fb67f4f7e9a3b21b6e4eb06e4ab730f7decca79.tar.gz chromium_src-5fb67f4f7e9a3b21b6e4eb06e4ab730f7decca79.tar.bz2 |
Prevent a worker that loops forever from preventing shutdown of the worker process.
BUG=11672
Review URL: http://codereview.chromium.org/112049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/worker')
-rw-r--r-- | chrome/worker/webworkerclient_proxy.cc | 42 | ||||
-rw-r--r-- | chrome/worker/webworkerclient_proxy.h | 2 |
2 files changed, 42 insertions, 2 deletions
diff --git a/chrome/worker/webworkerclient_proxy.cc b/chrome/worker/webworkerclient_proxy.cc index 003a860..8a0a6f1 100644 --- a/chrome/worker/webworkerclient_proxy.cc +++ b/chrome/worker/webworkerclient_proxy.cc @@ -4,7 +4,9 @@ #include "chrome/worker/webworkerclient_proxy.h" +#include "base/command_line.h" #include "chrome/common/child_process.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/ipc_logging.h" #include "chrome/common/worker_messages.h" #include "chrome/renderer/webworker_proxy.h" @@ -17,6 +19,26 @@ using WebKit::WebString; using WebKit::WebWorker; using WebKit::WebWorkerClient; +namespace { + +// How long to wait for worker to finish after it's been told to terminate. +static const int kMaxTimeForRunawayWorkerMs = 3000; + +class KillProcessTask : public Task { + public: + KillProcessTask(WebWorkerClientProxy* proxy) : proxy_(proxy) { } + void Run() { + // This shuts down the process cleanly from the perspective of the browser + // process, and avoids the crashed worker infobar from appearing to the new + // page. + proxy_->workerContextDestroyed(); + } + private: + WebWorkerClientProxy* proxy_; +}; + +} + WebWorkerClientProxy::WebWorkerClientProxy(const GURL& url, int route_id) : url_(url), route_id_(route_id), @@ -87,11 +109,27 @@ void WebWorkerClientProxy::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(WebWorkerClientProxy, message) IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, impl_, WebWorker::startWorkerContext) - IPC_MESSAGE_FORWARD(WorkerMsg_TerminateWorkerContext, impl_, - WebWorker::terminateWorkerContext) + IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, + OnTerminateWorkerContext) IPC_MESSAGE_FORWARD(WorkerMsg_PostMessageToWorkerContext, impl_, WebWorker::postMessageToWorkerContext) IPC_MESSAGE_FORWARD(WorkerMsg_WorkerObjectDestroyed, impl_, WebWorker::workerObjectDestroyed) IPC_END_MESSAGE_MAP() } + +void WebWorkerClientProxy::OnTerminateWorkerContext() { + impl_->terminateWorkerContext(); + + // Avoid a worker doing a while(1) from never exiting. + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kWebWorkerShareProcesses)) { + // Can't kill the process since there could be workers from other + // renderer process. + NOTIMPLEMENTED(); + return; + } + + MessageLoop::current()->PostDelayedTask(FROM_HERE, + new KillProcessTask(this), kMaxTimeForRunawayWorkerMs); +} diff --git a/chrome/worker/webworkerclient_proxy.h b/chrome/worker/webworkerclient_proxy.h index 5c27cf0..ccff6f1 100644 --- a/chrome/worker/webworkerclient_proxy.h +++ b/chrome/worker/webworkerclient_proxy.h @@ -50,6 +50,8 @@ class WebWorkerClientProxy : public WebKit::WebWorkerClient, bool Send(IPC::Message* message); + void OnTerminateWorkerContext(); + // The source url for this worker. GURL url_; |