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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/worker/webworkerclient_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/worker/webworkerclient_proxy.h" 5 #include "chrome/worker/webworkerclient_proxy.h"
6 6
7 #include "base/command_line.h"
7 #include "chrome/common/child_process.h" 8 #include "chrome/common/child_process.h"
9 #include "chrome/common/chrome_switches.h"
8 #include "chrome/common/ipc_logging.h" 10 #include "chrome/common/ipc_logging.h"
9 #include "chrome/common/worker_messages.h" 11 #include "chrome/common/worker_messages.h"
10 #include "chrome/renderer/webworker_proxy.h" 12 #include "chrome/renderer/webworker_proxy.h"
11 #include "chrome/worker/worker_thread.h" 13 #include "chrome/worker/worker_thread.h"
12 #include "webkit/api/public/WebString.h" 14 #include "webkit/api/public/WebString.h"
13 #include "webkit/api/public/WebURL.h" 15 #include "webkit/api/public/WebURL.h"
14 #include "webkit/api/public/WebWorker.h" 16 #include "webkit/api/public/WebWorker.h"
15 17
16 using WebKit::WebString; 18 using WebKit::WebString;
17 using WebKit::WebWorker; 19 using WebKit::WebWorker;
18 using WebKit::WebWorkerClient; 20 using WebKit::WebWorkerClient;
19 21
22 namespace {
23
24 // How long to wait for worker to finish after it's been told to terminate.
25 static const int kMaxTimeForRunawayWorkerMs = 3000;
26
27 class KillProcessTask : public Task {
28 public:
29 KillProcessTask(WebWorkerClientProxy* proxy) : proxy_(proxy) { }
30 void Run() {
31 // This shuts down the process cleanly from the perspective of the browser
32 // process, and avoids the crashed worker infobar from appearing to the new
33 // page.
34 proxy_->workerContextDestroyed();
35 }
36 private:
37 WebWorkerClientProxy* proxy_;
38 };
39
40 }
41
20 WebWorkerClientProxy::WebWorkerClientProxy(const GURL& url, int route_id) 42 WebWorkerClientProxy::WebWorkerClientProxy(const GURL& url, int route_id)
21 : url_(url), 43 : url_(url),
22 route_id_(route_id), 44 route_id_(route_id),
23 ALLOW_THIS_IN_INITIALIZER_LIST(impl_(WebWorker::create(this))) { 45 ALLOW_THIS_IN_INITIALIZER_LIST(impl_(WebWorker::create(this))) {
24 WorkerThread::current()->AddRoute(route_id_, this); 46 WorkerThread::current()->AddRoute(route_id_, this);
25 ChildProcess::current()->AddRefProcess(); 47 ChildProcess::current()->AddRefProcess();
26 } 48 }
27 49
28 WebWorkerClientProxy::~WebWorkerClientProxy() { 50 WebWorkerClientProxy::~WebWorkerClientProxy() {
29 WorkerThread::current()->RemoveRoute(route_id_); 51 WorkerThread::current()->RemoveRoute(route_id_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return WorkerThread::current()->Send(message); 102 return WorkerThread::current()->Send(message);
81 } 103 }
82 104
83 void WebWorkerClientProxy::OnMessageReceived(const IPC::Message& message) { 105 void WebWorkerClientProxy::OnMessageReceived(const IPC::Message& message) {
84 if (!impl_) 106 if (!impl_)
85 return; 107 return;
86 108
87 IPC_BEGIN_MESSAGE_MAP(WebWorkerClientProxy, message) 109 IPC_BEGIN_MESSAGE_MAP(WebWorkerClientProxy, message)
88 IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, impl_, 110 IPC_MESSAGE_FORWARD(WorkerMsg_StartWorkerContext, impl_,
89 WebWorker::startWorkerContext) 111 WebWorker::startWorkerContext)
90 IPC_MESSAGE_FORWARD(WorkerMsg_TerminateWorkerContext, impl_, 112 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext,
91 WebWorker::terminateWorkerContext) 113 OnTerminateWorkerContext)
92 IPC_MESSAGE_FORWARD(WorkerMsg_PostMessageToWorkerContext, impl_, 114 IPC_MESSAGE_FORWARD(WorkerMsg_PostMessageToWorkerContext, impl_,
93 WebWorker::postMessageToWorkerContext) 115 WebWorker::postMessageToWorkerContext)
94 IPC_MESSAGE_FORWARD(WorkerMsg_WorkerObjectDestroyed, impl_, 116 IPC_MESSAGE_FORWARD(WorkerMsg_WorkerObjectDestroyed, impl_,
95 WebWorker::workerObjectDestroyed) 117 WebWorker::workerObjectDestroyed)
96 IPC_END_MESSAGE_MAP() 118 IPC_END_MESSAGE_MAP()
97 } 119 }
120
121 void WebWorkerClientProxy::OnTerminateWorkerContext() {
122 impl_->terminateWorkerContext();
123
124 // Avoid a worker doing a while(1) from never exiting.
125 if (CommandLine::ForCurrentProcess()->HasSwitch(
126 switches::kWebWorkerShareProcesses)) {
127 // Can't kill the process since there could be workers from other
128 // renderer process.
129 NOTIMPLEMENTED();
130 return;
131 }
132
133 MessageLoop::current()->PostDelayedTask(FROM_HERE,
134 new KillProcessTask(this), kMaxTimeForRunawayWorkerMs);
135 }
OLDNEW
« 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