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

Unified Diff: content/renderer/pepper/plugin_module.cc

Issue 1132873002: Plugin Power Saver: Fix poster-click flaky test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0275-plugin-power-saver-preserve-js-access-for-throttled-plugins
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/plugin_module.cc
diff --git a/content/renderer/pepper/plugin_module.cc b/content/renderer/pepper/plugin_module.cc
index bb7b5e8cef9adfc37a42ea5b59b1b43d5effc2b8..2752840e2f418df0f49903a7026ffbe9913f994c 100644
--- a/content/renderer/pepper/plugin_module.cc
+++ b/content/renderer/pepper/plugin_module.cc
@@ -187,50 +187,63 @@ class PowerSaverTestPluginDelegate : public PluginInstanceThrottler::Observer {
explicit PowerSaverTestPluginDelegate(PluginInstanceThrottlerImpl* throttler)
: throttler_(throttler) {
throttler_->AddObserver(this);
- PostPowerSaverStatusToJavaScript(throttler_, "initial");
+ PostPowerSaverStatusToJavaScript("initial");
}
virtual ~PowerSaverTestPluginDelegate() { throttler_->RemoveObserver(this); }
static void PostPowerSaverStatusToJavaScript(
tommycli 2015/05/08 19:26:58 The changes in this file are necessary because pre
- PluginInstanceThrottlerImpl* throttler,
+ PepperPluginInstanceImpl* instance,
const std::string& source) {
- if (!throttler->GetWebPlugin() || !throttler->GetWebPlugin()->instance())
- return;
+ DCHECK(instance);
+
+ bool is_hidden_for_placeholder = false;
+ bool is_peripheral = false;
+ bool is_throttled = false;
- PepperPluginInstanceImpl* instance = throttler->GetWebPlugin()->instance();
+ if (instance->throttler()) {
+ PluginInstanceThrottlerImpl* throttler = instance->throttler();
+ is_hidden_for_placeholder = throttler->IsHiddenForPlaceholder();
+ is_peripheral = throttler->power_saver_enabled();
+ is_throttled = throttler->IsThrottled();
+ }
// Refcounted by the returned PP_Var.
ppapi::DictionaryVar* dictionary = new ppapi::DictionaryVar;
dictionary->Set(ppapi::StringVar::StringToPPVar("source"),
ppapi::StringVar::StringToPPVar(source));
- dictionary->Set(
- ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"),
- PP_MakeBool(PP_FromBool(throttler->IsHiddenForPlaceholder())));
+ dictionary->Set(ppapi::StringVar::StringToPPVar("isHiddenForPlaceholder"),
+ PP_MakeBool(PP_FromBool(is_hidden_for_placeholder)));
dictionary->Set(ppapi::StringVar::StringToPPVar("isPeripheral"),
- PP_MakeBool(PP_FromBool(throttler->power_saver_enabled())));
+ PP_MakeBool(PP_FromBool(is_peripheral)));
dictionary->Set(ppapi::StringVar::StringToPPVar("isThrottled"),
- PP_MakeBool(PP_FromBool(throttler->IsThrottled())));
+ PP_MakeBool(PP_FromBool(is_throttled)));
instance->PostMessageToJavaScript(dictionary->GetPPVar());
}
private:
void OnThrottleStateChange() override {
- PostPowerSaverStatusToJavaScript(throttler_, "throttleStatusChange");
+ PostPowerSaverStatusToJavaScript("throttleStatusChange");
}
void OnPeripheralStateChange() override {
- PostPowerSaverStatusToJavaScript(throttler_, "peripheralStatusChange");
+ PostPowerSaverStatusToJavaScript("peripheralStatusChange");
}
void OnHiddenForPlaceholder(bool hidden) override {
- PostPowerSaverStatusToJavaScript(throttler_,
- "hiddenForPlaceholderStatusChange");
+ PostPowerSaverStatusToJavaScript("hiddenForPlaceholderStatusChange");
}
void OnThrottlerDestroyed() override { delete this; }
+ void PostPowerSaverStatusToJavaScript(const std::string& source) {
+ if (!throttler_->GetWebPlugin() || !throttler_->GetWebPlugin()->instance())
+ return;
+ PostPowerSaverStatusToJavaScript(throttler_->GetWebPlugin()->instance(),
+ source);
+ }
+
// Non-owning pointer.
PluginInstanceThrottlerImpl* const throttler_;
};
@@ -303,21 +316,27 @@ PP_Bool IsOutOfProcess() { return PP_FALSE; }
void PostPowerSaverStatus(PP_Instance instance_id) {
PepperPluginInstanceImpl* plugin_instance =
host_globals->GetInstance(instance_id);
- if (!plugin_instance || !plugin_instance->throttler())
+ if (!plugin_instance)
return;
PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript(
- plugin_instance->throttler(), "getPowerSaverStatusResponse");
+ plugin_instance, "getPowerSaverStatusResponse");
}
void SubscribeToPowerSaverNotifications(PP_Instance instance_id) {
PepperPluginInstanceImpl* plugin_instance =
host_globals->GetInstance(instance_id);
- if (!plugin_instance || !plugin_instance->throttler())
+ if (!plugin_instance)
return;
- // Manages its own lifetime.
- new PowerSaverTestPluginDelegate(plugin_instance->throttler());
+ if (plugin_instance->throttler()) {
+ // Manages its own lifetime.
+ new PowerSaverTestPluginDelegate(plugin_instance->throttler());
+ } else {
+ // Just send an initial status. This status will never be updated.
+ PowerSaverTestPluginDelegate::PostPowerSaverStatusToJavaScript(
+ plugin_instance, "initial");
+ }
}
void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) {
« content/public/common/content_switches.cc ('K') | « content/public/common/content_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698