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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/plugin_main_nacl.cc
diff --git a/ppapi/proxy/plugin_main_nacl.cc b/ppapi/proxy/plugin_main_nacl.cc
index f050778227cad4eef35c4f1c26f59fe1a6ccbcbe..368f709bf6800c49f878e2fcbbcc48e8a7119601 100644
--- a/ppapi/proxy/plugin_main_nacl.cc
+++ b/ppapi/proxy/plugin_main_nacl.cc
@@ -12,6 +12,7 @@
// ViewMsgLog et al. functions.
#include "base/command_line.h"
+#include "base/debug/trace_event.h"
#include "base/message_loop/message_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
@@ -266,6 +267,23 @@ void PpapiPluginRegisterThreadCreator(
ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions);
}
+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.
+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.
+
+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.
+ 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.
+ PluginGlobals::Get()->set_plugin_has_been_active(false);
+
+ if (last_was_active != was_active) {
+ PluginGlobals::Get()->GetBrowserSender()->Send(
+ 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
+ }
+ last_was_active = was_active;
+
+ 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.
+ base::TimeDelta::FromSeconds(checkIntervalInSeconds));
+}
+
int PpapiPluginMain() {
// Though it isn't referenced here, we must instantiate an AtExitManager.
base::AtExitManager exit_manager;
@@ -289,6 +307,11 @@ int PpapiPluginMain() {
PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
+ io_thread.message_loop()->PostDelayedTask(FROM_HERE,
+ 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;
+ io_thread.message_loop(),
+ &ppapi_dispatcher),
+ 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.
loop.Run();
return 0;

Powered by Google App Engine
This is Rietveld 408576698