Chromium Code Reviews| 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/debug/trace_event.h" | |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.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" |
| 30 #include "ppapi/shared_impl/ppb_audio_shared.h" | 31 #include "ppapi/shared_impl/ppb_audio_shared.h" |
| 32 #include "ppapi/shared_impl/proxy_lock.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 |
| 40 | 42 |
| 41 #endif | 43 #endif |
| 42 #include "ppapi/proxy/ppapi_messages.h" | 44 #include "ppapi/proxy/ppapi_messages.h" |
| 43 | 45 |
| 44 // This must match up with NACL_CHROME_INITIAL_IPC_DESC, | 46 // This must match up with NACL_CHROME_INITIAL_IPC_DESC, |
| 45 // defined in sel_main_chrome.h | 47 // defined in sel_main_chrome.h |
| 46 #define NACL_IPC_FD 6 | 48 #define NACL_IPC_FD 6 |
| 47 | 49 |
| 48 using ppapi::proxy::PluginDispatcher; | 50 using ppapi::proxy::PluginDispatcher; |
| 49 using ppapi::proxy::PluginGlobals; | 51 using ppapi::proxy::PluginGlobals; |
| 50 using ppapi::proxy::PluginProxyDelegate; | 52 using ppapi::proxy::PluginProxyDelegate; |
| 51 using ppapi::proxy::ProxyChannel; | 53 using ppapi::proxy::ProxyChannel; |
| 52 using ppapi::proxy::SerializedHandle; | 54 using ppapi::proxy::SerializedHandle; |
| 53 | 55 |
| 54 namespace { | 56 namespace { |
| 55 | 57 |
| 58 // Interval to check if plugin has been active and report to the browser | |
| 59 // process. The value is somewhat arbitrary. It should be large enough to | |
| 60 // minimize computation overhead and small enough to not add exessive latency | |
| 61 // to detecting idle processes. | |
| 62 const int kIdleCheckIntervalInSeconds = 5; | |
| 63 | |
| 56 // This class manages communication between the plugin and the browser, and | 64 // This class manages communication between the plugin and the browser, and |
| 57 // manages the PluginDispatcher instances for communication between the plugin | 65 // manages the PluginDispatcher instances for communication between the plugin |
| 58 // and the renderer. | 66 // and the renderer. |
| 59 class PpapiDispatcher : public ProxyChannel, | 67 class PpapiDispatcher : public ProxyChannel, |
| 60 public PluginDispatcher::PluginDelegate, | 68 public PluginDispatcher::PluginDelegate, |
| 61 public PluginProxyDelegate { | 69 public PluginProxyDelegate { |
| 62 public: | 70 public: |
| 63 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); | 71 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); |
| 64 | 72 |
| 65 // PluginDispatcher::PluginDelegate implementation. | 73 // PluginDispatcher::PluginDelegate implementation. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 if (!msg.ReadUInt32(&iter, &id)) { | 258 if (!msg.ReadUInt32(&iter, &id)) { |
| 251 NOTREACHED(); | 259 NOTREACHED(); |
| 252 return; | 260 return; |
| 253 } | 261 } |
| 254 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 262 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
| 255 plugin_dispatchers_.find(id); | 263 plugin_dispatchers_.find(id); |
| 256 if (dispatcher != plugin_dispatchers_.end()) | 264 if (dispatcher != plugin_dispatchers_.end()) |
| 257 dispatcher->second->OnMessageReceived(msg); | 265 dispatcher->second->OnMessageReceived(msg); |
| 258 } | 266 } |
| 259 | 267 |
| 268 void CheckActivity(bool last_was_active) { | |
|
Mark Seaborn
2013/11/15 23:51:24
It looks like this will make every NaCl process wa
scheib
2013/12/11 21:35:40
Done by having the plugin only report when it is a
| |
| 269 ppapi::ProxyAutoLock lock; | |
| 270 if (!PluginGlobals::Get()) | |
| 271 return; | |
| 272 | |
| 273 bool was_active = PluginGlobals::Get()->plugin_has_been_active(); | |
| 274 PluginGlobals::Get()->set_plugin_has_been_active(false); | |
| 275 | |
| 276 if (last_was_active != was_active) { | |
| 277 PluginGlobals::Get()->GetBrowserSender()->Send( | |
| 278 new PpapiHostMsg_IdleStateChange(!was_active)); | |
| 279 } | |
| 280 | |
| 281 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 282 base::Bind(&CheckActivity, was_active), | |
| 283 base::TimeDelta::FromSeconds(kIdleCheckIntervalInSeconds)); | |
| 284 } | |
| 285 | |
| 260 } // namespace | 286 } // namespace |
| 261 | 287 |
| 262 void PpapiPluginRegisterThreadCreator( | 288 void PpapiPluginRegisterThreadCreator( |
| 263 const struct PP_ThreadFunctions* thread_functions) { | 289 const struct PP_ThreadFunctions* thread_functions) { |
| 264 // Initialize all classes that need to create threads that call back into | 290 // Initialize all classes that need to create threads that call back into |
| 265 // user code. | 291 // user code. |
| 266 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); | 292 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); |
| 267 } | 293 } |
| 268 | 294 |
| 269 int PpapiPluginMain() { | 295 int PpapiPluginMain() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 282 // module and start the PPAPI proxy so that the NaCl plugin can continue | 308 // module and start the PPAPI proxy so that the NaCl plugin can continue |
| 283 // loading the app. | 309 // loading the app. |
| 284 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; | 310 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; |
| 285 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { | 311 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { |
| 286 return 1; | 312 return 1; |
| 287 } | 313 } |
| 288 | 314 |
| 289 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 315 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
| 290 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 316 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
| 291 | 317 |
| 318 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 319 base::Bind(&CheckActivity, false), | |
| 320 base::TimeDelta::FromSeconds(kIdleCheckIntervalInSeconds)); | |
| 292 loop.Run(); | 321 loop.Run(); |
| 293 | 322 |
| 294 return 0; | 323 return 0; |
| 295 } | 324 } |
| OLD | NEW |