| 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 "ppapi/proxy/dispatcher.h" | 5 #include "ppapi/proxy/dispatcher.h" |
| 6 | 6 |
| 7 #include <string.h> // For memset. | 7 #include <string.h> // For memset. |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/proxy/var_serialization_rules.h" | 15 #include "ppapi/proxy/var_serialization_rules.h" |
| 16 | 16 |
| 17 namespace ppapi { | 17 namespace ppapi { |
| 18 namespace proxy { | 18 namespace proxy { |
| 19 | 19 |
| 20 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, | 20 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, |
| 21 GetInterfaceFunc local_get_interface) | 21 GetInterfaceFunc local_get_interface) |
| 22 : ProxyChannel(remote_process_handle), | 22 : ProxyChannel(remote_process_handle), |
| 23 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. | 23 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. |
| 24 local_get_interface_(local_get_interface) { | 24 local_get_interface_(local_get_interface), |
| 25 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 Dispatcher::~Dispatcher() { | 28 Dispatcher::~Dispatcher() { |
| 28 } | 29 } |
| 29 | 30 |
| 30 InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) { | 31 InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) { |
| 31 InterfaceProxy* proxy = proxies_[id].get(); | 32 InterfaceProxy* proxy = proxies_[id].get(); |
| 32 if (!proxy) { | 33 if (!proxy) { |
| 33 // Handle the first time for a given API by creating the proxy for it. | 34 // Handle the first time for a given API by creating the proxy for it. |
| 34 InterfaceProxy::Factory factory = | 35 InterfaceProxy::Factory factory = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { | 48 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { |
| 48 return delegate()->GetIPCMessageLoop(); | 49 return delegate()->GetIPCMessageLoop(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void Dispatcher::AddIOThreadMessageFilter( | 52 void Dispatcher::AddIOThreadMessageFilter( |
| 52 IPC::ChannelProxy::MessageFilter* filter) { | 53 IPC::ChannelProxy::MessageFilter* filter) { |
| 53 channel()->AddFilter(filter); | 54 channel()->AddFilter(filter); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { | 57 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 58 // Control messages. |
| 59 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 60 bool handled = true; |
| 61 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) |
| 62 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, |
| 63 CallbackTracker::ReceiveExecuteSerializedCallback) |
| 64 IPC_MESSAGE_UNHANDLED(handled = false) |
| 65 IPC_END_MESSAGE_MAP() |
| 66 return handled; |
| 67 } |
| 68 |
| 57 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) { | 69 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) { |
| 58 OnInvalidMessageReceived(); | 70 OnInvalidMessageReceived(); |
| 59 return true; | 71 return true; |
| 60 } | 72 } |
| 61 | 73 |
| 62 InterfaceProxy* proxy = GetInterfaceProxy( | 74 InterfaceProxy* proxy = GetInterfaceProxy( |
| 63 static_cast<ApiID>(msg.routing_id())); | 75 static_cast<ApiID>(msg.routing_id())); |
| 64 if (!proxy) { | 76 if (!proxy) { |
| 65 NOTREACHED(); | 77 NOTREACHED(); |
| 66 return true; | 78 return true; |
| 67 } | 79 } |
| 68 return proxy->OnMessageReceived(msg); | 80 return proxy->OnMessageReceived(msg); |
| 69 } | 81 } |
| 70 | 82 |
| 71 void Dispatcher::SetSerializationRules( | 83 void Dispatcher::SetSerializationRules( |
| 72 VarSerializationRules* var_serialization_rules) { | 84 VarSerializationRules* var_serialization_rules) { |
| 73 serialization_rules_.reset(var_serialization_rules); | 85 serialization_rules_.reset(var_serialization_rules); |
| 74 } | 86 } |
| 75 | 87 |
| 76 void Dispatcher::OnInvalidMessageReceived() { | 88 void Dispatcher::OnInvalidMessageReceived() { |
| 77 } | 89 } |
| 78 | 90 |
| 79 } // namespace proxy | 91 } // namespace proxy |
| 80 } // namespace ppapi | 92 } // namespace ppapi |
| OLD | NEW |