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

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

Issue 849723002: Plugin Power Saver: Make PepperPluginInstanceThrottler interface public. (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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/plugin_placeholder.h" 5 #include "components/plugins/renderer/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 : content::RenderFrameObserver(render_frame), 61 : content::RenderFrameObserver(render_frame),
62 frame_(frame), 62 frame_(frame),
63 plugin_params_(params), 63 plugin_params_(params),
64 plugin_(WebViewPlugin::Create(this, 64 plugin_(WebViewPlugin::Create(this,
65 render_frame->GetWebkitPreferences(), 65 render_frame->GetWebkitPreferences(),
66 html_data, 66 html_data,
67 placeholderDataUrl)), 67 placeholderDataUrl)),
68 is_blocked_for_background_tab_(false), 68 is_blocked_for_background_tab_(false),
69 is_blocked_for_prerendering_(false), 69 is_blocked_for_prerendering_(false),
70 is_blocked_for_power_saver_poster_(false), 70 is_blocked_for_power_saver_poster_(false),
71 power_saver_mode_(content::RenderFrame::POWER_SAVER_MODE_ESSENTIAL), 71 power_saver_mode_(
72 content::PluginInstanceThrottler::POWER_SAVER_MODE_ESSENTIAL),
72 allow_loading_(false), 73 allow_loading_(false),
73 hidden_(false), 74 hidden_(false),
74 finished_loading_(false), 75 finished_loading_(false),
75 weak_factory_(this) { 76 weak_factory_(this) {
76 } 77 }
77 78
78 PluginPlaceholder::~PluginPlaceholder() {} 79 PluginPlaceholder::~PluginPlaceholder() {}
79 80
80 #if defined(ENABLE_PLUGINS) 81 #if defined(ENABLE_PLUGINS)
81 void PluginPlaceholder::DisablePowerSaverForInstance() { 82 void PluginPlaceholder::DisablePowerSaverForInstance() {
82 power_saver_mode_ = content::RenderFrame::POWER_SAVER_MODE_ESSENTIAL; 83 power_saver_mode_ =
84 content::PluginInstanceThrottler::POWER_SAVER_MODE_ESSENTIAL;
83 if (is_blocked_for_power_saver_poster_) { 85 if (is_blocked_for_power_saver_poster_) {
84 is_blocked_for_power_saver_poster_ = false; 86 is_blocked_for_power_saver_poster_ = false;
85 if (!LoadingBlocked()) 87 if (!LoadingBlocked())
86 LoadPlugin(); 88 LoadPlugin();
87 } 89 }
88 } 90 }
89 #endif 91 #endif
90 92
91 gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder( 93 gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder(
92 v8::Isolate* isolate) { 94 v8::Isolate* isolate) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // event propagation changes between "close" vs. "click-to-play". 242 // event propagation changes between "close" vs. "click-to-play".
241 if (hidden_) 243 if (hidden_)
242 return; 244 return;
243 if (!plugin_) 245 if (!plugin_)
244 return; 246 return;
245 if (!allow_loading_) { 247 if (!allow_loading_) {
246 NOTREACHED(); 248 NOTREACHED();
247 return; 249 return;
248 } 250 }
249 251
252 scoped_ptr<content::PluginInstanceThrottler> throttler;
253 #if defined(ENABLE_PLUGINS)
254 if (power_saver_mode_ !=
255 content::PluginInstanceThrottler::POWER_SAVER_MODE_ESSENTIAL) {
256 throttler.reset(
257 content::PluginInstanceThrottler::Create(
258 render_frame(), plugin_params_.url, power_saver_mode_).release());
piman 2015/01/14 19:15:43 ditto
tommycli 2015/01/14 19:22:05 Done.
259 }
260 #endif
250 // TODO(mmenke): In the case of prerendering, feed into 261 // TODO(mmenke): In the case of prerendering, feed into
251 // ChromeContentRendererClient::CreatePlugin instead, to 262 // ChromeContentRendererClient::CreatePlugin instead, to
252 // reduce the chance of future regressions. 263 // reduce the chance of future regressions.
253 WebPlugin* plugin = render_frame()->CreatePlugin( 264 WebPlugin* plugin = render_frame()->CreatePlugin(
254 frame_, plugin_info_, plugin_params_, power_saver_mode_); 265 frame_, plugin_info_, plugin_params_, throttler.Pass());
255 ReplacePlugin(plugin); 266 ReplacePlugin(plugin);
256 } 267 }
257 268
258 void PluginPlaceholder::LoadCallback() { 269 void PluginPlaceholder::LoadCallback() {
259 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); 270 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click"));
260 // If the user specifically clicks on the plug-in content's placeholder, 271 // If the user specifically clicks on the plug-in content's placeholder,
261 // disable power saver throttling for this instance. 272 // disable power saver throttling for this instance.
262 #if defined(ENABLE_PLUGINS) 273 #if defined(ENABLE_PLUGINS)
263 DisablePowerSaverForInstance(); 274 DisablePowerSaverForInstance();
264 #endif 275 #endif
(...skipping 30 matching lines...) Expand all
295 return plugin_params_; 306 return plugin_params_;
296 } 307 }
297 308
298 bool PluginPlaceholder::LoadingBlocked() const { 309 bool PluginPlaceholder::LoadingBlocked() const {
299 DCHECK(allow_loading_); 310 DCHECK(allow_loading_);
300 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || 311 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ ||
301 is_blocked_for_prerendering_; 312 is_blocked_for_prerendering_;
302 } 313 }
303 314
304 } // namespace plugins 315 } // namespace plugins
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698