blob: 548f64a8a965142bc1d2109bc6f8540adddb7e9f [file] [log] [blame]
tommyclie8722702015-01-16 11:40:411// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/renderer/pepper/pepper_plugin_instance_metrics.h"
6
avi1023d012015-12-25 02:39:147#include <stddef.h>
8
tommyclie8722702015-01-16 11:40:419#include "base/metrics/histogram.h"
10#include "base/metrics/sparse_histogram.h"
avi1023d012015-12-25 02:39:1411#include "build/build_config.h"
tommyclie8722702015-01-16 11:40:4112#include "ppapi/shared_impl/ppapi_preferences.h"
13
14#if defined(OS_WIN)
15#include "base/win/windows_version.h"
16#endif
17
18#define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \
19 UMA_HISTOGRAM_SPARSE_SLOWLY( \
20 name, (height) ? ((width)*100) / (height) : kInfiniteRatio);
21
22namespace content {
23
24namespace {
25
26// Histogram tracking prevalence of tiny Flash instances. Units in pixels.
27enum PluginFlashTinyContentSize {
28 TINY_CONTENT_SIZE_1_1 = 0,
29 TINY_CONTENT_SIZE_5_5 = 1,
30 TINY_CONTENT_SIZE_10_10 = 2,
31 TINY_CONTENT_SIZE_LARGE = 3,
32 TINY_CONTENT_SIZE_NUM_ITEMS
33};
34
35const int kInfiniteRatio = 99999;
36
37const char kFlashClickSizeAspectRatioHistogram[] =
38 "Plugin.Flash.ClickSize.AspectRatio";
39const char kFlashClickSizeHeightHistogram[] = "Plugin.Flash.ClickSize.Height";
40const char kFlashClickSizeWidthHistogram[] = "Plugin.Flash.ClickSize.Width";
41const char kFlashTinyContentSizeHistogram[] = "Plugin.Flash.TinyContentSize";
42
43} // namespace
44
45void RecordFlashSizeMetric(int width, int height) {
46 PluginFlashTinyContentSize size = TINY_CONTENT_SIZE_LARGE;
47
48 if (width <= 1 && height <= 1)
49 size = TINY_CONTENT_SIZE_1_1;
50 else if (width <= 5 && height <= 5)
51 size = TINY_CONTENT_SIZE_5_5;
52 else if (width <= 10 && height <= 10)
53 size = TINY_CONTENT_SIZE_10_10;
54
55 UMA_HISTOGRAM_ENUMERATION(kFlashTinyContentSizeHistogram, size,
56 TINY_CONTENT_SIZE_NUM_ITEMS);
57}
58
59void RecordFlashClickSizeMetric(int width, int height) {
60 base::HistogramBase* width_histogram = base::LinearHistogram::FactoryGet(
61 kFlashClickSizeWidthHistogram,
62 0, // minimum width
63 500, // maximum width
64 100, // number of buckets.
65 base::HistogramBase::kUmaTargetedHistogramFlag);
66 width_histogram->Add(width);
67
68 base::HistogramBase* height_histogram = base::LinearHistogram::FactoryGet(
69 kFlashClickSizeHeightHistogram,
70 0, // minimum height
71 400, // maximum height
72 100, // number of buckets.
73 base::HistogramBase::kUmaTargetedHistogramFlag);
74 height_histogram->Add(height);
75
76 UMA_HISTOGRAM_ASPECT_RATIO(kFlashClickSizeAspectRatioHistogram, width,
77 height);
78}
79
80void SetGPUHistogram(const ppapi::Preferences& prefs,
81 const std::vector<std::string>& arg_names,
82 const std::vector<std::string>& arg_values) {
83// Calculate a histogram to let us determine how likely people are to try to
84// run Stage3D content on machines that have it blacklisted.
85#if defined(OS_WIN)
86 bool needs_gpu = false;
87 bool is_xp = base::win::GetVersion() <= base::win::VERSION_XP;
88
89 for (size_t i = 0; i < arg_names.size(); i++) {
90 if (arg_names[i] == "wmode") {
91 // In theory content other than Flash could have a "wmode" argument,
92 // but that's pretty unlikely.
93 if (arg_values[i] == "direct" || arg_values[i] == "gpu")
94 needs_gpu = true;
95 break;
96 }
97 }
98 // 0 : No 3D content and GPU is blacklisted
99 // 1 : No 3D content and GPU is not blacklisted
100 // 2 : 3D content but GPU is blacklisted
101 // 3 : 3D content and GPU is not blacklisted
102 // 4 : No 3D content and GPU is blacklisted on XP
103 // 5 : No 3D content and GPU is not blacklisted on XP
104 // 6 : 3D content but GPU is blacklisted on XP
105 // 7 : 3D content and GPU is not blacklisted on XP
106 UMA_HISTOGRAM_ENUMERATION(
107 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8);
108#endif
109}
110
111} // namespace content