tommycli | e872270 | 2015-01-16 11:40:41 | [diff] [blame] | 1 | // 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 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
tommycli | e872270 | 2015-01-16 11:40:41 | [diff] [blame] | 9 | #include "base/metrics/histogram.h" |
| 10 | #include "base/metrics/sparse_histogram.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 11 | #include "build/build_config.h" |
tommycli | e872270 | 2015-01-16 11:40:41 | [diff] [blame] | 12 | #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 | |
| 22 | namespace content { |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | // Histogram tracking prevalence of tiny Flash instances. Units in pixels. |
| 27 | enum 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 | |
| 35 | const int kInfiniteRatio = 99999; |
| 36 | |
| 37 | const char kFlashClickSizeAspectRatioHistogram[] = |
| 38 | "Plugin.Flash.ClickSize.AspectRatio"; |
| 39 | const char kFlashClickSizeHeightHistogram[] = "Plugin.Flash.ClickSize.Height"; |
| 40 | const char kFlashClickSizeWidthHistogram[] = "Plugin.Flash.ClickSize.Width"; |
| 41 | const char kFlashTinyContentSizeHistogram[] = "Plugin.Flash.TinyContentSize"; |
| 42 | |
| 43 | } // namespace |
| 44 | |
| 45 | void 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 | |
| 59 | void 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 | |
| 80 | void 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 |