Chromium Code Reviews| Index: content/renderer/pepper/pepper_plugin_instance_impl.cc |
| diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc |
| index 4efdbb6458c958fbda35c459dc4fe58886c3ee59..803bdff7f999ceb9cfc2a734aa469044ab19b37d 100644 |
| --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc |
| +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc |
| @@ -6,12 +6,10 @@ |
| #include "base/bind.h" |
| #include "base/callback_helpers.h" |
| -#include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| #include "base/logging.h" |
| #include "base/memory/linked_ptr.h" |
| #include "base/message_loop/message_loop.h" |
| -#include "base/metrics/histogram.h" |
| #include "base/stl_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_offset_string_conversions.h" |
| @@ -25,7 +23,6 @@ |
| #include "content/common/frame_messages.h" |
| #include "content/common/input/web_input_event_traits.h" |
| #include "content/public/common/content_constants.h" |
| -#include "content/public/common/content_switches.h" |
| #include "content/public/common/page_zoom.h" |
| #include "content/public/renderer/content_renderer_client.h" |
| #include "content/renderer/gpu/render_widget_compositor.h" |
| @@ -47,7 +44,6 @@ |
| #include "content/renderer/pepper/pepper_url_loader_host.h" |
| #include "content/renderer/pepper/plugin_module.h" |
| #include "content/renderer/pepper/plugin_object.h" |
| -#include "content/renderer/pepper/plugin_power_saver_helper.h" |
| #include "content/renderer/pepper/ppapi_preferences_builder.h" |
| #include "content/renderer/pepper/ppb_buffer_impl.h" |
| #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
| @@ -112,7 +108,6 @@ |
| #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| #include "third_party/WebKit/public/web/WebDataSource.h" |
| #include "third_party/WebKit/public/web/WebDocument.h" |
| -#include "third_party/WebKit/public/web/WebElement.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| @@ -391,26 +386,6 @@ void InitLatencyInfo(ui::LatencyInfo* new_latency, |
| } |
| } |
| -// How the throttled power saver is unthrottled, if ever. |
| -// These numeric values are used in UMA logs; do not change them. |
| -enum PowerSaverUnthrottleMethod { |
| - UNTHROTTLE_METHOD_NEVER = 0, |
| - UNTHROTTLE_METHOD_BY_CLICK = 1, |
| - UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
| - UNTHROTTLE_METHOD_NUM_ITEMS |
| -}; |
| - |
| -const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaverUnthrottle"; |
| - |
| -void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) { |
| - UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method, |
| - UNTHROTTLE_METHOD_NUM_ITEMS); |
| -} |
| - |
| -bool IsFlashPlugin(PluginModule* module) { |
| - return module->name() == kFlashPluginName; |
| -} |
| - |
| } // namespace |
| // static |
| @@ -511,9 +486,6 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl( |
| layer_bound_to_fullscreen_(false), |
| layer_is_hardware_(false), |
| plugin_url_(plugin_url), |
| - power_saver_enabled_(false), |
| - is_peripheral_content_(false), |
| - plugin_throttled_(false), |
| full_frame_(false), |
| sent_initial_did_change_view_(false), |
| bound_graphics_2d_platform_(NULL), |
| @@ -607,7 +579,7 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl( |
| GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
| external_document_load_ = true; |
| - if (IsFlashPlugin(module_.get())) { |
| + if (module->name() == kFlashPluginName) { |
| RenderThread::Get()->RecordAction( |
| base::UserMetricsAction("Flash.PluginInstanceCreated")); |
| } |
| @@ -616,9 +588,6 @@ PepperPluginInstanceImpl::PepperPluginInstanceImpl( |
| PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
| DCHECK(!fullscreen_container_); |
| - if (plugin_throttled_) |
| - RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
| - |
| // Notify all the plugin objects of deletion. This will prevent blink from |
| // calling into the plugin any more. |
| // |
| @@ -871,37 +840,9 @@ bool PepperPluginInstanceImpl::Initialize( |
| if (!render_frame_) |
| return false; |
| - PluginPowerSaverHelper* power_saver_helper = |
| - render_frame_->plugin_power_saver_helper(); |
| - GURL content_origin = plugin_url_.GetOrigin(); |
| - blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| - |
| - bool cross_origin = false; |
| - is_peripheral_content_ = |
| - IsFlashPlugin(module_.get()) && |
| - power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, |
| - bounds.height, &cross_origin); |
| - |
| - power_saver_enabled_ = is_peripheral_content_ && |
| - base::CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kEnablePluginPowerSaver); |
| - |
| - if (is_peripheral_content_) { |
| - // To collect UMAs, register peripheral content even if we don't throttle. |
| - power_saver_helper->RegisterPeripheralPlugin( |
| - content_origin, |
| - base::Bind( |
| - &PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist, |
| - weak_factory_.GetWeakPtr())); |
| - |
| - if (power_saver_enabled_) { |
| - throttler_.reset(new PepperPluginInstanceThrottler( |
| - base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, |
| - weak_factory_.GetWeakPtr(), true /* throttled */))); |
| - } |
| - } else if (cross_origin) { |
| - power_saver_helper->WhitelistContentOrigin(content_origin); |
| - } |
| + throttler_.reset(new PepperPluginInstanceThrottler( |
| + this, base::Bind(&PepperPluginInstanceImpl::SendDidChangeView, |
|
raymes
2014/11/10 02:34:20
Since we're already passing the PepperPluginInstan
tommycli
2014/11/11 19:54:30
Yes we can, but then we have to make SendDidChange
|
| + weak_factory_.GetWeakPtr()))); |
| message_channel_ = MessageChannel::Create(this, &message_channel_object_); |
| @@ -1158,17 +1099,8 @@ bool PepperPluginInstanceImpl::HandleInputEvent( |
| WebCursorInfo* cursor_info) { |
| TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
| - if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { |
| - is_peripheral_content_ = false; |
| - power_saver_enabled_ = false; |
| - |
| - RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK); |
| - |
| - if (plugin_throttled_) { |
| - SetPluginThrottled(false /* throttled */); |
| - return true; |
| - } |
| - } |
| + if (throttler_->ConsumeInputEvent(event)) |
| + return true; |
| if (!render_frame_) |
| return false; |
| @@ -1721,8 +1653,9 @@ void PepperPluginInstanceImpl::SendDidChangeView() { |
| return; |
| // When plugin is throttled, send ViewData indicating it's in the background. |
| - const ppapi::ViewData& view_data = |
| - plugin_throttled_ ? empty_view_data_ : view_data_; |
| + const ppapi::ViewData& view_data = throttler_->is_throttled() |
| + ? throttler_->throttled_view_data() |
| + : view_data_; |
| if (view_change_weak_ptr_factory_.HasWeakPtrs() || |
| (sent_initial_did_change_view_ && |
| @@ -3352,24 +3285,4 @@ void PepperPluginInstanceImpl::DidDataFromWebURLResponse( |
| } |
| } |
| -void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
| - // Do not throttle if we've already disabled power saver. |
| - if (!power_saver_enabled_ && throttled) |
| - return; |
| - |
| - plugin_throttled_ = throttled; |
| - SendDidChangeView(); |
| -} |
| - |
| -void PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist() { |
| - if (!is_peripheral_content_) |
| - return; |
| - |
| - is_peripheral_content_ = false; |
| - power_saver_enabled_ = false; |
| - SetPluginThrottled(false); |
| - |
| - RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST); |
| -} |
| - |
| } // namespace content |