OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 // Need to include this before most other files because it defines | 9 // Need to include this before most other files because it defines |
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define | 10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define |
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the | 11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the |
12 // ViewMsgLog et al. functions. | 12 // ViewMsgLog et al. functions. |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/string_number_conversions.h" | |
17 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
18 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
19 #include "components/tracing/child_trace_message_filter.h" | 18 #include "components/tracing/child_trace_message_filter.h" |
20 #include "ipc/ipc_channel_handle.h" | 19 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_logging.h" | 20 #include "ipc/ipc_logging.h" |
22 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
23 #include "native_client/src/shared/srpc/nacl_srpc.h" | 22 #include "native_client/src/shared/srpc/nacl_srpc.h" |
24 #include "native_client/src/untrusted/irt/irt_ppapi.h" | 23 #include "native_client/src/untrusted/irt/irt_ppapi.h" |
25 #include "ppapi/c/ppp.h" | 24 #include "ppapi/c/ppp.h" |
26 #include "ppapi/c/ppp_instance.h" | 25 #include "ppapi/c/ppp_instance.h" |
27 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" | 26 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" |
28 #include "ppapi/proxy/plugin_dispatcher.h" | 27 #include "ppapi/proxy/plugin_dispatcher.h" |
29 #include "ppapi/proxy/plugin_globals.h" | 28 #include "ppapi/proxy/plugin_globals.h" |
30 #include "ppapi/proxy/plugin_message_filter.h" | 29 #include "ppapi/proxy/plugin_message_filter.h" |
31 #include "ppapi/proxy/plugin_proxy_delegate.h" | 30 #include "ppapi/proxy/plugin_proxy_delegate.h" |
32 #include "ppapi/proxy/resource_reply_thread_registrar.h" | 31 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
33 #include "ppapi/shared_impl/ppapi_switches.h" | |
34 #include "ppapi/shared_impl/ppb_audio_shared.h" | 32 #include "ppapi/shared_impl/ppb_audio_shared.h" |
35 | 33 |
36 #if defined(IPC_MESSAGE_LOG_ENABLED) | 34 #if defined(IPC_MESSAGE_LOG_ENABLED) |
37 #include "base/containers/hash_tables.h" | 35 #include "base/containers/hash_tables.h" |
38 | 36 |
39 LogFunctionMap g_log_function_mapping; | 37 LogFunctionMap g_log_function_mapping; |
40 | 38 |
41 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 39 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ | 40 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ |
43 g_log_function_mapping[msg_id] = logger | 41 g_log_function_mapping[msg_id] = logger |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 88 |
91 // IPC::Listener implementation. | 89 // IPC::Listener implementation. |
92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 90 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
93 | 91 |
94 private: | 92 private: |
95 void OnMsgCreateNaClChannel(int renderer_id, | 93 void OnMsgCreateNaClChannel(int renderer_id, |
96 const ppapi::PpapiNaClChannelArgs& args, | 94 const ppapi::PpapiNaClChannelArgs& args, |
97 SerializedHandle handle); | 95 SerializedHandle handle); |
98 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); | 96 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); |
99 | 97 |
100 void SetPpapiKeepAliveThrottleFromCommandLine(); | |
101 | |
102 std::set<PP_Instance> instances_; | 98 std::set<PP_Instance> instances_; |
103 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; | 99 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; |
104 uint32 next_plugin_dispatcher_id_; | 100 uint32 next_plugin_dispatcher_id_; |
105 scoped_refptr<base::MessageLoopProxy> message_loop_; | 101 scoped_refptr<base::MessageLoopProxy> message_loop_; |
106 base::WaitableEvent shutdown_event_; | 102 base::WaitableEvent shutdown_event_; |
107 }; | 103 }; |
108 | 104 |
109 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) | 105 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) |
110 : next_plugin_dispatcher_id_(0), | 106 : next_plugin_dispatcher_id_(0), |
111 message_loop_(io_loop), | 107 message_loop_(io_loop), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (!command_line_and_logging_initialized) { | 201 if (!command_line_and_logging_initialized) { |
206 CommandLine::Init(0, NULL); | 202 CommandLine::Init(0, NULL); |
207 for (size_t i = 0; i < args.switch_names.size(); ++i) { | 203 for (size_t i = 0; i < args.switch_names.size(); ++i) { |
208 DCHECK(i < args.switch_values.size()); | 204 DCHECK(i < args.switch_values.size()); |
209 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 205 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
210 args.switch_names[i], args.switch_values[i]); | 206 args.switch_names[i], args.switch_values[i]); |
211 } | 207 } |
212 logging::LoggingSettings settings; | 208 logging::LoggingSettings settings; |
213 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 209 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
214 logging::InitLogging(settings); | 210 logging::InitLogging(settings); |
215 SetPpapiKeepAliveThrottleFromCommandLine(); | |
216 command_line_and_logging_initialized = true; | 211 command_line_and_logging_initialized = true; |
217 } | 212 } |
218 // Tell the process-global GetInterface which interfaces it can return to the | 213 // Tell the process-global GetInterface which interfaces it can return to the |
219 // plugin. | 214 // plugin. |
220 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( | 215 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( |
221 args.permissions); | 216 args.permissions); |
222 | 217 |
223 int32_t error = ::PPP_InitializeModule( | 218 int32_t error = ::PPP_InitializeModule( |
224 0 /* module */, | 219 0 /* module */, |
225 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); | 220 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); |
(...skipping 22 matching lines...) Expand all Loading... |
248 if (!msg.ReadUInt32(&iter, &id)) { | 243 if (!msg.ReadUInt32(&iter, &id)) { |
249 NOTREACHED(); | 244 NOTREACHED(); |
250 return; | 245 return; |
251 } | 246 } |
252 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 247 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
253 plugin_dispatchers_.find(id); | 248 plugin_dispatchers_.find(id); |
254 if (dispatcher != plugin_dispatchers_.end()) | 249 if (dispatcher != plugin_dispatchers_.end()) |
255 dispatcher->second->OnMessageReceived(msg); | 250 dispatcher->second->OnMessageReceived(msg); |
256 } | 251 } |
257 | 252 |
258 void PpapiDispatcher::SetPpapiKeepAliveThrottleFromCommandLine() { | |
259 unsigned keepalive_throttle_interval_milliseconds = 0; | |
260 if (base::StringToUint( | |
261 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
262 switches::kPpapiKeepAliveThrottle), | |
263 &keepalive_throttle_interval_milliseconds)) { | |
264 ppapi::proxy::PluginGlobals::Get()-> | |
265 set_keepalive_throttle_interval_milliseconds( | |
266 keepalive_throttle_interval_milliseconds); | |
267 } | |
268 } | |
269 | |
270 } // namespace | 253 } // namespace |
271 | 254 |
272 void PpapiPluginRegisterThreadCreator( | 255 void PpapiPluginRegisterThreadCreator( |
273 const struct PP_ThreadFunctions* thread_functions) { | 256 const struct PP_ThreadFunctions* thread_functions) { |
274 // Initialize all classes that need to create threads that call back into | 257 // Initialize all classes that need to create threads that call back into |
275 // user code. | 258 // user code. |
276 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); | 259 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); |
277 } | 260 } |
278 | 261 |
279 int PpapiPluginMain() { | 262 int PpapiPluginMain() { |
(...skipping 16 matching lines...) Expand all Loading... |
296 return 1; | 279 return 1; |
297 } | 280 } |
298 | 281 |
299 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 282 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
300 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 283 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
301 | 284 |
302 loop.Run(); | 285 loop.Run(); |
303 | 286 |
304 return 0; | 287 return 0; |
305 } | 288 } |
OLD | NEW |