| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/renderer/shared_worker/websharedworker_proxy.h" | 5 #include "content/renderer/shared_worker/websharedworker_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "content/child/child_thread_impl.h" | 9 #include "content/child/child_thread_impl.h" |
| 10 #include "content/child/webmessageportchannel_impl.h" | 10 #include "content/child/webmessageportchannel_impl.h" |
| 11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
| 12 #include "content/common/worker_messages.h" | 12 #include "content/common/worker_messages.h" |
| 13 #include "content/common/worker_use_counter.h" |
| 13 #include "ipc/message_router.h" | 14 #include "ipc/message_router.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 WebSharedWorkerProxy::WebSharedWorkerProxy( | 18 WebSharedWorkerProxy::WebSharedWorkerProxy( |
| 18 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener, | 19 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener, |
| 19 ViewHostMsg_CreateWorker_Params params, | 20 ViewHostMsg_CreateWorker_Params params, |
| 20 blink::WebMessagePortChannel* channel) | 21 blink::WebMessagePortChannel* channel) |
| 21 : route_id_(MSG_ROUTING_NONE), | 22 : route_id_(MSG_ROUTING_NONE), |
| 22 router_(ChildThreadImpl::current()->GetRouter()), | 23 router_(ChildThreadImpl::current()->GetRouter()), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 } | 54 } |
| 54 | 55 |
| 55 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { | 56 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { |
| 56 bool handled = true; | 57 bool handled = true; |
| 57 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) | 58 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) |
| 58 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) | 59 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) |
| 59 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, | 60 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, |
| 60 OnWorkerScriptLoadFailed) | 61 OnWorkerScriptLoadFailed) |
| 61 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, | 62 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, |
| 62 OnWorkerConnected) | 63 OnWorkerConnected) |
| 64 IPC_MESSAGE_HANDLER(ViewMsg_WorkerDestroyed, OnWorkerDestroyed) |
| 65 IPC_MESSAGE_HANDLER(ViewMsg_CountFeatureOnSharedWorker, OnCountFeature) |
| 63 IPC_MESSAGE_UNHANDLED(handled = false) | 66 IPC_MESSAGE_UNHANDLED(handled = false) |
| 64 IPC_END_MESSAGE_MAP() | 67 IPC_END_MESSAGE_MAP() |
| 65 return handled; | 68 return handled; |
| 66 } | 69 } |
| 67 | 70 |
| 68 void WebSharedWorkerProxy::OnWorkerCreated() { | 71 void WebSharedWorkerProxy::OnWorkerCreated() { |
| 69 // The worker is created - now send off the connection request. | 72 // The worker is created - now send off the connection request. |
| 70 router_->Send( | 73 router_->Send( |
| 71 new ViewHostMsg_ConnectToWorker(route_id_, message_port_id_)); | 74 new ViewHostMsg_ConnectToWorker(route_id_, message_port_id_)); |
| 72 } | 75 } |
| 73 | 76 |
| 74 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { | 77 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { |
| 75 listener_->scriptLoadFailed(); | 78 listener_->scriptLoadFailed(); |
| 76 delete this; | 79 delete this; |
| 77 } | 80 } |
| 78 | 81 |
| 79 void WebSharedWorkerProxy::OnWorkerConnected() { | 82 void WebSharedWorkerProxy::OnWorkerConnected(std::vector<char> features) { |
| 80 listener_->connected(); | 83 listener_->connected(); |
| 84 WorkerUseCounter counter(features); |
| 85 for (size_t i = 0; i < counter.GetNumberOfBits(); ++i) { |
| 86 if (!counter.IsCounted(i)) |
| 87 continue; |
| 88 listener_->countFeature(i); |
| 89 } |
| 90 } |
| 91 |
| 92 void WebSharedWorkerProxy::OnWorkerDestroyed() { |
| 81 delete this; | 93 delete this; |
| 82 } | 94 } |
| 83 | 95 |
| 96 void WebSharedWorkerProxy::OnCountFeature(uint32_t feature) { |
| 97 listener_->countFeature(feature); |
| 98 } |
| 99 |
| 84 } // namespace content | 100 } // namespace content |
| OLD | NEW |