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

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: diii 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..46c988a80f3114594b1759c1890add14e32eba22 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"
@@ -28,6 +29,7 @@
#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/plugin_proxy_delegate.h"
#include "ppapi/shared_impl/ppb_audio_shared.h"
+#include "ppapi/shared_impl/proxy_lock.h"
#if defined(IPC_MESSAGE_LOG_ENABLED)
#include "base/containers/hash_tables.h"
@@ -53,6 +55,12 @@ using ppapi::proxy::SerializedHandle;
namespace {
+// Interval to check if plugin has been active and report to the browser
+// process. The value is somewhat arbitrary. It should be large enough to
+// minimize computation overhead and small enough to not add exessive latency
+// to detecting idle processes.
+const int kIdleCheckIntervalInSeconds = 5;
+
// This class manages communication between the plugin and the browser, and
// manages the PluginDispatcher instances for communication between the plugin
// and the renderer.
@@ -257,6 +265,24 @@ void PpapiDispatcher::OnPluginDispatcherMessageReceived(
dispatcher->second->OnMessageReceived(msg);
}
+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
+ ppapi::ProxyAutoLock lock;
+ if (!PluginGlobals::Get())
+ return;
+
+ bool was_active = PluginGlobals::Get()->plugin_has_been_active();
+ PluginGlobals::Get()->set_plugin_has_been_active(false);
+
+ if (last_was_active != was_active) {
+ PluginGlobals::Get()->GetBrowserSender()->Send(
+ new PpapiHostMsg_IdleStateChange(!was_active));
+ }
+
+ base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ base::Bind(&CheckActivity, was_active),
+ base::TimeDelta::FromSeconds(kIdleCheckIntervalInSeconds));
+}
+
} // namespace
void PpapiPluginRegisterThreadCreator(
@@ -289,6 +315,9 @@ int PpapiPluginMain() {
PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
+ base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ base::Bind(&CheckActivity, false),
+ base::TimeDelta::FromSeconds(kIdleCheckIntervalInSeconds));
loop.Run();
return 0;

Powered by Google App Engine
This is Rietveld 408576698