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)) { | |
26 } | 25 } |
27 | 26 |
28 Dispatcher::~Dispatcher() { | 27 Dispatcher::~Dispatcher() { |
29 } | 28 } |
30 | 29 |
31 InterfaceProxy* Dispatcher::GetInterfaceProxy(InterfaceID id) { | 30 InterfaceProxy* Dispatcher::GetInterfaceProxy(InterfaceID id) { |
32 InterfaceProxy* proxy = proxies_[id].get(); | 31 InterfaceProxy* proxy = proxies_[id].get(); |
33 if (!proxy) { | 32 if (!proxy) { |
34 // Handle the first time for a given API by creating the proxy for it. | 33 // Handle the first time for a given API by creating the proxy for it. |
35 InterfaceProxy::Factory factory = | 34 InterfaceProxy::Factory factory = |
(...skipping 12 matching lines...) Expand all Loading... |
48 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { | 47 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { |
49 return delegate()->GetIPCMessageLoop(); | 48 return delegate()->GetIPCMessageLoop(); |
50 } | 49 } |
51 | 50 |
52 void Dispatcher::AddIOThreadMessageFilter( | 51 void Dispatcher::AddIOThreadMessageFilter( |
53 IPC::ChannelProxy::MessageFilter* filter) { | 52 IPC::ChannelProxy::MessageFilter* filter) { |
54 channel()->AddFilter(filter); | 53 channel()->AddFilter(filter); |
55 } | 54 } |
56 | 55 |
57 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { | 56 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 | |
69 if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { | 57 if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { |
70 OnInvalidMessageReceived(); | 58 OnInvalidMessageReceived(); |
71 return true; | 59 return true; |
72 } | 60 } |
73 | 61 |
74 InterfaceProxy* proxy = GetInterfaceProxy( | 62 InterfaceProxy* proxy = GetInterfaceProxy( |
75 static_cast<InterfaceID>(msg.routing_id())); | 63 static_cast<InterfaceID>(msg.routing_id())); |
76 if (!proxy) { | 64 if (!proxy) { |
77 NOTREACHED(); | 65 NOTREACHED(); |
78 return true; | 66 return true; |
79 } | 67 } |
80 return proxy->OnMessageReceived(msg); | 68 return proxy->OnMessageReceived(msg); |
81 } | 69 } |
82 | 70 |
83 void Dispatcher::SetSerializationRules( | 71 void Dispatcher::SetSerializationRules( |
84 VarSerializationRules* var_serialization_rules) { | 72 VarSerializationRules* var_serialization_rules) { |
85 serialization_rules_.reset(var_serialization_rules); | 73 serialization_rules_.reset(var_serialization_rules); |
86 } | 74 } |
87 | 75 |
88 void Dispatcher::OnInvalidMessageReceived() { | 76 void Dispatcher::OnInvalidMessageReceived() { |
89 } | 77 } |
90 | 78 |
91 } // namespace proxy | 79 } // namespace proxy |
92 } // namespace ppapi | 80 } // namespace ppapi |
OLD | NEW |