| OLD | NEW |
| 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 "base/command_line.h" |
| 8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/webmessageportchannel_impl.h" | 9 #include "chrome/common/webmessageportchannel_impl.h" |
| 10 #include "chrome/common/worker_messages.h" | 10 #include "chrome/common/worker_messages.h" |
| 11 #include "chrome/renderer/webworker_proxy.h" | 11 #include "chrome/renderer/webworker_proxy.h" |
| 12 #include "chrome/worker/webworker_stub_base.h" | 12 #include "chrome/worker/webworker_stub_base.h" |
| 13 #include "chrome/worker/worker_thread.h" | 13 #include "chrome/worker/worker_thread.h" |
| 14 #include "chrome/worker/worker_webapplicationcachehost_impl.h" |
| 14 #include "ipc/ipc_logging.h" | 15 #include "ipc/ipc_logging.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebWorker.h" |
| 18 | 19 |
| 20 using WebKit::WebApplicationCacheHost; |
| 19 using WebKit::WebMessagePortChannel; | 21 using WebKit::WebMessagePortChannel; |
| 20 using WebKit::WebMessagePortChannelArray; | 22 using WebKit::WebMessagePortChannelArray; |
| 21 using WebKit::WebString; | 23 using WebKit::WebString; |
| 22 using WebKit::WebWorker; | 24 using WebKit::WebWorker; |
| 23 using WebKit::WebWorkerClient; | 25 using WebKit::WebWorkerClient; |
| 24 | 26 |
| 25 // How long to wait for worker to finish after it's been told to terminate. | 27 // How long to wait for worker to finish after it's been told to terminate. |
| 26 #define kMaxTimeForRunawayWorkerMs 3000 | 28 #define kMaxTimeForRunawayWorkerMs 3000 |
| 27 | 29 |
| 28 WebWorkerClientProxy::WebWorkerClientProxy(int route_id, | 30 WebWorkerClientProxy::WebWorkerClientProxy(int route_id, |
| 29 WebWorkerStubBase* stub) | 31 WebWorkerStubBase* stub) |
| 30 : route_id_(route_id), | 32 : route_id_(route_id), |
| 33 appcache_host_id_(0), |
| 31 stub_(stub), | 34 stub_(stub), |
| 32 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)) { | 35 ALLOW_THIS_IN_INITIALIZER_LIST(kill_process_factory_(this)) { |
| 33 } | 36 } |
| 34 | 37 |
| 35 WebWorkerClientProxy::~WebWorkerClientProxy() { | 38 WebWorkerClientProxy::~WebWorkerClientProxy() { |
| 36 } | 39 } |
| 37 | 40 |
| 38 void WebWorkerClientProxy::postMessageToWorkerObject( | 41 void WebWorkerClientProxy::postMessageToWorkerObject( |
| 39 const WebString& message, | 42 const WebString& message, |
| 40 const WebMessagePortChannelArray& channels) { | 43 const WebMessagePortChannelArray& channels) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 98 |
| 96 void WebWorkerClientProxy::workerContextDestroyed() { | 99 void WebWorkerClientProxy::workerContextDestroyed() { |
| 97 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_)); | 100 Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_)); |
| 98 // Tell the stub that the worker has shutdown - frees this object. | 101 // Tell the stub that the worker has shutdown - frees this object. |
| 99 if (stub_) | 102 if (stub_) |
| 100 stub_->Shutdown(); | 103 stub_->Shutdown(); |
| 101 } | 104 } |
| 102 | 105 |
| 103 WebKit::WebWorker* WebWorkerClientProxy::createWorker( | 106 WebKit::WebWorker* WebWorkerClientProxy::createWorker( |
| 104 WebKit::WebWorkerClient* client) { | 107 WebKit::WebWorkerClient* client) { |
| 105 return new WebWorkerProxy(client, WorkerThread::current(), 0, 0); | 108 return new WebWorkerProxy(client, WorkerThread::current(), |
| 106 // TODO(michaeln): Fill in the appcache_host_id parameter value. | 109 0, appcache_host_id_); |
| 110 } |
| 111 |
| 112 WebApplicationCacheHost* WebWorkerClientProxy::createApplicationCacheHost( |
| 113 WebKit::WebApplicationCacheHostClient* client) { |
| 114 WorkerWebApplicationCacheHostImpl* host = |
| 115 new WorkerWebApplicationCacheHostImpl(stub_->appcache_init_info(), |
| 116 client); |
| 117 // Remember the id of the instance we create so we have access to that |
| 118 // value when creating nested dedicated workers in createWorker. |
| 119 appcache_host_id_ = host->host_id(); |
| 120 return host; |
| 107 } | 121 } |
| 108 | 122 |
| 109 bool WebWorkerClientProxy::Send(IPC::Message* message) { | 123 bool WebWorkerClientProxy::Send(IPC::Message* message) { |
| 110 return WorkerThread::current()->Send(message); | 124 return WorkerThread::current()->Send(message); |
| 111 } | 125 } |
| 112 | 126 |
| 113 void WebWorkerClientProxy::EnsureWorkerContextTerminates() { | 127 void WebWorkerClientProxy::EnsureWorkerContextTerminates() { |
| 114 // Avoid a worker doing a while(1) from never exiting. | 128 // Avoid a worker doing a while(1) from never exiting. |
| 115 if (CommandLine::ForCurrentProcess()->HasSwitch( | 129 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 116 switches::kWebWorkerShareProcesses)) { | 130 switches::kWebWorkerShareProcesses)) { |
| 117 // Can't kill the process since there could be workers from other | 131 // Can't kill the process since there could be workers from other |
| 118 // renderer process. | 132 // renderer process. |
| 119 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
| 120 return; | 134 return; |
| 121 } | 135 } |
| 122 | 136 |
| 123 // This shuts down the process cleanly from the perspective of the browser | 137 // This shuts down the process cleanly from the perspective of the browser |
| 124 // process, and avoids the crashed worker infobar from appearing to the new | 138 // process, and avoids the crashed worker infobar from appearing to the new |
| 125 // page. It's ok to post several of theese, because the first executed task | 139 // page. It's ok to post several of theese, because the first executed task |
| 126 // will exit the message loop and subsequent ones won't be executed. | 140 // will exit the message loop and subsequent ones won't be executed. |
| 127 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 141 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 128 kill_process_factory_.NewRunnableMethod( | 142 kill_process_factory_.NewRunnableMethod( |
| 129 &WebWorkerClientProxy::workerContextDestroyed), | 143 &WebWorkerClientProxy::workerContextDestroyed), |
| 130 kMaxTimeForRunawayWorkerMs); | 144 kMaxTimeForRunawayWorkerMs); |
| 131 } | 145 } |
| 132 | 146 |
| OLD | NEW |