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_message_filter.h" | 30 #include "ppapi/proxy/plugin_message_filter.h" |
30 #include "ppapi/proxy/plugin_proxy_delegate.h" | 31 #include "ppapi/proxy/plugin_proxy_delegate.h" |
31 #include "ppapi/proxy/resource_reply_thread_registrar.h" | 32 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
| 33 #include "ppapi/shared_impl/ppapi_switches.h" |
32 #include "ppapi/shared_impl/ppb_audio_shared.h" | 34 #include "ppapi/shared_impl/ppb_audio_shared.h" |
33 | 35 |
34 #if defined(IPC_MESSAGE_LOG_ENABLED) | 36 #if defined(IPC_MESSAGE_LOG_ENABLED) |
35 #include "base/containers/hash_tables.h" | 37 #include "base/containers/hash_tables.h" |
36 | 38 |
37 LogFunctionMap g_log_function_mapping; | 39 LogFunctionMap g_log_function_mapping; |
38 | 40 |
39 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 41 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
40 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ | 42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ |
41 g_log_function_mapping[msg_id] = logger | 43 g_log_function_mapping[msg_id] = logger |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 90 |
89 // IPC::Listener implementation. | 91 // IPC::Listener implementation. |
90 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
91 | 93 |
92 private: | 94 private: |
93 void OnMsgCreateNaClChannel(int renderer_id, | 95 void OnMsgCreateNaClChannel(int renderer_id, |
94 const ppapi::PpapiNaClChannelArgs& args, | 96 const ppapi::PpapiNaClChannelArgs& args, |
95 SerializedHandle handle); | 97 SerializedHandle handle); |
96 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); | 98 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); |
97 | 99 |
| 100 void SetPpapiKeepAliveThrottleFromCommandLine(); |
| 101 |
98 std::set<PP_Instance> instances_; | 102 std::set<PP_Instance> instances_; |
99 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; | 103 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; |
100 uint32 next_plugin_dispatcher_id_; | 104 uint32 next_plugin_dispatcher_id_; |
101 scoped_refptr<base::MessageLoopProxy> message_loop_; | 105 scoped_refptr<base::MessageLoopProxy> message_loop_; |
102 base::WaitableEvent shutdown_event_; | 106 base::WaitableEvent shutdown_event_; |
103 }; | 107 }; |
104 | 108 |
105 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) | 109 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) |
106 : next_plugin_dispatcher_id_(0), | 110 : next_plugin_dispatcher_id_(0), |
107 message_loop_(io_loop), | 111 message_loop_(io_loop), |
(...skipping 93 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 22 matching lines...) Expand all Loading... |
243 if (!msg.ReadUInt32(&iter, &id)) { | 248 if (!msg.ReadUInt32(&iter, &id)) { |
244 NOTREACHED(); | 249 NOTREACHED(); |
245 return; | 250 return; |
246 } | 251 } |
247 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 252 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
248 plugin_dispatchers_.find(id); | 253 plugin_dispatchers_.find(id); |
249 if (dispatcher != plugin_dispatchers_.end()) | 254 if (dispatcher != plugin_dispatchers_.end()) |
250 dispatcher->second->OnMessageReceived(msg); | 255 dispatcher->second->OnMessageReceived(msg); |
251 } | 256 } |
252 | 257 |
| 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 |
253 } // namespace | 270 } // namespace |
254 | 271 |
255 void PpapiPluginRegisterThreadCreator( | 272 void PpapiPluginRegisterThreadCreator( |
256 const struct PP_ThreadFunctions* thread_functions) { | 273 const struct PP_ThreadFunctions* thread_functions) { |
257 // Initialize all classes that need to create threads that call back into | 274 // Initialize all classes that need to create threads that call back into |
258 // user code. | 275 // user code. |
259 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); | 276 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); |
260 } | 277 } |
261 | 278 |
262 int PpapiPluginMain() { | 279 int PpapiPluginMain() { |
(...skipping 16 matching lines...) Expand all Loading... |
279 return 1; | 296 return 1; |
280 } | 297 } |
281 | 298 |
282 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 299 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
283 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 300 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
284 | 301 |
285 loop.Run(); | 302 loop.Run(); |
286 | 303 |
287 return 0; | 304 return 0; |
288 } | 305 } |
OLD | NEW |