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" |
16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "components/tracing/child_trace_message_filter.h" | 19 #include "components/tracing/child_trace_message_filter.h" |
19 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
20 #include "ipc/ipc_logging.h" | 21 #include "ipc/ipc_logging.h" |
21 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
22 #include "native_client/src/shared/srpc/nacl_srpc.h" | 23 #include "native_client/src/shared/srpc/nacl_srpc.h" |
23 #include "native_client/src/untrusted/irt/irt_ppapi.h" | 24 #include "native_client/src/untrusted/irt/irt_ppapi.h" |
24 #include "ppapi/c/ppp.h" | 25 #include "ppapi/c/ppp.h" |
25 #include "ppapi/c/ppp_instance.h" | 26 #include "ppapi/c/ppp_instance.h" |
26 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" | 27 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" |
27 #include "ppapi/proxy/plugin_dispatcher.h" | 28 #include "ppapi/proxy/plugin_dispatcher.h" |
28 #include "ppapi/proxy/plugin_globals.h" | 29 #include "ppapi/proxy/plugin_globals.h" |
29 #include "ppapi/proxy/plugin_proxy_delegate.h" | 30 #include "ppapi/proxy/plugin_proxy_delegate.h" |
| 31 #include "ppapi/shared_impl/ppapi_switches.h" |
30 #include "ppapi/shared_impl/ppb_audio_shared.h" | 32 #include "ppapi/shared_impl/ppb_audio_shared.h" |
31 | 33 |
32 #if defined(IPC_MESSAGE_LOG_ENABLED) | 34 #if defined(IPC_MESSAGE_LOG_ENABLED) |
33 #include "base/containers/hash_tables.h" | 35 #include "base/containers/hash_tables.h" |
34 | 36 |
35 LogFunctionMap g_log_function_mapping; | 37 LogFunctionMap g_log_function_mapping; |
36 | 38 |
37 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 39 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
38 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ | 40 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ |
39 g_log_function_mapping[msg_id] = logger | 41 g_log_function_mapping[msg_id] = logger |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 91 |
90 private: | 92 private: |
91 void OnMsgCreateNaClChannel(int renderer_id, | 93 void OnMsgCreateNaClChannel(int renderer_id, |
92 const ppapi::PpapiNaClChannelArgs& args, | 94 const ppapi::PpapiNaClChannelArgs& args, |
93 SerializedHandle handle); | 95 SerializedHandle handle); |
94 void OnMsgResourceReply( | 96 void OnMsgResourceReply( |
95 const ppapi::proxy::ResourceMessageReplyParams& reply_params, | 97 const ppapi::proxy::ResourceMessageReplyParams& reply_params, |
96 const IPC::Message& nested_msg); | 98 const IPC::Message& nested_msg); |
97 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); | 99 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); |
98 | 100 |
| 101 void SetPpapiKeepAliveThrottleFromCommandLine(); |
| 102 |
99 std::set<PP_Instance> instances_; | 103 std::set<PP_Instance> instances_; |
100 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; | 104 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; |
101 uint32 next_plugin_dispatcher_id_; | 105 uint32 next_plugin_dispatcher_id_; |
102 scoped_refptr<base::MessageLoopProxy> message_loop_; | 106 scoped_refptr<base::MessageLoopProxy> message_loop_; |
103 base::WaitableEvent shutdown_event_; | 107 base::WaitableEvent shutdown_event_; |
104 }; | 108 }; |
105 | 109 |
106 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) | 110 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) |
107 : next_plugin_dispatcher_id_(0), | 111 : next_plugin_dispatcher_id_(0), |
108 message_loop_(io_loop), | 112 message_loop_(io_loop), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (!command_line_and_logging_initialized) { | 205 if (!command_line_and_logging_initialized) { |
202 CommandLine::Init(0, NULL); | 206 CommandLine::Init(0, NULL); |
203 for (size_t i = 0; i < args.switch_names.size(); ++i) { | 207 for (size_t i = 0; i < args.switch_names.size(); ++i) { |
204 DCHECK(i < args.switch_values.size()); | 208 DCHECK(i < args.switch_values.size()); |
205 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 209 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
206 args.switch_names[i], args.switch_values[i]); | 210 args.switch_names[i], args.switch_values[i]); |
207 } | 211 } |
208 logging::LoggingSettings settings; | 212 logging::LoggingSettings settings; |
209 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 213 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
210 logging::InitLogging(settings); | 214 logging::InitLogging(settings); |
| 215 SetPpapiKeepAliveThrottleFromCommandLine(); |
211 command_line_and_logging_initialized = true; | 216 command_line_and_logging_initialized = true; |
212 } | 217 } |
213 // Tell the process-global GetInterface which interfaces it can return to the | 218 // Tell the process-global GetInterface which interfaces it can return to the |
214 // plugin. | 219 // plugin. |
215 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( | 220 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( |
216 args.permissions); | 221 args.permissions); |
217 | 222 |
218 int32_t error = ::PPP_InitializeModule( | 223 int32_t error = ::PPP_InitializeModule( |
219 0 /* module */, | 224 0 /* module */, |
220 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); | 225 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); |
(...skipping 29 matching lines...) Expand all Loading... |
250 if (!msg.ReadUInt32(&iter, &id)) { | 255 if (!msg.ReadUInt32(&iter, &id)) { |
251 NOTREACHED(); | 256 NOTREACHED(); |
252 return; | 257 return; |
253 } | 258 } |
254 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 259 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
255 plugin_dispatchers_.find(id); | 260 plugin_dispatchers_.find(id); |
256 if (dispatcher != plugin_dispatchers_.end()) | 261 if (dispatcher != plugin_dispatchers_.end()) |
257 dispatcher->second->OnMessageReceived(msg); | 262 dispatcher->second->OnMessageReceived(msg); |
258 } | 263 } |
259 | 264 |
| 265 void PpapiDispatcher::SetPpapiKeepAliveThrottleFromCommandLine() { |
| 266 unsigned keepalive_throttle_interval_milliseconds = 0; |
| 267 if (base::StringToUint( |
| 268 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 269 switches::kPpapiKeepAliveThrottle), |
| 270 &keepalive_throttle_interval_milliseconds)) { |
| 271 ppapi::proxy::PluginGlobals::Get()-> |
| 272 set_keepalive_throttle_interval_milliseconds( |
| 273 keepalive_throttle_interval_milliseconds); |
| 274 } |
| 275 } |
| 276 |
260 } // namespace | 277 } // namespace |
261 | 278 |
262 void PpapiPluginRegisterThreadCreator( | 279 void PpapiPluginRegisterThreadCreator( |
263 const struct PP_ThreadFunctions* thread_functions) { | 280 const struct PP_ThreadFunctions* thread_functions) { |
264 // Initialize all classes that need to create threads that call back into | 281 // Initialize all classes that need to create threads that call back into |
265 // user code. | 282 // user code. |
266 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); | 283 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); |
267 } | 284 } |
268 | 285 |
269 int PpapiPluginMain() { | 286 int PpapiPluginMain() { |
(...skipping 16 matching lines...) Expand all Loading... |
286 return 1; | 303 return 1; |
287 } | 304 } |
288 | 305 |
289 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 306 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
290 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 307 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
291 | 308 |
292 loop.Run(); | 309 loop.Run(); |
293 | 310 |
294 return 0; | 311 return 0; |
295 } | 312 } |
OLD | NEW |