Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7804)

Unified Diff: chrome/worker/webworkerclient_proxy.cc

Issue 112049: Prevent a worker that loops forever from preventing shutdown of the worker pr... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/worker/webworkerclient_proxy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/worker/webworkerclient_proxy.cc
===================================================================
--- chrome/worker/webworkerclient_proxy.cc (revision 16641)
+++ chrome/worker/webworkerclient_proxy.cc (working copy)
@@ -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::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 @@
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);
+}
« no previous file with comments | « chrome/worker/webworkerclient_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698