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" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 260 |
260 } // namespace | 261 } // namespace |
261 | 262 |
262 void PpapiPluginRegisterThreadCreator( | 263 void PpapiPluginRegisterThreadCreator( |
263 const struct PP_ThreadFunctions* thread_functions) { | 264 const struct PP_ThreadFunctions* thread_functions) { |
264 // Initialize all classes that need to create threads that call back into | 265 // Initialize all classes that need to create threads that call back into |
265 // user code. | 266 // user code. |
266 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); | 267 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); |
267 } | 268 } |
268 | 269 |
270 const int checkIntervalInSeconds = 1; | |
yzshen1
2013/11/06 22:43:15
Please use kCheck....
Shall we put these two vari
scheib
2013/11/15 01:22:17
Done.
| |
271 bool last_was_active = false; | |
272 | |
273 void CheckActivity(base::MessageLoop* loop, PpapiDispatcher* dispatcher) { | |
yzshen1
2013/11/06 22:43:15
|dispatcher| is not needed, right?
scheib
2013/11/15 01:22:17
Done.
| |
274 bool was_active = PluginGlobals::Get()->plugin_has_been_active(); | |
yzshen1
2013/11/06 22:43:15
You need to lock the pepper proxy lock before you
scheib
2013/11/15 01:22:17
Done.
| |
275 PluginGlobals::Get()->set_plugin_has_been_active(false); | |
276 | |
277 if (last_was_active != was_active) { | |
278 PluginGlobals::Get()->GetBrowserSender()->Send( | |
279 new PpapiHostMsg_IdleState(!was_active)); | |
280 } | |
281 last_was_active = was_active; | |
282 | |
283 loop->PostDelayedTask(FROM_HERE, base::Bind(&CheckActivity, loop, dispatcher), | |
yzshen1
2013/11/06 22:43:15
nit: you could use MessageLoop::current() instead
scheib
2013/11/15 01:22:17
Done.
| |
284 base::TimeDelta::FromSeconds(checkIntervalInSeconds)); | |
285 } | |
286 | |
269 int PpapiPluginMain() { | 287 int PpapiPluginMain() { |
270 // Though it isn't referenced here, we must instantiate an AtExitManager. | 288 // Though it isn't referenced here, we must instantiate an AtExitManager. |
271 base::AtExitManager exit_manager; | 289 base::AtExitManager exit_manager; |
272 base::MessageLoop loop; | 290 base::MessageLoop loop; |
273 IPC::Logging::set_log_function_map(&g_log_function_mapping); | 291 IPC::Logging::set_log_function_map(&g_log_function_mapping); |
274 ppapi::proxy::PluginGlobals plugin_globals; | 292 ppapi::proxy::PluginGlobals plugin_globals; |
275 base::Thread io_thread("Chrome_NaClIOThread"); | 293 base::Thread io_thread("Chrome_NaClIOThread"); |
276 base::Thread::Options options; | 294 base::Thread::Options options; |
277 options.message_loop_type = base::MessageLoop::TYPE_IO; | 295 options.message_loop_type = base::MessageLoop::TYPE_IO; |
278 io_thread.StartWithOptions(options); | 296 io_thread.StartWithOptions(options); |
279 | 297 |
280 // Start up the SRPC server on another thread. Otherwise, when it blocks | 298 // Start up the SRPC server on another thread. Otherwise, when it blocks |
281 // on an RPC, the PPAPI proxy will hang. Do this before we initialize the | 299 // on an RPC, the PPAPI proxy will hang. Do this before we initialize the |
282 // module and start the PPAPI proxy so that the NaCl plugin can continue | 300 // module and start the PPAPI proxy so that the NaCl plugin can continue |
283 // loading the app. | 301 // loading the app. |
284 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; | 302 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; |
285 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { | 303 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { |
286 return 1; | 304 return 1; |
287 } | 305 } |
288 | 306 |
289 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 307 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
290 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 308 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
291 | 309 |
310 io_thread.message_loop()->PostDelayedTask(FROM_HERE, | |
311 base::Bind(&CheckActivity, | |
312 io_thread.message_loop(), | |
313 &ppapi_dispatcher), | |
314 base::TimeDelta::FromSeconds(checkIntervalInSeconds)); | |
yzshen1
2013/11/06 22:43:15
wrong indent.
scheib
2013/11/15 01:22:17
Done.
| |
292 loop.Run(); | 315 loop.Run(); |
293 | 316 |
294 return 0; | 317 return 0; |
295 } | 318 } |
OLD | NEW |