| Index: content/renderer/pepper/plugin_instance_throttler_impl.cc
|
| diff --git a/content/renderer/pepper/pepper_plugin_instance_throttler.cc b/content/renderer/pepper/plugin_instance_throttler_impl.cc
|
| similarity index 43%
|
| rename from content/renderer/pepper/pepper_plugin_instance_throttler.cc
|
| rename to content/renderer/pepper/plugin_instance_throttler_impl.cc
|
| index 81382093e84ee05fd4966e6754e7617d2a5d1aa3..4d04cb7a289802328ea05530a6ec33492f6a20b4 100644
|
| --- a/content/renderer/pepper/pepper_plugin_instance_throttler.cc
|
| +++ b/content/renderer/pepper/plugin_instance_throttler_impl.cc
|
| @@ -2,12 +2,12 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/renderer/pepper/pepper_plugin_instance_throttler.h"
|
| +#include "content/renderer/pepper/plugin_instance_throttler_impl.h"
|
|
|
| #include "base/metrics/histogram.h"
|
| -#include "base/metrics/sparse_histogram.h"
|
| #include "base/time/time.h"
|
| #include "content/public/common/content_constants.h"
|
| +#include "content/public/renderer/render_frame.h"
|
| #include "content/public/renderer/render_thread.h"
|
| #include "third_party/WebKit/public/web/WebInputEvent.h"
|
| #include "ui/gfx/color_utils.h"
|
| @@ -17,70 +17,13 @@ namespace content {
|
|
|
| namespace {
|
|
|
| -static const int kInfiniteRatio = 99999;
|
| -
|
| -#define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \
|
| - UMA_HISTOGRAM_SPARSE_SLOWLY( \
|
| - name, (height) ? ((width)*100) / (height) : kInfiniteRatio);
|
| -
|
| -// Histogram tracking prevalence of tiny Flash instances. Units in pixels.
|
| -enum PluginFlashTinyContentSize {
|
| - TINY_CONTENT_SIZE_1_1 = 0,
|
| - TINY_CONTENT_SIZE_5_5 = 1,
|
| - TINY_CONTENT_SIZE_10_10 = 2,
|
| - TINY_CONTENT_SIZE_LARGE = 3,
|
| - TINY_CONTENT_SIZE_NUM_ITEMS
|
| -};
|
| -
|
| -const char kFlashClickSizeAspectRatioHistogram[] =
|
| - "Plugin.Flash.ClickSize.AspectRatio";
|
| -const char kFlashClickSizeHeightHistogram[] = "Plugin.Flash.ClickSize.Height";
|
| -const char kFlashClickSizeWidthHistogram[] = "Plugin.Flash.ClickSize.Width";
|
| -const char kFlashTinyContentSizeHistogram[] = "Plugin.Flash.TinyContentSize";
|
| const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaver.Unthrottle";
|
|
|
| -// Record size metrics for all Flash instances.
|
| -void RecordFlashSizeMetric(int width, int height) {
|
| - PluginFlashTinyContentSize size = TINY_CONTENT_SIZE_LARGE;
|
| -
|
| - if (width <= 1 && height <= 1)
|
| - size = TINY_CONTENT_SIZE_1_1;
|
| - else if (width <= 5 && height <= 5)
|
| - size = TINY_CONTENT_SIZE_5_5;
|
| - else if (width <= 10 && height <= 10)
|
| - size = TINY_CONTENT_SIZE_10_10;
|
| -
|
| - UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, size,
|
| - TINY_CONTENT_SIZE_NUM_ITEMS);
|
| -}
|
| -
|
| void RecordUnthrottleMethodMetric(
|
| - PepperPluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
|
| + PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) {
|
| UMA_HISTOGRAM_ENUMERATION(
|
| kPowerSaverUnthrottleHistogram, method,
|
| - PepperPluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS);
|
| -}
|
| -
|
| -// Records size metrics for Flash instances that are clicked.
|
| -void RecordFlashClickSizeMetric(int width, int height) {
|
| - base::HistogramBase* width_histogram = base::LinearHistogram::FactoryGet(
|
| - kFlashClickSizeWidthHistogram,
|
| - 0, // minimum width
|
| - 500, // maximum width
|
| - 100, // number of buckets.
|
| - base::HistogramBase::kUmaTargetedHistogramFlag);
|
| - width_histogram->Add(width);
|
| -
|
| - base::HistogramBase* height_histogram = base::LinearHistogram::FactoryGet(
|
| - kFlashClickSizeHeightHistogram,
|
| - 0, // minimum height
|
| - 400, // maximum height
|
| - 100, // number of buckets.
|
| - base::HistogramBase::kUmaTargetedHistogramFlag);
|
| - height_histogram->Add(height);
|
| -
|
| - UMA_HISTOGRAM_ASPECT_RATIO(kFlashClickSizeAspectRatioHistogram, width,
|
| - height);
|
| + PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS);
|
| }
|
|
|
| // When we give up waiting for a suitable preview frame, and simply suspend
|
| @@ -96,58 +39,62 @@ const int kMinimumConsecutiveInterestingFrames = 4;
|
|
|
| } // namespace
|
|
|
| -PepperPluginInstanceThrottler::PepperPluginInstanceThrottler(
|
| +PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl(
|
| RenderFrame* frame,
|
| - const blink::WebRect& bounds,
|
| - bool is_flash_plugin,
|
| const GURL& plugin_url,
|
| - RenderFrame::PluginPowerSaverMode power_saver_mode,
|
| - const base::Closure& throttle_change_callback)
|
| - : bounds_(bounds),
|
| - throttle_change_callback_(throttle_change_callback),
|
| - is_flash_plugin_(is_flash_plugin),
|
| - needs_representative_keyframe_(false),
|
| + PluginPowerSaverMode power_saver_mode)
|
| + : needs_representative_keyframe_(false),
|
| consecutive_interesting_frames_(0),
|
| - has_been_clicked_(false),
|
| - power_saver_enabled_(false),
|
| - is_peripheral_content_(power_saver_mode !=
|
| - RenderFrame::POWER_SAVER_MODE_ESSENTIAL),
|
| + power_saver_enabled_(power_saver_mode ==
|
| + POWER_SAVER_MODE_PERIPHERAL_THROTTLED),
|
| + has_been_unthrottled_(false),
|
| plugin_throttled_(false),
|
| weak_factory_(this) {
|
| - if (is_flash_plugin_ && RenderThread::Get()) {
|
| - RenderThread::Get()->RecordAction(
|
| - base::UserMetricsAction("Flash.PluginInstanceCreated"));
|
| - RecordFlashSizeMetric(bounds.width, bounds.height);
|
| - }
|
| -
|
| - power_saver_enabled_ =
|
| - is_flash_plugin_ &&
|
| - power_saver_mode == RenderFrame::POWER_SAVER_MODE_PERIPHERAL_THROTTLED;
|
| -
|
| - GURL content_origin = plugin_url.GetOrigin();
|
| -
|
| // To collect UMAs, register peripheral content even if power saver disabled.
|
| if (frame) {
|
| frame->RegisterPeripheralPlugin(
|
| - content_origin,
|
| - base::Bind(&PepperPluginInstanceThrottler::DisablePowerSaver,
|
| + plugin_url.GetOrigin(),
|
| + base::Bind(&PluginInstanceThrottlerImpl::DisablePowerSaver,
|
| weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST));
|
| }
|
|
|
| if (power_saver_enabled_) {
|
| needs_representative_keyframe_ = true;
|
| base::MessageLoop::current()->PostDelayedTask(
|
| - FROM_HERE,
|
| - base::Bind(&PepperPluginInstanceThrottler::SetPluginThrottled,
|
| - weak_factory_.GetWeakPtr(), true /* throttled */),
|
| + FROM_HERE, base::Bind(&PluginInstanceThrottlerImpl::SetPluginThrottled,
|
| + weak_factory_.GetWeakPtr(), true /* throttled */),
|
| base::TimeDelta::FromMilliseconds(kThrottleTimeout));
|
| }
|
| }
|
|
|
| -PepperPluginInstanceThrottler::~PepperPluginInstanceThrottler() {
|
| +PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() {
|
| +}
|
| +
|
| +void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) {
|
| + observer_list_.AddObserver(observer);
|
| +}
|
| +
|
| +void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) {
|
| + observer_list_.RemoveObserver(observer);
|
| +}
|
| +
|
| +bool PluginInstanceThrottlerImpl::IsThrottled() const {
|
| + return plugin_throttled_;
|
| +}
|
| +
|
| +void PluginInstanceThrottlerImpl::DisablePowerSaver(
|
| + PowerSaverUnthrottleMethod method) {
|
| + if (has_been_unthrottled_)
|
| + return;
|
| +
|
| + has_been_unthrottled_ = true;
|
| + power_saver_enabled_ = false;
|
| + SetPluginThrottled(false);
|
| +
|
| + RecordUnthrottleMethodMetric(method);
|
| }
|
|
|
| -void PepperPluginInstanceThrottler::OnImageFlush(const SkBitmap* bitmap) {
|
| +void PluginInstanceThrottlerImpl::OnImageFlush(const SkBitmap* bitmap) {
|
| if (!needs_representative_keyframe_ || !bitmap)
|
| return;
|
|
|
| @@ -161,7 +108,7 @@ void PepperPluginInstanceThrottler::OnImageFlush(const SkBitmap* bitmap) {
|
| SetPluginThrottled(true);
|
| }
|
|
|
| -bool PepperPluginInstanceThrottler::ConsumeInputEvent(
|
| +bool PluginInstanceThrottlerImpl::ConsumeInputEvent(
|
| const blink::WebInputEvent& event) {
|
| // Always allow right-clicks through so users may verify it's a plug-in.
|
| // TODO(tommycli): We should instead show a custom context menu (probably
|
| @@ -170,16 +117,9 @@ bool PepperPluginInstanceThrottler::ConsumeInputEvent(
|
| if (event.modifiers & blink::WebInputEvent::Modifiers::RightButtonDown)
|
| return false;
|
|
|
| - if (!has_been_clicked_ && is_flash_plugin_ &&
|
| - event.type == blink::WebInputEvent::MouseDown &&
|
| - (event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
|
| - has_been_clicked_ = true;
|
| - RecordFlashClickSizeMetric(bounds_.width, bounds_.height);
|
| - }
|
| -
|
| - if (is_peripheral_content_ && event.type == blink::WebInputEvent::MouseUp &&
|
| + if (!has_been_unthrottled_ && event.type == blink::WebInputEvent::MouseUp &&
|
| (event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
|
| - is_peripheral_content_ = false;
|
| + has_been_unthrottled_ = true;
|
| power_saver_enabled_ = false;
|
| needs_representative_keyframe_ = false;
|
|
|
| @@ -194,19 +134,7 @@ bool PepperPluginInstanceThrottler::ConsumeInputEvent(
|
| return plugin_throttled_;
|
| }
|
|
|
| -void PepperPluginInstanceThrottler::DisablePowerSaver(
|
| - PowerSaverUnthrottleMethod method) {
|
| - if (!is_peripheral_content_)
|
| - return;
|
| -
|
| - is_peripheral_content_ = false;
|
| - power_saver_enabled_ = false;
|
| - SetPluginThrottled(false);
|
| -
|
| - RecordUnthrottleMethodMetric(method);
|
| -}
|
| -
|
| -void PepperPluginInstanceThrottler::SetPluginThrottled(bool throttled) {
|
| +void PluginInstanceThrottlerImpl::SetPluginThrottled(bool throttled) {
|
| // Do not throttle if we've already disabled power saver.
|
| if (!power_saver_enabled_ && throttled)
|
| return;
|
| @@ -215,7 +143,7 @@ void PepperPluginInstanceThrottler::SetPluginThrottled(bool throttled) {
|
| needs_representative_keyframe_ = false;
|
|
|
| plugin_throttled_ = throttled;
|
| - throttle_change_callback_.Run();
|
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
|
| }
|
|
|
| } // namespace content
|
|
|