Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: ppapi/proxy/plugin_main_nacl.cc

Issue 61063003: Keep NaCl plugins used in app background pages alive when active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: working prototype Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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;
dmichael (off chromium) 2013/11/06 22:39:21 nit: kCheckIntervalInSeconds Some rationale about
scheib 2013/11/15 01:22:17 Done.
271 bool last_was_active = false;
dmichael (off chromium) 2013/11/06 22:39:21 Could this be a parameter to CheckActivity instead
scheib 2013/11/15 01:22:17 Done.
272
273 void CheckActivity(base::MessageLoop* loop, PpapiDispatcher* dispatcher) {
dmichael (off chromium) 2013/11/06 22:39:21 You're not using dispatcher, and it will become in
scheib 2013/11/15 01:22:17 Done.
274 bool was_active = PluginGlobals::Get()->plugin_has_been_active();
dmichael (off chromium) 2013/11/06 22:39:21 At shutdown, PluginGlobals()::Get() will be NULL.
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));
dmichael (off chromium) 2013/11/06 22:39:21 So we're only sending a message if the state chang
scheib 2013/11/07 01:06:42 I think it is what we want. Browser side we are tr
dmichael (off chromium) 2013/11/07 17:11:55 Sounds good. I wrote this comment before I'd read
280 }
281 last_was_active = was_active;
282
283 loop->PostDelayedTask(FROM_HERE, base::Bind(&CheckActivity, loop, dispatcher),
dmichael (off chromium) 2013/11/06 22:39:21 Why not use MessageLoop::current()? I'm not used t
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,
dmichael (off chromium) 2013/11/06 22:39:21 CheckActivity needs to have the global proxy lock,
scheib 2013/11/15 01:22:17 Done via: ppapi::ProxyAutoLock lock;
312 io_thread.message_loop(),
313 &ppapi_dispatcher),
314 base::TimeDelta::FromSeconds(checkIntervalInSeconds));
dmichael (off chromium) 2013/11/06 22:39:21 (nit: all the arguments should just be indented by
scheib 2013/11/15 01:22:17 Done.
292 loop.Run(); 315 loop.Run();
293 316
294 return 0; 317 return 0;
295 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698