summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortommycli <tommycli@chromium.org>2015-04-29 14:41:25 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-29 21:42:09 +0000
commitfd2d6d70942f4a64845022066098622809c189e9 (patch)
treeecceed3c63ec0c16b2b13ef76368bd791fd3c7ad
parent2af423f68fbcd51366b90ba953ead51b16f0b85b (diff)
downloadchromium_src-fd2d6d70942f4a64845022066098622809c189e9.zip
chromium_src-fd2d6d70942f4a64845022066098622809c189e9.tar.gz
chromium_src-fd2d6d70942f4a64845022066098622809c189e9.tar.bz2
Plugin Power Saver: Fix double-counting NEVER case in LoadablePluginPlaceholder.
Also: - Remove some redundant bool variables from LoadablePluginPlaceholder. - Remove LoadablePluginPlaceholder observing the throttler. (No longer necessary). BUG=482205 Review URL: https://codereview.chromium.org/1111893003 Cr-Commit-Position: refs/heads/master@{#327572}
-rw-r--r--components/plugins/renderer/loadable_plugin_placeholder.cc58
-rw-r--r--components/plugins/renderer/loadable_plugin_placeholder.h22
2 files changed, 28 insertions, 52 deletions
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.cc b/components/plugins/renderer/loadable_plugin_placeholder.cc
index 3719130..6b2a0dd 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.cc
+++ b/components/plugins/renderer/loadable_plugin_placeholder.cc
@@ -47,16 +47,14 @@ void LoadablePluginPlaceholder::BlockForPowerSaverPoster() {
weak_factory_.GetWeakPtr(),
PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST));
}
-#endif
void LoadablePluginPlaceholder::SetPremadePlugin(
content::PluginInstanceThrottler* throttler) {
DCHECK(throttler);
DCHECK(!premade_throttler_);
premade_throttler_ = throttler;
-
- premade_throttler_->AddObserver(this);
}
+#endif
LoadablePluginPlaceholder::LoadablePluginPlaceholder(
content::RenderFrame* render_frame,
@@ -73,34 +71,24 @@ LoadablePluginPlaceholder::LoadablePluginPlaceholder(
is_blocked_for_prerendering_(false),
is_blocked_for_power_saver_poster_(false),
power_saver_enabled_(false),
- plugin_marked_essential_(false),
premade_throttler_(nullptr),
allow_loading_(false),
- placeholder_was_replaced_(false),
hidden_(false),
finished_loading_(false),
weak_factory_(this) {
}
LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
-#if defined(ENABLE_PLUGINS)
- DCHECK(!premade_throttler_);
-
- if (!plugin_marked_essential_ && !placeholder_was_replaced_ &&
- !is_blocked_for_prerendering_ && is_blocked_for_power_saver_poster_) {
- PluginInstanceThrottler::RecordUnthrottleMethodMetric(
- PluginInstanceThrottler::UNTHROTTLE_METHOD_NEVER);
- }
-#endif
}
#if defined(ENABLE_PLUGINS)
void LoadablePluginPlaceholder::MarkPluginEssential(
PluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
- if (plugin_marked_essential_)
+ if (!power_saver_enabled_)
return;
- plugin_marked_essential_ = true;
+ power_saver_enabled_ = false;
+
if (premade_throttler_)
premade_throttler_->MarkPluginEssential(method);
else
@@ -148,8 +136,6 @@ void LoadablePluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) {
return;
}
- placeholder_was_replaced_ = true;
-
// During initialization, the new plugin might have replaced itself in turn
// with another plugin. Make sure not to use the passed in |new_plugin| after
// this point.
@@ -226,13 +212,23 @@ void LoadablePluginPlaceholder::UpdateMessage() {
}
void LoadablePluginPlaceholder::PluginDestroyed() {
- // Since the premade plugin has been detached from the container, it will not
- // be automatically destroyed along with the page.
- if (!placeholder_was_replaced_ && premade_throttler_) {
- premade_throttler_->RemoveObserver(this);
- premade_throttler_->GetWebPlugin()->destroy();
- premade_throttler_ = nullptr;
+#if defined(ENABLE_PLUGINS)
+ if (power_saver_enabled_) {
+ if (premade_throttler_) {
+ // Since the premade plugin has been detached from the container, it will
+ // not be automatically destroyed along with the page.
+ premade_throttler_->GetWebPlugin()->destroy();
+ premade_throttler_ = nullptr;
+ } else if (is_blocked_for_power_saver_poster_) {
+ // Record the NEVER unthrottle count only if there is no throttler.
+ PluginInstanceThrottler::RecordUnthrottleMethodMetric(
+ PluginInstanceThrottler::UNTHROTTLE_METHOD_NEVER);
+ }
+
+ // Prevent processing subsequent calls to MarkPluginEssential.
+ power_saver_enabled_ = false;
}
+#endif
PluginPlaceholder::PluginDestroyed();
}
@@ -245,14 +241,6 @@ void LoadablePluginPlaceholder::WasShown() {
}
}
-void LoadablePluginPlaceholder::OnThrottleStateChange() {
- DCHECK(premade_throttler_);
- if (!premade_throttler_->IsThrottled()) {
- // Premade plugin has been unthrottled externally (by audio playback, etc.).
- LoadPlugin();
- }
-}
-
void LoadablePluginPlaceholder::OnLoadBlockedPlugins(
const std::string& identifier) {
if (!identifier.empty() && identifier != identifier_)
@@ -286,9 +274,7 @@ void LoadablePluginPlaceholder::LoadPlugin() {
}
if (premade_throttler_) {
- premade_throttler_->RemoveObserver(this);
premade_throttler_->SetHiddenForPlaceholder(false /* hidden */);
-
ReplacePlugin(premade_throttler_->GetWebPlugin());
premade_throttler_ = nullptr;
} else {
@@ -299,7 +285,7 @@ void LoadablePluginPlaceholder::LoadPlugin() {
#if defined(ENABLE_PLUGINS)
// If the plugin has already been marked essential in its placeholder form,
// we shouldn't create a new throttler and start the process all over again.
- if (!plugin_marked_essential_ && power_saver_enabled_)
+ if (power_saver_enabled_)
throttler = PluginInstanceThrottler::Create();
#endif
WebPlugin* plugin = render_frame()->CreatePlugin(
@@ -331,7 +317,7 @@ void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
// Wait for the placeholder to finish loading to hide the premade plugin.
// This is necessary to prevent a flicker.
- if (premade_throttler_ && !placeholder_was_replaced_)
+ if (premade_throttler_ && power_saver_enabled_)
premade_throttler_->SetHiddenForPlaceholder(true /* hidden */);
}
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.h b/components/plugins/renderer/loadable_plugin_placeholder.h
index e67c861..53ef5e1 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.h
+++ b/components/plugins/renderer/loadable_plugin_placeholder.h
@@ -13,9 +13,7 @@
namespace plugins {
// Placeholders can be used if a plugin is missing or not available
// (blocked or disabled).
-class LoadablePluginPlaceholder
- : public PluginPlaceholder,
- public content::PluginInstanceThrottler::Observer {
+class LoadablePluginPlaceholder : public PluginPlaceholder {
public:
void set_blocked_for_background_tab(bool blocked_for_background_tab) {
is_blocked_for_background_tab_ = blocked_for_background_tab;
@@ -32,12 +30,12 @@ class LoadablePluginPlaceholder
// Defer loading of plugin, and instead show the Power Saver poster image.
void BlockForPowerSaverPoster();
-#endif
-
- void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; }
// When we load the plugin, use this already-created plugin, not a new one.
void SetPremadePlugin(content::PluginInstanceThrottler* throttler);
+#endif
+
+ void set_allow_loading(bool allow_loading) { allow_loading_ = allow_loading; }
protected:
LoadablePluginPlaceholder(content::RenderFrame* render_frame,
@@ -83,9 +81,6 @@ class LoadablePluginPlaceholder
// RenderFrameObserver methods:
void WasShown() override;
- // content::PluginInstanceThrottler::Observer methods:
- void OnThrottleStateChange() override;
-
// Javascript callbacks:
// Load the blocked plugin by calling LoadPlugin().
@@ -115,20 +110,15 @@ class LoadablePluginPlaceholder
// True if the plugin load was deferred due to a Power Saver poster.
bool is_blocked_for_power_saver_poster_;
- // This is independent of deferred plugin load due to a Power Saver poster.
+ // True if power saver is enabled for this plugin and it has not been marked
+ // essential (by a click or retroactive whitelisting).
bool power_saver_enabled_;
- // True if the plugin has been marked essential.
- bool plugin_marked_essential_;
-
// When we load, uses this premade plugin instead of creating a new one.
content::PluginInstanceThrottler* premade_throttler_;
bool allow_loading_;
- // True if the placeholder was replaced with the real plugin.
- bool placeholder_was_replaced_;
-
bool hidden_;
bool finished_loading_;
std::string identifier_;