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

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

Issue 703453004: Plugin Power Saver: Add some UMAs to test plugins in wild. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try reupload 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 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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/metrics/histogram.h"
6 #include "content/common/frame_messages.h" 7 #include "content/common/frame_messages.h"
7 #include "content/public/renderer/document_state.h" 8 #include "content/public/renderer/document_state.h"
8 #include "content/public/renderer/navigation_state.h" 9 #include "content/public/renderer/navigation_state.h"
9 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
10 #include "content/renderer/pepper/plugin_power_saver_helper.h" 11 #include "content/renderer/pepper/plugin_power_saver_helper.h"
11 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
12 #include "third_party/WebKit/public/web/WebLocalFrame.h" 13 #include "third_party/WebKit/public/web/WebLocalFrame.h"
13 #include "third_party/WebKit/public/web/WebView.h" 14 #include "third_party/WebKit/public/web/WebView.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 namespace { 18 namespace {
18 19
20 // Initial decision of the peripheral content decision.
21 // These numeric values are used in UMA logs; do not change them.
22 enum PeripheralHeuristicDecision {
23 HEURISTIC_DECISION_PERIPHERAL = 0,
24 HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1,
25 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2,
26 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 3,
27 HEURISTIC_DECISION_NUM_ITEMS
28 };
29
30 const char kPeripheralHeuristicHistogram[] =
31 "Plugin.PowerSaverPeripheralHeuristic";
32
19 // Maximum dimensions plug-in content may have while still being considered 33 // Maximum dimensions plug-in content may have while still being considered
20 // peripheral content. These match the sizes used by Safari. 34 // peripheral content. These match the sizes used by Safari.
21 const int kPeripheralContentMaxWidth = 400; 35 const int kPeripheralContentMaxWidth = 400;
22 const int kPeripheralContentMaxHeight = 300; 36 const int kPeripheralContentMaxHeight = 300;
23 37
38 void RecordDecisionMetric(PeripheralHeuristicDecision decision) {
39 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, decision,
40 HEURISTIC_DECISION_NUM_ITEMS);
41 }
42
24 } // namespace 43 } // namespace
25 44
26 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( 45 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin(
27 const GURL& content_origin, 46 const GURL& content_origin,
28 const base::Closure& unthrottle_callback) 47 const base::Closure& unthrottle_callback)
29 : content_origin(content_origin), unthrottle_callback(unthrottle_callback) { 48 : content_origin(content_origin), unthrottle_callback(unthrottle_callback) {
30 } 49 }
31 50
32 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() { 51 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() {
33 } 52 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 int height, 101 int height,
83 bool* cross_origin) const { 102 bool* cross_origin) const {
84 DCHECK(cross_origin); 103 DCHECK(cross_origin);
85 *cross_origin = true; 104 *cross_origin = true;
86 105
87 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 106 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512
88 // is fixed. For now, case 3 in the class level comment doesn't work in 107 // is fixed. For now, case 3 in the class level comment doesn't work in
89 // --site-per-process mode. 108 // --site-per-process mode.
90 blink::WebFrame* main_frame = 109 blink::WebFrame* main_frame =
91 render_frame()->GetWebFrame()->view()->mainFrame(); 110 render_frame()->GetWebFrame()->view()->mainFrame();
92 if (main_frame->isWebRemoteFrame()) 111 if (main_frame->isWebRemoteFrame()) {
112 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL);
93 return true; 113 return true;
114 }
94 115
95 // All same-origin plugin content is essential. 116 // All same-origin plugin content is essential.
96 GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin(); 117 GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin();
97 if (content_origin == main_frame_origin) { 118 if (content_origin == main_frame_origin) {
119 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN);
98 *cross_origin = false; 120 *cross_origin = false;
99 return false; 121 return false;
100 } 122 }
101 123
102 // Whitelisted plugin origins are also essential. 124 // Whitelisted plugin origins are also essential.
103 if (origin_whitelist_.count(content_origin)) 125 if (origin_whitelist_.count(content_origin)) {
126 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED);
104 return false; 127 return false;
128 }
105 129
106 // Cross-origin plugin content is peripheral if smaller than a maximum size. 130 // Cross-origin plugin content is peripheral if smaller than a maximum size.
107 bool content_is_small = width < kPeripheralContentMaxWidth || 131 bool content_is_small = width < kPeripheralContentMaxWidth ||
108 height < kPeripheralContentMaxHeight; 132 height < kPeripheralContentMaxHeight;
109 133
134 if (content_is_small)
135 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL);
136 else
137 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG);
138
110 return content_is_small; 139 return content_is_small;
111 } 140 }
112 141
113 void PluginPowerSaverHelper::RegisterPeripheralPlugin( 142 void PluginPowerSaverHelper::RegisterPeripheralPlugin(
114 const GURL& content_origin, 143 const GURL& content_origin,
115 const base::Closure& unthrottle_callback) { 144 const base::Closure& unthrottle_callback) {
116 peripheral_plugins_.push_back( 145 peripheral_plugins_.push_back(
117 PeripheralPlugin(content_origin, unthrottle_callback)); 146 PeripheralPlugin(content_origin, unthrottle_callback));
118 } 147 }
119 148
120 void PluginPowerSaverHelper::WhitelistContentOrigin( 149 void PluginPowerSaverHelper::WhitelistContentOrigin(
121 const GURL& content_origin) { 150 const GURL& content_origin) {
122 if (origin_whitelist_.insert(content_origin).second) { 151 if (origin_whitelist_.insert(content_origin).second) {
123 Send(new FrameHostMsg_PluginContentOriginAllowed( 152 Send(new FrameHostMsg_PluginContentOriginAllowed(
124 render_frame()->GetRoutingID(), content_origin)); 153 render_frame()->GetRoutingID(), content_origin));
125 } 154 }
126 } 155 }
127 156
128 } // namespace content 157 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.cc ('k') | tools/metrics/actions/actions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698