Chromium Code Reviews| Index: ppapi/proxy/plugin_globals.cc |
| diff --git a/ppapi/proxy/plugin_globals.cc b/ppapi/proxy/plugin_globals.cc |
| index fa5530e4390f53022ca2e22f8192d0ec237e7b67..563ff8ad151d7ac3b436fbcdceb557f8081cdf0e 100644 |
| --- a/ppapi/proxy/plugin_globals.cc |
| +++ b/ppapi/proxy/plugin_globals.cc |
| @@ -10,10 +10,17 @@ |
| #include "ipc/ipc_sender.h" |
| #include "ppapi/proxy/plugin_dispatcher.h" |
| #include "ppapi/proxy/plugin_proxy_delegate.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| #include "ppapi/proxy/ppb_message_loop_proxy.h" |
| #include "ppapi/shared_impl/proxy_lock.h" |
| #include "ppapi/thunk/enter.h" |
| +namespace { |
| + |
| +const int kKeepaliveThrottleIntervalDefault = 5000; |
| + |
| +} // namespace |
| + |
| namespace ppapi { |
| namespace proxy { |
| @@ -51,7 +58,12 @@ PluginGlobals* PluginGlobals::plugin_globals_ = NULL; |
| PluginGlobals::PluginGlobals() |
| : ppapi::PpapiGlobals(), |
| plugin_proxy_delegate_(NULL), |
| - callback_tracker_(new CallbackTracker) { |
| + callback_tracker_(new CallbackTracker), |
| + plugin_recently_active_(false), |
| + keep_aliave_throttle_interval_milliseconds_( |
| + kKeepaliveThrottleIntervalDefault), |
| + weak_factory_(this) |
| + { |
|
yzshen1
2013/12/13 21:23:15
On the previous line, please.
scheib
2013/12/14 00:07:41
Done.
|
| DCHECK(!plugin_globals_); |
| plugin_globals_ = this; |
| @@ -66,7 +78,9 @@ PluginGlobals::PluginGlobals() |
| PluginGlobals::PluginGlobals(PerThreadForTest per_thread_for_test) |
| : ppapi::PpapiGlobals(per_thread_for_test), |
| plugin_proxy_delegate_(NULL), |
| - callback_tracker_(new CallbackTracker) { |
| + callback_tracker_(new CallbackTracker), |
| + plugin_recently_active_(false), |
|
yzshen1
2013/12/13 21:23:15
Please also init keep_alive_throttle_interval_mill
scheib
2013/12/14 00:07:41
Done.
|
| + weak_factory_(this) { |
| DCHECK(!plugin_globals_); |
| } |
| @@ -160,6 +174,21 @@ base::TaskRunner* PluginGlobals::GetFileTaskRunner() { |
| return file_thread_->message_loop_proxy(); |
| } |
| +void PluginGlobals::MarkPluginIsActive() { |
| + if (!plugin_recently_active_) { |
| + plugin_recently_active_ = true; |
| + if (!GetBrowserSender() || !base::MessageLoop::current()) |
| + return; |
| + GetBrowserSender()->Send(new PpapiHostMsg_Keepalive()); |
| + |
| + base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + base::Bind(&PluginGlobals::OnReleaseKeepaliveThrottle, |
| + weak_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds( |
| + keep_aliave_throttle_interval_milliseconds())); |
| + } |
| +} |
| + |
| IPC::Sender* PluginGlobals::GetBrowserSender() { |
| if (!browser_sender_.get()) { |
| browser_sender_.reset( |
| @@ -190,9 +219,22 @@ MessageLoopResource* PluginGlobals::loop_for_main_thread() { |
| return loop_for_main_thread_.get(); |
| } |
| +int PluginGlobals::keep_aliave_throttle_interval_milliseconds() { |
| + return keep_aliave_throttle_interval_milliseconds_; |
| +} |
| + |
| +void PluginGlobals::set_keep_aliave_throttle_interval_milliseconds(int i) { |
| + keep_aliave_throttle_interval_milliseconds_ = i; |
| +} |
| + |
| bool PluginGlobals::IsPluginGlobals() const { |
| return true; |
| } |
| +void PluginGlobals::OnReleaseKeepaliveThrottle() { |
| + ppapi::ProxyAutoLock lock; |
| + plugin_recently_active_ = false; |
| +} |
| + |
| } // namespace proxy |
| } // namespace ppapi |