Chromium Code Reviews| Index: content/renderer/pepper/plugin_instance_throttler_impl.cc |
| diff --git a/content/renderer/pepper/plugin_instance_throttler_impl.cc b/content/renderer/pepper/plugin_instance_throttler_impl.cc |
| index 593fb99d7fadb924a36c0e4cd68100d9ef121719..5880ed98c292e50a9501fb3c621a38c309fe299d 100644 |
| --- a/content/renderer/pepper/plugin_instance_throttler_impl.cc |
| +++ b/content/renderer/pepper/plugin_instance_throttler_impl.cc |
| @@ -9,7 +9,6 @@ |
| #include "content/public/common/content_constants.h" |
| #include "content/public/renderer/render_thread.h" |
| #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| -#include "content/renderer/pepper/pepper_webplugin_impl.h" |
| #include "content/renderer/render_frame_impl.h" |
| #include "ppapi/shared_impl/ppapi_constants.h" |
| #include "ppapi/shared_impl/scoped_pp_var.h" |
| @@ -36,6 +35,37 @@ const int kMinimumConsecutiveInterestingFrames = 4; |
| // poster image. Chosen arbitrarily. |
| const int kAudioThrottledFrameTimeoutMilliseconds = 500; |
| +class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer { |
| + public: |
| + explicit PowerSaverTestPluginDelegate( |
| + const PluginInstanceThrottlerImpl* throttler) |
| + : throttler_(throttler) {} |
| + |
| + virtual ~PowerSaverTestPluginDelegate() {} |
| + |
| + private: |
| + void OnThrottleStateChange() override { |
| + if (throttler_->GetWebPlugin() && throttler_->GetWebPlugin()->instance()) { |
| + throttler_->GetWebPlugin()->instance()->HandleMessage(ppapi::ScopedPPVar( |
| + ppapi::ScopedPPVar::PassRef(), |
| + ppapi::StringVar::StringToPPVar("throttleStatusChange"))); |
| + } |
| + } |
| + |
| + void OnPeripheralStateChange() override { |
| + if (throttler_->GetWebPlugin() && throttler_->GetWebPlugin()->instance()) { |
| + throttler_->GetWebPlugin()->instance()->HandleMessage(ppapi::ScopedPPVar( |
| + ppapi::ScopedPPVar::PassRef(), |
| + ppapi::StringVar::StringToPPVar("peripheralStatusChange"))); |
| + } |
| + } |
| + |
| + void OnThrottlerDestroyed() override { delete this; } |
| + |
| + // Non-owning pointer. |
| + const PluginInstanceThrottlerImpl* const throttler_; |
| +}; |
| + |
| } // namespace |
| // static |
| @@ -101,16 +131,10 @@ void PluginInstanceThrottlerImpl::MarkPluginEssential( |
| state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| RecordUnthrottleMethodMetric(method); |
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); |
| + |
| if (was_throttled) |
| FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
| - |
| - // Notify the Power Saver test plugin of a peripheral status change. |
| - if (web_plugin_ && web_plugin_->instance() && |
| - plugin_module_name_ == ppapi::kPowerSaverTestPluginName) { |
| - web_plugin_->instance()->HandleMessage(ppapi::ScopedPPVar( |
| - ppapi::ScopedPPVar::PassRef(), |
| - ppapi::StringVar::StringToPPVar("peripheralStatusChange"))); |
| - } |
| } |
| void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { |
| @@ -118,7 +142,7 @@ void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { |
| FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); |
| } |
| -blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const { |
| +PepperWebPluginImpl* PluginInstanceThrottlerImpl::GetWebPlugin() const { |
| DCHECK(web_plugin_); |
| return web_plugin_; |
| } |
| @@ -143,7 +167,6 @@ void PluginInstanceThrottlerImpl::Initialize( |
| const GURL& content_origin, |
| const std::string& plugin_module_name, |
| const gfx::Size& unobscured_size) { |
| - plugin_module_name_ = plugin_module_name; |
| unobscured_size_ = unobscured_size; |
| // |frame| may be nullptr in tests. |
| @@ -162,6 +185,11 @@ void PluginInstanceThrottlerImpl::Initialize( |
| return; |
| } |
| + if (plugin_module_name == ppapi::kPowerSaverTestPluginName) { |
| + // Delegate manages its own lifetime. |
| + new PowerSaverTestPluginDelegate(this); |
| + } |
|
raymes
2015/04/30 00:42:07
It still feels a bit nasty to have the observer ad
tommycli
2015/04/30 01:27:10
That's a good idea. Will do that!
|
| + |
| // To collect UMAs, register peripheral content even if power saver mode |
| // is disabled. |
| helper->RegisterPeripheralPlugin( |