| Index: content/renderer/pepper/pepper_plugin_instance_metrics.cc
|
| diff --git a/content/renderer/pepper/pepper_plugin_instance_throttler.cc b/content/renderer/pepper/pepper_plugin_instance_metrics.cc
|
| similarity index 29%
|
| copy from content/renderer/pepper/pepper_plugin_instance_throttler.cc
|
| copy to content/renderer/pepper/pepper_plugin_instance_metrics.cc
|
| index 81382093e84ee05fd4966e6754e7617d2a5d1aa3..1c8a0e28f5ae99a0d54ca75cfff085deccd4ba6d 100644
|
| --- a/content/renderer/pepper/pepper_plugin_instance_throttler.cc
|
| +++ b/content/renderer/pepper/pepper_plugin_instance_metrics.cc
|
| @@ -1,28 +1,25 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // 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/pepper_plugin_instance_metrics.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_thread.h"
|
| -#include "third_party/WebKit/public/web/WebInputEvent.h"
|
| -#include "ui/gfx/color_utils.h"
|
| -#include "url/gurl.h"
|
| +#include "ppapi/shared_impl/ppapi_preferences.h"
|
|
|
| -namespace content {
|
| -
|
| -namespace {
|
| -
|
| -static const int kInfiniteRatio = 99999;
|
| +#if defined(OS_WIN)
|
| +#include "base/win/windows_version.h"
|
| +#endif
|
|
|
| #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \
|
| UMA_HISTOGRAM_SPARSE_SLOWLY( \
|
| name, (height) ? ((width)*100) / (height) : kInfiniteRatio);
|
|
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| // Histogram tracking prevalence of tiny Flash instances. Units in pixels.
|
| enum PluginFlashTinyContentSize {
|
| TINY_CONTENT_SIZE_1_1 = 0,
|
| @@ -32,14 +29,16 @@ enum PluginFlashTinyContentSize {
|
| TINY_CONTENT_SIZE_NUM_ITEMS
|
| };
|
|
|
| +const int kInfiniteRatio = 99999;
|
| +
|
| 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.
|
| +} // namespace
|
| +
|
| void RecordFlashSizeMetric(int width, int height) {
|
| PluginFlashTinyContentSize size = TINY_CONTENT_SIZE_LARGE;
|
|
|
| @@ -54,14 +53,6 @@ void RecordFlashSizeMetric(int width, int height) {
|
| TINY_CONTENT_SIZE_NUM_ITEMS);
|
| }
|
|
|
| -void RecordUnthrottleMethodMetric(
|
| - PepperPluginInstanceThrottler::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,
|
| @@ -83,139 +74,35 @@ void RecordFlashClickSizeMetric(int width, int height) {
|
| height);
|
| }
|
|
|
| -// When we give up waiting for a suitable preview frame, and simply suspend
|
| -// the plugin where it's at. In milliseconds.
|
| -const int kThrottleTimeout = 5000;
|
| -
|
| -// Threshold for 'boring' score to accept a frame as good enough to be a
|
| -// representative keyframe. Units are the ratio of all pixels that are within
|
| -// the most common luma bin. The same threshold is used for history thumbnails.
|
| -const double kAcceptableFrameMaximumBoringness = 0.94;
|
| -
|
| -const int kMinimumConsecutiveInterestingFrames = 4;
|
| -
|
| -} // namespace
|
| -
|
| -PepperPluginInstanceThrottler::PepperPluginInstanceThrottler(
|
| - 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),
|
| - consecutive_interesting_frames_(0),
|
| - has_been_clicked_(false),
|
| - power_saver_enabled_(false),
|
| - is_peripheral_content_(power_saver_mode !=
|
| - RenderFrame::POWER_SAVER_MODE_ESSENTIAL),
|
| - 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,
|
| - 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 */),
|
| - base::TimeDelta::FromMilliseconds(kThrottleTimeout));
|
| - }
|
| -}
|
| -
|
| -PepperPluginInstanceThrottler::~PepperPluginInstanceThrottler() {
|
| -}
|
| -
|
| -void PepperPluginInstanceThrottler::OnImageFlush(const SkBitmap* bitmap) {
|
| - if (!needs_representative_keyframe_ || !bitmap)
|
| - return;
|
| -
|
| - double boring_score = color_utils::CalculateBoringScore(*bitmap);
|
| - if (boring_score <= kAcceptableFrameMaximumBoringness)
|
| - ++consecutive_interesting_frames_;
|
| - else
|
| - consecutive_interesting_frames_ = 0;
|
| -
|
| - if (consecutive_interesting_frames_ >= kMinimumConsecutiveInterestingFrames)
|
| - SetPluginThrottled(true);
|
| -}
|
| -
|
| -bool PepperPluginInstanceThrottler::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
|
| - // using PluginPlaceholder) so users aren't confused and try to click the
|
| - // Flash-internal 'Play' menu item. This is a stopgap solution.
|
| - 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 &&
|
| - (event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
|
| - is_peripheral_content_ = false;
|
| - power_saver_enabled_ = false;
|
| - needs_representative_keyframe_ = false;
|
| -
|
| - RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK);
|
| -
|
| - if (plugin_throttled_) {
|
| - SetPluginThrottled(false /* throttled */);
|
| - return true;
|
| +void SetGPUHistogram(const ppapi::Preferences& prefs,
|
| + const std::vector<std::string>& arg_names,
|
| + const std::vector<std::string>& arg_values) {
|
| +// Calculate a histogram to let us determine how likely people are to try to
|
| +// run Stage3D content on machines that have it blacklisted.
|
| +#if defined(OS_WIN)
|
| + bool needs_gpu = false;
|
| + bool is_xp = base::win::GetVersion() <= base::win::VERSION_XP;
|
| +
|
| + for (size_t i = 0; i < arg_names.size(); i++) {
|
| + if (arg_names[i] == "wmode") {
|
| + // In theory content other than Flash could have a "wmode" argument,
|
| + // but that's pretty unlikely.
|
| + if (arg_values[i] == "direct" || arg_values[i] == "gpu")
|
| + needs_gpu = true;
|
| + break;
|
| }
|
| }
|
| -
|
| - 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) {
|
| - // Do not throttle if we've already disabled power saver.
|
| - if (!power_saver_enabled_ && throttled)
|
| - return;
|
| -
|
| - // Once we change the throttle state, we will never need the snapshot again.
|
| - needs_representative_keyframe_ = false;
|
| -
|
| - plugin_throttled_ = throttled;
|
| - throttle_change_callback_.Run();
|
| + // 0 : No 3D content and GPU is blacklisted
|
| + // 1 : No 3D content and GPU is not blacklisted
|
| + // 2 : 3D content but GPU is blacklisted
|
| + // 3 : 3D content and GPU is not blacklisted
|
| + // 4 : No 3D content and GPU is blacklisted on XP
|
| + // 5 : No 3D content and GPU is not blacklisted on XP
|
| + // 6 : 3D content but GPU is blacklisted on XP
|
| + // 7 : 3D content and GPU is not blacklisted on XP
|
| + UMA_HISTOGRAM_ENUMERATION(
|
| + "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8);
|
| +#endif
|
| }
|
|
|
| } // namespace content
|
|
|