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

Unified Diff: content/renderer/pepper/plugin_power_saver_helper.cc

Issue 1522173002: Reland: Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix an NPE crash/race on plugin destruction Created 5 years 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/plugin_power_saver_helper.cc
diff --git a/content/renderer/pepper/plugin_power_saver_helper.cc b/content/renderer/pepper/plugin_power_saver_helper.cc
index 2544162ad5869144cb50c9b32599b7ccea51f528..cd1f27cc0c9bd1a2e5962fa6fd6a037705aa350e 100644
--- a/content/renderer/pepper/plugin_power_saver_helper.cc
+++ b/content/renderer/pepper/plugin_power_saver_helper.cc
@@ -15,6 +15,7 @@
#include "content/renderer/peripheral_content_heuristic.h"
#include "ppapi/shared_impl/ppapi_constants.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "ui/gfx/geometry/size.h"
namespace content {
@@ -84,33 +85,28 @@ void PluginPowerSaverHelper::RegisterPeripheralPlugin(
PeripheralPlugin(content_origin, unthrottle_callback));
}
-bool PluginPowerSaverHelper::ShouldThrottleContent(
+RenderFrame::PeripheralContentStatus
+PluginPowerSaverHelper::GetPeripheralContentStatus(
const url::Origin& main_frame_origin,
const url::Origin& content_origin,
- int width,
- int height,
- bool* cross_origin_main_content) const {
- if (cross_origin_main_content)
- *cross_origin_main_content = false;
-
+ const gfx::Size& unobscured_size) const {
if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kOverridePluginPowerSaverForTesting) == "always") {
- return true;
+ return RenderFrame::CONTENT_STATUS_PERIPHERAL;
}
- auto decision = PeripheralContentHeuristic::GetPeripheralStatus(
- origin_whitelist_, main_frame_origin, content_origin, width, height);
-
- UMA_HISTOGRAM_ENUMERATION(
- kPeripheralHeuristicHistogram, decision,
- PeripheralContentHeuristic::HEURISTIC_DECISION_NUM_ITEMS);
-
- if (decision == PeripheralContentHeuristic::
- HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG &&
- cross_origin_main_content)
- *cross_origin_main_content = true;
+ auto status = PeripheralContentHeuristic::GetPeripheralStatus(
+ origin_whitelist_, main_frame_origin, content_origin, unobscured_size);
+ if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_UNKNOWN_SIZE) {
+ // Early exit here to avoid recording a UMA. Every plugin will call this
+ // method once before the size is known (to faciliate early-exit for
+ // same-origin and whitelisted-origin content).
+ return status;
+ }
- return decision == PeripheralContentHeuristic::HEURISTIC_DECISION_PERIPHERAL;
+ UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, status,
+ RenderFrame::CONTENT_STATUS_NUM_ITEMS);
+ return status;
}
void PluginPowerSaverHelper::WhitelistContentOrigin(

Powered by Google App Engine
This is Rietveld 408576698