Index: content/renderer/pepper/pepper_plugin_instance_throttler.h |
diff --git a/content/renderer/pepper/pepper_plugin_instance_throttler.h b/content/renderer/pepper/pepper_plugin_instance_throttler.h |
index 15a5c10af3c60f7495b83ddebffecad1d9f60e1f..6ed446f45268b403a634979df6345c745a31f783 100644 |
--- a/content/renderer/pepper/pepper_plugin_instance_throttler.h |
+++ b/content/renderer/pepper/pepper_plugin_instance_throttler.h |
@@ -5,23 +5,65 @@ |
#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
#define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
-#include "base/callback_forward.h" |
+#include "base/callback.h" |
#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "ppapi/shared_impl/ppb_view_shared.h" |
+ |
+namespace blink { |
+class WebInputEvent; |
+} |
namespace content { |
-// Throttles Pepper Plugin instances in Power Saver mode. Currently just a |
-// stub implementation that engages throttling after a fixed timeout. |
-// In the future, will examine plugin frames to find a suitable preview |
-// image before engaging throttling. |
+class PepperPluginInstanceImpl; |
+ |
+// Manages the Plugin Power Saver feature for a single Pepper plugin instance. |
class PepperPluginInstanceThrottler { |
public: |
- // |throttle_closure| is called to engage throttling. |
- explicit PepperPluginInstanceThrottler(const base::Closure& throttle_closure); |
+ PepperPluginInstanceThrottler(PepperPluginInstanceImpl* instance, |
+ const base::Closure& throttle_change_callback); |
virtual ~PepperPluginInstanceThrottler(); |
+ bool is_throttled() const { return plugin_throttled_; } |
+ const ppapi::ViewData& throttled_view_data() const { |
+ return empty_view_data_; |
+ } |
+ |
+ // Returns true if |event| was handled and shouldn't be further processed. |
+ bool ConsumeInputEvent(const blink::WebInputEvent& event); |
+ |
+ protected: |
+ // Used only for testing. |
+ PepperPluginInstanceThrottler(const base::Closure& throttle_change_callback, |
+ bool power_saver_enabled, |
+ bool is_peripheral_content); |
+ |
+ void SetPluginThrottled(bool throttled); |
+ void DisablePowerSaverByRetroactiveWhitelist(); |
+ |
private: |
+ // Called when the throttle state changes. |
+ base::Closure throttle_change_callback_; |
+ |
+ // Indicates whether this plugin may be throttled to reduce power consumption. |
+ // |power_saver_enabled_| implies |is_peripheral_content_|. |
+ bool power_saver_enabled_; |
+ |
+ // Indicates whether this plugin was found to be peripheral content. |
+ // This is separately tracked from |power_saver_enabled_| to collect UMAs. |
+ // Always true if |power_saver_enabled_| is true. |
+ bool is_peripheral_content_; |
+ |
+ // Indicates if the plugin is currently throttled. |
+ bool plugin_throttled_; |
+ |
+ // Fake view data used by the Power Saver feature to throttle plugins. |
+ const ppapi::ViewData empty_view_data_; |
+ |
+ base::WeakPtrFactory<PepperPluginInstanceThrottler> weak_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); |
}; |
} |