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

Side by Side Diff: components/plugins/renderer/loadable_plugin_placeholder.cc

Issue 863813002: Plugin Power Saver: Make Unthrottle metric collection more consistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/plugins/renderer/loadable_plugin_placeholder.h" 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 13 matching lines...) Expand all
24 using base::UserMetricsAction; 24 using base::UserMetricsAction;
25 using blink::WebElement; 25 using blink::WebElement;
26 using blink::WebLocalFrame; 26 using blink::WebLocalFrame;
27 using blink::WebMouseEvent; 27 using blink::WebMouseEvent;
28 using blink::WebNode; 28 using blink::WebNode;
29 using blink::WebPlugin; 29 using blink::WebPlugin;
30 using blink::WebPluginContainer; 30 using blink::WebPluginContainer;
31 using blink::WebPluginParams; 31 using blink::WebPluginParams;
32 using blink::WebScriptSource; 32 using blink::WebScriptSource;
33 using blink::WebURLRequest; 33 using blink::WebURLRequest;
34 using content::PluginInstanceThrottler;
34 using content::PluginPowerSaverMode; 35 using content::PluginPowerSaverMode;
35 using content::RenderThread; 36 using content::RenderThread;
36 37
37 namespace plugins { 38 namespace plugins {
38 39
39 #if defined(ENABLE_PLUGINS) 40 #if defined(ENABLE_PLUGINS)
40 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { 41 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() {
41 DCHECK(!is_blocked_for_power_saver_poster_); 42 DCHECK(!is_blocked_for_power_saver_poster_);
42 is_blocked_for_power_saver_poster_ = true; 43 is_blocked_for_power_saver_poster_ = true;
43 44
44 render_frame()->RegisterPeripheralPlugin( 45 render_frame()->RegisterPeripheralPlugin(
45 GURL(GetPluginParams().url).GetOrigin(), 46 GURL(GetPluginParams().url).GetOrigin(),
46 base::Bind(&LoadablePluginPlaceholder::DisablePowerSaverForInstance, 47 base::Bind(&LoadablePluginPlaceholder::DisablePowerSaverForInstance,
47 weak_factory_.GetWeakPtr())); 48 weak_factory_.GetWeakPtr(),
49 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST));
48 } 50 }
49 #endif 51 #endif
50 52
51 LoadablePluginPlaceholder::LoadablePluginPlaceholder( 53 LoadablePluginPlaceholder::LoadablePluginPlaceholder(
52 content::RenderFrame* render_frame, 54 content::RenderFrame* render_frame,
53 WebLocalFrame* frame, 55 WebLocalFrame* frame,
54 const WebPluginParams& params, 56 const WebPluginParams& params,
55 const std::string& html_data, 57 const std::string& html_data,
56 GURL placeholderDataUrl) 58 GURL placeholderDataUrl)
57 : PluginPlaceholder(render_frame, 59 : PluginPlaceholder(render_frame,
58 frame, 60 frame,
59 params, 61 params,
60 html_data, 62 html_data,
61 placeholderDataUrl), 63 placeholderDataUrl),
62 is_blocked_for_background_tab_(false), 64 is_blocked_for_background_tab_(false),
63 is_blocked_for_prerendering_(false), 65 is_blocked_for_prerendering_(false),
64 is_blocked_for_power_saver_poster_(false), 66 is_blocked_for_power_saver_poster_(false),
65 power_saver_mode_(PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL), 67 power_saver_mode_(PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL),
66 allow_loading_(false), 68 allow_loading_(false),
69 placeholder_was_replaced_(false),
67 hidden_(false), 70 hidden_(false),
68 finished_loading_(false), 71 finished_loading_(false),
69 weak_factory_(this) { 72 weak_factory_(this) {
70 } 73 }
71 74
72 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { 75 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
76 #if defined(ENABLE_PLUGINS)
77 if (!placeholder_was_replaced_ && !is_blocked_for_prerendering_ &&
78 power_saver_mode_ != PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL) {
79 PluginInstanceThrottler::RecordUnthrottleMethodMetric(
80 PluginInstanceThrottler::UNTHROTTLE_METHOD_NEVER);
81 }
82 #endif
73 } 83 }
74 84
75 #if defined(ENABLE_PLUGINS) 85 #if defined(ENABLE_PLUGINS)
76 void LoadablePluginPlaceholder::DisablePowerSaverForInstance() { 86 void LoadablePluginPlaceholder::DisablePowerSaverForInstance(
87 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
88 if (power_saver_mode_ == PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL)
89 return;
90
77 power_saver_mode_ = PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL; 91 power_saver_mode_ = PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL;
92 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method);
78 if (is_blocked_for_power_saver_poster_) { 93 if (is_blocked_for_power_saver_poster_) {
79 is_blocked_for_power_saver_poster_ = false; 94 is_blocked_for_power_saver_poster_ = false;
80 if (!LoadingBlocked()) 95 if (!LoadingBlocked())
81 LoadPlugin(); 96 LoadPlugin();
82 } 97 }
83 } 98 }
84 #endif 99 #endif
85 100
86 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( 101 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder(
87 v8::Isolate* isolate) { 102 v8::Isolate* isolate) {
(...skipping 30 matching lines...) Expand all
118 // During initialization, the new plug-in might have replaced itself in turn 133 // During initialization, the new plug-in might have replaced itself in turn
119 // with another plug-in. Make sure not to use the passed in |new_plugin| after 134 // with another plug-in. Make sure not to use the passed in |new_plugin| after
120 // this point. 135 // this point.
121 new_plugin = container->plugin(); 136 new_plugin = container->plugin();
122 137
123 plugin()->RestoreTitleText(); 138 plugin()->RestoreTitleText();
124 container->invalidate(); 139 container->invalidate();
125 container->reportGeometry(); 140 container->reportGeometry();
126 plugin()->ReplayReceivedData(new_plugin); 141 plugin()->ReplayReceivedData(new_plugin);
127 plugin()->destroy(); 142 plugin()->destroy();
143
144 placeholder_was_replaced_ = true;
128 } 145 }
129 146
130 void LoadablePluginPlaceholder::HidePlugin() { 147 void LoadablePluginPlaceholder::HidePlugin() {
131 hidden_ = true; 148 hidden_ = true;
132 if (!plugin()) 149 if (!plugin())
133 return; 150 return;
134 WebPluginContainer* container = plugin()->container(); 151 WebPluginContainer* container = plugin()->container();
135 WebElement element = container->element(); 152 WebElement element = container->element();
136 element.setAttribute("style", "display: none;"); 153 element.setAttribute("style", "display: none;");
137 // If we have a width and height, search for a parent (often <div>) with the 154 // If we have a width and height, search for a parent (often <div>) with the
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (!plugin()) 249 if (!plugin())
233 return; 250 return;
234 if (!allow_loading_) { 251 if (!allow_loading_) {
235 NOTREACHED(); 252 NOTREACHED();
236 return; 253 return;
237 } 254 }
238 255
239 // TODO(mmenke): In the case of prerendering, feed into 256 // TODO(mmenke): In the case of prerendering, feed into
240 // ChromeContentRendererClient::CreatePlugin instead, to 257 // ChromeContentRendererClient::CreatePlugin instead, to
241 // reduce the chance of future regressions. 258 // reduce the chance of future regressions.
242 scoped_ptr<content::PluginInstanceThrottler> throttler; 259 scoped_ptr<PluginInstanceThrottler> throttler;
243 #if defined(ENABLE_PLUGINS) 260 #if defined(ENABLE_PLUGINS)
244 throttler = content::PluginInstanceThrottler::Get( 261 throttler = PluginInstanceThrottler::Get(
245 render_frame(), GetPluginParams().url, power_saver_mode_); 262 render_frame(), GetPluginParams().url, power_saver_mode_);
246 #endif 263 #endif
247 WebPlugin* plugin = render_frame()->CreatePlugin( 264 WebPlugin* plugin = render_frame()->CreatePlugin(
248 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass()); 265 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass());
249 ReplacePlugin(plugin); 266 ReplacePlugin(plugin);
250 } 267 }
251 268
252 void LoadablePluginPlaceholder::LoadCallback() { 269 void LoadablePluginPlaceholder::LoadCallback() {
253 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); 270 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click"));
254 #if defined(ENABLE_PLUGINS) 271 #if defined(ENABLE_PLUGINS)
255 // If the user specifically clicks on the plug-in content's placeholder, 272 // If the user specifically clicks on the plug-in content's placeholder,
256 // disable power saver throttling for this instance. 273 // disable power saver throttling for this instance.
257 DisablePowerSaverForInstance(); 274 DisablePowerSaverForInstance(
275 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK);
258 #endif 276 #endif
259 LoadPlugin(); 277 LoadPlugin();
260 } 278 }
261 279
262 void LoadablePluginPlaceholder::HideCallback() { 280 void LoadablePluginPlaceholder::HideCallback() {
263 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click")); 281 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click"));
264 HidePlugin(); 282 HidePlugin();
265 } 283 }
266 284
267 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { 285 void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
(...skipping 15 matching lines...) Expand all
283 identifier_ = identifier; 301 identifier_ = identifier;
284 } 302 }
285 303
286 bool LoadablePluginPlaceholder::LoadingBlocked() const { 304 bool LoadablePluginPlaceholder::LoadingBlocked() const {
287 DCHECK(allow_loading_); 305 DCHECK(allow_loading_);
288 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || 306 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ ||
289 is_blocked_for_prerendering_; 307 is_blocked_for_prerendering_;
290 } 308 }
291 309
292 } // namespace plugins 310 } // namespace plugins
OLDNEW
« no previous file with comments | « components/plugins/renderer/loadable_plugin_placeholder.h ('k') | content/content_renderer.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698