Index: content/renderer/pepper/plugin_instance_throttler_impl.h |
diff --git a/content/renderer/pepper/pepper_plugin_instance_throttler.h b/content/renderer/pepper/plugin_instance_throttler_impl.h |
similarity index 34% |
rename from content/renderer/pepper/pepper_plugin_instance_throttler.h |
rename to content/renderer/pepper/plugin_instance_throttler_impl.h |
index af5794e60e1da4ffae54faefd674e7ef887d03a4..e438b866ab3b73ca00247a0ed25c96655e47c00e 100644 |
--- a/content/renderer/pepper/pepper_plugin_instance_throttler.h |
+++ b/content/renderer/pepper/plugin_instance_throttler_impl.h |
@@ -2,14 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
-#define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
+#ifndef CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
+#define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
-#include "base/callback.h" |
#include "base/macros.h" |
#include "base/memory/weak_ptr.h" |
+#include "base/observer_list.h" |
#include "content/common/content_export.h" |
-#include "content/public/renderer/render_frame.h" |
+#include "content/public/renderer/plugin_instance_throttler.h" |
#include "ppapi/shared_impl/ppb_view_shared.h" |
#include "third_party/WebKit/public/platform/WebRect.h" |
@@ -17,110 +17,66 @@ namespace blink { |
class WebInputEvent; |
} |
-class GURL; |
class SkBitmap; |
namespace content { |
-// Manages the Plugin Power Saver feature for a single Pepper plugin instance. |
-// |
-// A plugin must meet certain criteria in order to be throttled (e.g. it must |
-// be a Flash plugin, it must meet certain size criteria, etc.). The process |
-// for throttling a plugin is as follows: |
-// 1) Attempt to find a representative keyframe to display as a placeholder for |
-// the plugin. |
-// 2) a) If a representative keyframe is found, throttle the plugin at that |
-// keyframe. |
-// b) If a representative keyframe is not found, throttle the plugin after a |
-// certain period of time. |
-// |
-// The plugin will then be unthrottled by receiving a mouse click from the user. |
-// |
-// To choose a representative keyframe, we first wait for a certain number of |
-// "interesting" frames to be displayed by the plugin. A frame is called |
-// interesting if it meets some heuristic. After we have seen a certain number |
-// of interesting frames, we throttle the plugin and use that frame as the |
-// representative keyframe. |
-class CONTENT_EXPORT PepperPluginInstanceThrottler { |
+class CONTENT_EXPORT PluginInstanceThrottlerImpl |
+ : public PluginInstanceThrottler { |
public: |
- // How the throttled power saver is unthrottled, if ever. |
- // These numeric values are used in UMA logs; do not change them. |
- enum PowerSaverUnthrottleMethod { |
- UNTHROTTLE_METHOD_NEVER = 0, |
- UNTHROTTLE_METHOD_BY_CLICK = 1, |
- UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
- UNTHROTTLE_METHOD_BY_AUDIO = 3, |
- UNTHROTTLE_METHOD_NUM_ITEMS |
- }; |
- |
- PepperPluginInstanceThrottler( |
- RenderFrame* frame, |
- const blink::WebRect& bounds, |
- bool is_flash_plugin, |
- const GURL& plugin_url, |
- RenderFrame::PluginPowerSaverMode power_saver_mode, |
- const base::Closure& throttle_change_callback); |
- |
- virtual ~PepperPluginInstanceThrottler(); |
+ PluginInstanceThrottlerImpl(RenderFrame* frame, |
+ const GURL& plugin_url, |
+ PluginPowerSaverMode power_saver_mode); |
+ |
+ ~PluginInstanceThrottlerImpl() override; |
+ |
+ // PluginInstanceThrottler implementation: |
+ void AddObserver(Observer* observer) override; |
+ void RemoveObserver(Observer* observer) override; |
+ bool IsThrottled() const override; |
+ void DisablePowerSaver(PowerSaverUnthrottleMethod method) override; |
bool needs_representative_keyframe() const { |
return needs_representative_keyframe_; |
} |
- bool power_saver_enabled() const { |
- return power_saver_enabled_; |
- } |
+ bool power_saver_enabled() const { return power_saver_enabled_; } |
// Called when the plugin flushes it's graphics context. Supplies the |
// throttler with a candidate to use as the representative keyframe. |
void OnImageFlush(const SkBitmap* bitmap); |
- bool is_throttled() const { return plugin_throttled_; } |
- |
// Returns true if |event| was handled and shouldn't be further processed. |
bool ConsumeInputEvent(const blink::WebInputEvent& event); |
- // Disables Power Saver and unthrottles the plugin if already throttled. |
- void DisablePowerSaver(PowerSaverUnthrottleMethod method); |
- |
private: |
- friend class PepperPluginInstanceThrottlerTest; |
+ friend class PluginInstanceThrottlerImplTest; |
void SetPluginThrottled(bool throttled); |
- // Plugin's bounds in view space. |
- blink::WebRect bounds_; |
- |
- // Called when the throttle state changes. |
- base::Closure throttle_change_callback_; |
- |
- bool is_flash_plugin_; |
- |
// True if throttler is still waiting to find a representative keyframe. |
bool needs_representative_keyframe_; |
// Number of consecutive interesting frames we've encountered. |
int consecutive_interesting_frames_; |
- // Set to true first time plugin is clicked. Used to collect metrics. |
- bool has_been_clicked_; |
- |
// Indicates whether this plugin may be throttled to reduce power consumption. |
// |power_saver_enabled_| implies |is_peripheral_content_|. |
Lei Zhang
2015/01/15 01:18:38
You still reference |is_peripheral_content_| here.
tommycli
2015/01/15 23:19:32
Done.
|
bool power_saver_enabled_; |
- // Indicates whether this plugin was found to be peripheral content. |
+ // Indicates whether this plugin has been unthrottled. |
// This is separately tracked from |power_saver_enabled_| to collect UMAs. |
- // Always true if |power_saver_enabled_| is true. |
- bool is_peripheral_content_; |
+ bool has_been_unthrottled_; |
Lei Zhang
2015/01/15 01:18:38
Now this variable name and |plugin_throttled_| bel
tommycli
2015/01/15 23:19:32
Done.
|
// Indicates if the plugin is currently throttled. |
bool plugin_throttled_; |
- base::WeakPtrFactory<PepperPluginInstanceThrottler> weak_factory_; |
+ ObserverList<Observer> observer_list_; |
+ |
+ base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_; |
- DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); |
+ DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl); |
}; |
} |
-#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
+#endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |