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

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

Issue 764763005: Plugin Power Saver: Always mark 'tiny' plugins as essential. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0201-plugin-power-saver-use-poster-frame-on-blocked-only
Patch Set: Created 6 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
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/pepper/plugin_power_saver_helper_impl.cc
diff --git a/content/renderer/pepper/plugin_power_saver_helper_impl.cc b/content/renderer/pepper/plugin_power_saver_helper_impl.cc
index 92fcb4dc247668d4f0614366c79539a70cc713b3..5b240a780ca24e66a5c390557da78d76c79be962 100644
--- a/content/renderer/pepper/plugin_power_saver_helper_impl.cc
+++ b/content/renderer/pepper/plugin_power_saver_helper_impl.cc
@@ -28,6 +28,7 @@ enum PeripheralHeuristicDecision {
HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1,
HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2,
HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 3,
+ HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY = 4,
HEURISTIC_DECISION_NUM_ITEMS
};
@@ -39,6 +40,11 @@ const char kPeripheralHeuristicHistogram[] =
const int kPeripheralContentMaxWidth = 400;
const int kPeripheralContentMaxHeight = 300;
+// Plug-in content below this size in height and width is considered "tiny".
+// Tiny content is never peripheral, as tiny plug-ins often serve a critical
+// purpose, and the user often cannot find and click to unthrottle it.
+const int kPeripheralContentTinySize = 5;
+
void RecordDecisionMetric(PeripheralHeuristicDecision decision) {
UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, decision,
HEURISTIC_DECISION_NUM_ITEMS);
@@ -137,11 +143,10 @@ GURL PluginPowerSaverHelperImpl::GetPluginInstancePosterImage(
int width = 0;
int height = 0;
- bool cross_origin = false;
if (!ExtractDimensions(params, &width, &height))
return GURL();
- if (!ShouldThrottleContent(content_origin, width, height, &cross_origin))
+ if (!ShouldThrottleContent(content_origin, width, height, nullptr))
return GURL();
for (size_t i = 0; i < params.attributeNames.size(); ++i) {
@@ -165,9 +170,10 @@ bool PluginPowerSaverHelperImpl::ShouldThrottleContent(
const GURL& content_origin,
int width,
int height,
- bool* cross_origin) const {
- DCHECK(cross_origin);
- *cross_origin = true;
+ bool* is_main_attraction) const {
+ DCHECK_EQ(content_origin.GetOrigin(), content_origin);
+ if (is_main_attraction)
+ *is_main_attraction = false;
// TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512
// is fixed. For now, case 3 in the class level comment doesn't work in
@@ -183,7 +189,6 @@ bool PluginPowerSaverHelperImpl::ShouldThrottleContent(
GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin();
if (content_origin == main_frame_origin) {
RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN);
- *cross_origin = false;
return false;
}
@@ -193,16 +198,24 @@ bool PluginPowerSaverHelperImpl::ShouldThrottleContent(
return false;
}
- // Cross-origin plugin content is peripheral if smaller than a maximum size.
- bool content_is_small = width < kPeripheralContentMaxWidth ||
- height < kPeripheralContentMaxHeight;
+ // Never mark tiny content as peripheral.
+ if (width <= kPeripheralContentTinySize &&
+ height <= kPeripheralContentTinySize) {
+ RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY);
+ return false;
+ }
- if (content_is_small)
- RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL);
- else
+ // Plugin content large in both dimensions are the "main attraction".
+ if (width >= kPeripheralContentMaxWidth &&
+ height >= kPeripheralContentMaxHeight) {
RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG);
+ if (is_main_attraction)
+ *is_main_attraction = true;
+ return false;
+ }
- return content_is_small;
+ RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL);
+ return true;
}
void PluginPowerSaverHelperImpl::WhitelistContentOrigin(
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698