| 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/child_process.h" | 8 #include "chrome/common/child_process.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/webmessageportchannel_impl.h" | 10 #include "chrome/common/webmessageportchannel_impl.h" |
| 11 #include "chrome/common/worker_messages.h" | 11 #include "chrome/common/worker_messages.h" |
| 12 #include "chrome/renderer/webworker_proxy.h" | 12 #include "chrome/renderer/webworker_proxy.h" |
| 13 #include "chrome/worker/worker_thread.h" | 13 #include "chrome/worker/worker_thread.h" |
| 14 #include "chrome/worker/nativewebworker_impl.h" | 14 #include "chrome/worker/nativewebworker_impl.h" |
| 15 #include "ipc/ipc_logging.h" | 15 #include "ipc/ipc_logging.h" |
| 16 #include "webkit/api/public/WebString.h" | 16 #include "webkit/api/public/WebString.h" |
| 17 #include "webkit/api/public/WebURL.h" | 17 #include "webkit/api/public/WebURL.h" |
| 18 #include "webkit/api/public/WebWorker.h" | 18 #include "webkit/api/public/WebWorker.h" |
| 19 | 19 |
| 20 using WebKit::WebMessagePortChannel; | 20 using WebKit::WebMessagePortChannel; |
| 21 using WebKit::WebMessagePortChannelArray; |
| 21 using WebKit::WebString; | 22 using WebKit::WebString; |
| 22 using WebKit::WebWorker; | 23 using WebKit::WebWorker; |
| 23 using WebKit::WebWorkerClient; | 24 using WebKit::WebWorkerClient; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // How long to wait for worker to finish after it's been told to terminate. | 28 // How long to wait for worker to finish after it's been told to terminate. |
| 28 static const int kMaxTimeForRunawayWorkerMs = 3000; | 29 static const int kMaxTimeForRunawayWorkerMs = 3000; |
| 29 | 30 |
| 30 class KillProcessTask : public Task { | 31 class KillProcessTask : public Task { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 ChildProcess::current()->AddRefProcess(); | 75 ChildProcess::current()->AddRefProcess(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 WebWorkerClientProxy::~WebWorkerClientProxy() { | 78 WebWorkerClientProxy::~WebWorkerClientProxy() { |
| 78 WorkerThread::current()->RemoveRoute(route_id_); | 79 WorkerThread::current()->RemoveRoute(route_id_); |
| 79 ChildProcess::current()->ReleaseProcess(); | 80 ChildProcess::current()->ReleaseProcess(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void WebWorkerClientProxy::postMessageToWorkerObject( | 83 void WebWorkerClientProxy::postMessageToWorkerObject( |
| 83 const WebString& message, | 84 const WebString& message, |
| 84 WebMessagePortChannel* channel) { | 85 const WebMessagePortChannelArray& channels) { |
| 85 int message_port_id = MSG_ROUTING_NONE; | 86 std::vector<int> message_port_ids(channels.size()); |
| 86 if (channel) { | 87 std::vector<int> routing_ids(channels.size()); |
| 88 for (size_t i = 0; i < channels.size(); ++i) { |
| 87 WebMessagePortChannelImpl* webchannel = | 89 WebMessagePortChannelImpl* webchannel = |
| 88 static_cast<WebMessagePortChannelImpl*>(channel); | 90 static_cast<WebMessagePortChannelImpl*>(channels[i]); |
| 89 message_port_id = webchannel->message_port_id(); | 91 message_port_ids[i] = webchannel->message_port_id(); |
| 90 webchannel->QueueMessages(); | 92 webchannel->QueueMessages(); |
| 91 DCHECK(message_port_id != MSG_ROUTING_NONE); | 93 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); |
| 94 routing_ids[i] = MSG_ROUTING_NONE; |
| 92 } | 95 } |
| 93 | 96 |
| 94 Send(new WorkerMsg_PostMessage( | 97 Send(new WorkerMsg_PostMessage( |
| 95 route_id_, message, message_port_id, MSG_ROUTING_NONE)); | 98 route_id_, message, message_port_ids, routing_ids)); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void WebWorkerClientProxy::postExceptionToWorkerObject( | 101 void WebWorkerClientProxy::postExceptionToWorkerObject( |
| 99 const WebString& error_message, | 102 const WebString& error_message, |
| 100 int line_number, | 103 int line_number, |
| 101 const WebString& source_url) { | 104 const WebString& source_url) { |
| 102 Send(new WorkerHostMsg_PostExceptionToWorkerObject( | 105 Send(new WorkerHostMsg_PostExceptionToWorkerObject( |
| 103 route_id_, error_message, line_number, source_url)); | 106 route_id_, error_message, line_number, source_url)); |
| 104 } | 107 } |
| 105 | 108 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Can't kill the process since there could be workers from other | 175 // Can't kill the process since there could be workers from other |
| 173 // renderer process. | 176 // renderer process. |
| 174 NOTIMPLEMENTED(); | 177 NOTIMPLEMENTED(); |
| 175 return; | 178 return; |
| 176 } | 179 } |
| 177 | 180 |
| 178 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 181 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 179 new KillProcessTask(this), kMaxTimeForRunawayWorkerMs); | 182 new KillProcessTask(this), kMaxTimeForRunawayWorkerMs); |
| 180 } | 183 } |
| 181 | 184 |
| 182 void WebWorkerClientProxy::OnPostMessage(const string16& message, | 185 void WebWorkerClientProxy::OnPostMessage( |
| 183 int sent_message_port_id, | 186 const string16& message, |
| 184 int new_routing_id) { | 187 const std::vector<int>& sent_message_port_ids, |
| 185 WebMessagePortChannel* channel = NULL; | 188 const std::vector<int>& new_routing_ids) { |
| 186 if (sent_message_port_id != MSG_ROUTING_NONE) { | 189 WebMessagePortChannelArray channels(sent_message_port_ids.size()); |
| 187 channel = new WebMessagePortChannelImpl( | 190 for (size_t i = 0; i < sent_message_port_ids.size(); i++) { |
| 188 new_routing_id, sent_message_port_id); | 191 channels[i] = new WebMessagePortChannelImpl( |
| 192 new_routing_ids[i], sent_message_port_ids[i]); |
| 189 } | 193 } |
| 190 | 194 |
| 191 impl_->postMessageToWorkerContext(message, channel); | 195 impl_->postMessageToWorkerContext(message, channels); |
| 192 } | 196 } |
| OLD | NEW |