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

Side by Side Diff: content/renderer/pepper/plugin_power_saver_helper.cc

Issue 1124173008: Plugin Power Saver: Unthrottle dynamically sized plugins correctly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/pepper/plugin_power_saver_helper.h" 5 #include "content/renderer/pepper/plugin_power_saver_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "content/common/frame_messages.h" 12 #include "content/common/frame_messages.h"
13 #include "content/public/common/content_constants.h" 13 #include "content/public/common/content_constants.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/renderer/plugin_instance_throttler.h"
15 #include "content/public/renderer/render_frame.h" 16 #include "content/public/renderer/render_frame.h"
16 #include "ppapi/shared_impl/ppapi_constants.h" 17 #include "ppapi/shared_impl/ppapi_constants.h"
17 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
18 #include "third_party/WebKit/public/web/WebLocalFrame.h" 19 #include "third_party/WebKit/public/web/WebLocalFrame.h"
19 #include "third_party/WebKit/public/web/WebPluginParams.h" 20 #include "third_party/WebKit/public/web/WebPluginParams.h"
20 #include "third_party/WebKit/public/web/WebView.h" 21 #include "third_party/WebKit/public/web/WebView.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 namespace { 25 namespace {
25 26
26 // Initial decision of the peripheral content decision. 27 // Initial decision of the peripheral content decision.
27 // These numeric values are used in UMA logs; do not change them. 28 // These numeric values are used in UMA logs; do not change them.
28 enum PeripheralHeuristicDecision { 29 enum PeripheralHeuristicDecision {
29 HEURISTIC_DECISION_PERIPHERAL = 0, 30 HEURISTIC_DECISION_PERIPHERAL = 0,
30 HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1, 31 HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1,
31 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2, 32 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2,
32 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 3, 33 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 3,
33 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY = 4, 34 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY = 4,
34 HEURISTIC_DECISION_NUM_ITEMS 35 HEURISTIC_DECISION_NUM_ITEMS
35 }; 36 };
36 37
37 const char kPeripheralHeuristicHistogram[] = 38 const char kPeripheralHeuristicHistogram[] =
38 "Plugin.PowerSaver.PeripheralHeuristic"; 39 "Plugin.PowerSaver.PeripheralHeuristic";
39 40
40 // Maximum dimensions plugin content may have while still being considered
41 // peripheral content. These are similar to the numbers used by WebKit.
42 const int kPeripheralContentMaxWidth = 398;
43 const int kPeripheralContentMaxHeight = 298;
44
45 // Plugin content below this size in height and width is considered "tiny". 41 // Plugin content below this size in height and width is considered "tiny".
46 // Tiny content is never peripheral, as tiny plugins often serve a critical 42 // Tiny content is never peripheral, as tiny plugins often serve a critical
47 // purpose, and the user often cannot find and click to unthrottle it. 43 // purpose, and the user often cannot find and click to unthrottle it.
48 const int kPeripheralContentTinySize = 5; 44 const int kPeripheralContentTinySize = 5;
49 45
50 void RecordDecisionMetric(PeripheralHeuristicDecision decision) { 46 void RecordDecisionMetric(PeripheralHeuristicDecision decision) {
51 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, decision, 47 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, decision,
52 HEURISTIC_DECISION_NUM_ITEMS); 48 HEURISTIC_DECISION_NUM_ITEMS);
53 } 49 }
54 50
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 169 }
174 170
175 // Never mark tiny content as peripheral. 171 // Never mark tiny content as peripheral.
176 if (width <= kPeripheralContentTinySize && 172 if (width <= kPeripheralContentTinySize &&
177 height <= kPeripheralContentTinySize) { 173 height <= kPeripheralContentTinySize) {
178 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY); 174 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY);
179 return false; 175 return false;
180 } 176 }
181 177
182 // Plugin content large in both dimensions are the "main attraction". 178 // Plugin content large in both dimensions are the "main attraction".
183 if (width >= kPeripheralContentMaxWidth && 179 if (PluginInstanceThrottler::IsLargeContent(width, height)) {
184 height >= kPeripheralContentMaxHeight) {
185 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG); 180 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG);
186 if (cross_origin_main_content) 181 if (cross_origin_main_content)
187 *cross_origin_main_content = true; 182 *cross_origin_main_content = true;
188 return false; 183 return false;
189 } 184 }
190 185
191 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL); 186 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL);
192 return true; 187 return true;
193 } 188 }
194 189
195 void PluginPowerSaverHelper::WhitelistContentOrigin( 190 void PluginPowerSaverHelper::WhitelistContentOrigin(
196 const GURL& content_origin) { 191 const GURL& content_origin) {
197 DCHECK_EQ(content_origin.GetOrigin(), content_origin); 192 DCHECK_EQ(content_origin.GetOrigin(), content_origin);
198 if (origin_whitelist_.insert(content_origin).second) { 193 if (origin_whitelist_.insert(content_origin).second) {
199 Send(new FrameHostMsg_PluginContentOriginAllowed( 194 Send(new FrameHostMsg_PluginContentOriginAllowed(
200 render_frame()->GetRoutingID(), content_origin)); 195 render_frame()->GetRoutingID(), content_origin));
201 } 196 }
202 } 197 }
203 198
204 } // namespace content 199 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/plugin_instance_throttler_impl.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698