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

Unified Diff: content/renderer/pepper/pepper_plugin_instance_throttler.h

Issue 707113002: Plugin Power Saver: Refactor Plugin Instance Throttling code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0190-plugin-power-saver-add-some-umas
Patch Set: Created 6 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: 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..9d768909537a060923aa500924cb604f64595fe4 100644
--- a/content/renderer/pepper/pepper_plugin_instance_throttler.h
+++ b/content/renderer/pepper/pepper_plugin_instance_throttler.h
@@ -5,23 +5,76 @@
#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 "content/common/content_export.h"
+#include "ppapi/shared_impl/ppb_view_shared.h"
+#include "third_party/WebKit/public/platform/WebRect.h"
+
+namespace blink {
+class WebInputEvent;
+}
+
+class GURL;
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 PepperPluginInstanceThrottler {
+class PluginPowerSaverHelper;
+
+// Manages the Plugin Power Saver feature for a single Pepper plugin instance.
+class CONTENT_EXPORT PepperPluginInstanceThrottler {
public:
- // |throttle_closure| is called to engage throttling.
- explicit PepperPluginInstanceThrottler(const base::Closure& throttle_closure);
+ PepperPluginInstanceThrottler(PluginPowerSaverHelper* power_saver_helper,
+ const blink::WebRect& bounds,
+ const std::string& module_name,
+ const GURL& plugin_url,
+ 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);
+
private:
+ friend class PepperPluginInstanceThrottlerTest;
+
+ void SetPluginThrottled(bool throttled);
+ void DisablePowerSaverByRetroactiveWhitelist();
+
+ // Plugin's bounds in view space.
+ blink::WebRect bounds_;
+
+ // Called when the throttle state changes.
+ base::Closure throttle_change_callback_;
+
+ bool is_flash_plugin_;
+
+ // 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_|.
+ 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);
};
}

Powered by Google App Engine
This is Rietveld 408576698