Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ | 5 #ifndef CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ |
| 6 #define CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ | 6 #define CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 // Used to send UMA data about missing plugins to UMA histogram server. Method | 17 // Used to send UMA data about missing plugins to UMA histogram server. Method |
| 18 // ReportPluginMissing should be called whenever plugin that is not available or | 18 // ReportPluginMissing should be called whenever plugin that is not available or |
| 19 // enabled is called. We try to determine plugin's type by requested mime type, | 19 // enabled is called. We try to determine plugin's type by requested mime type, |
| 20 // or, if mime type is unknown, by plugin's src url. | 20 // or, if mime type is unknown, by plugin's src url. |
| 21 class PluginUMAReporter { | 21 class PluginUMAReporter { |
| 22 public: | 22 public: |
| 23 enum ReportType { | 23 enum ReportType { |
| 24 MISSING_PLUGIN, | 24 MISSING_PLUGIN, |
| 25 DISABLED_PLUGIN | 25 DISABLED_PLUGIN, |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 // Make sure the enum list in tools/histogram/histograms.xml is updated with | 28 // Make sure the enum list in tools/histogram/histograms.xml is updated with |
| 29 // any change in this list. | 29 // any change in this list. |
| 30 enum PluginType { | 30 enum PluginType { |
| 31 WINDOWS_MEDIA_PLAYER = 0, | 31 WINDOWS_MEDIA_PLAYER = 0, |
| 32 SILVERLIGHT = 1, | 32 SILVERLIGHT = 1, |
| 33 REALPLAYER = 2, | 33 REALPLAYER = 2, |
| 34 JAVA = 3, | 34 JAVA = 3, |
| 35 QUICKTIME = 4, | 35 QUICKTIME = 4, |
| 36 OTHER = 5, // This is obsolete and replaced by UNSUPPORTED_* types. | 36 OTHER = 5, // This is obsolete and replaced by UNSUPPORTED_* types. |
| 37 UNSUPPORTED_MIMETYPE, | 37 UNSUPPORTED_MIMETYPE, |
| 38 UNSUPPORTED_EXTENSION, | 38 UNSUPPORTED_EXTENSION, |
| 39 // NOTE: Add new unsupported types only immediately above this line. | 39 // NOTE: Add new unsupported types only immediately above this line. |
| 40 BROWSER_PLUGIN = 10, | 40 BROWSER_PLUGIN = 10, |
| 41 SHOCKWAVE_FLASH, | 41 SHOCKWAVE_FLASH, |
| 42 WIDEVINE_CDM, | 42 WIDEVINE_CDM, |
| 43 // NOTE: Add new plugin types only immediately above this line. | 43 // NOTE: Add new plugin types only immediately above this line. |
| 44 PLUGIN_TYPE_MAX | 44 PLUGIN_TYPE_MAX |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Must be kept in sync with PDFLoadStatus enum in histograms.xml. | |
| 48 enum PDFLoadStatus { | |
| 49 LOADED_FULL_PAGE_PDF_WITH_PDFIUM = 0, | |
| 50 LOADED_EMBEDDED_PDF_WITH_PDFIUM = 1, | |
| 51 SHOWED_DISABLED_PLUGIN_PLACEHOLDER_FOR_EMBEDDED_PDF = 2, | |
| 52 PDF_LOAD_STATUS_MAX | |
| 53 }; | |
| 54 | |
| 47 // Sends UMA data, i.e. plugin's type. | 55 // Sends UMA data, i.e. plugin's type. |
| 48 class UMASender { | 56 class UMASender { |
| 49 public: | 57 public: |
| 50 virtual ~UMASender() {} | 58 virtual ~UMASender() {} |
| 51 virtual void SendPluginUMA(ReportType report_type, | 59 virtual void SendPluginUMA(ReportType report_type, |
| 52 PluginType plugin_type) = 0; | 60 PluginType plugin_type) = 0; |
| 53 }; | 61 }; |
| 54 | 62 |
| 55 // Returns singleton instance. | 63 // Returns singleton instance. |
| 56 static PluginUMAReporter* GetInstance(); | 64 static PluginUMAReporter* GetInstance(); |
| 57 | 65 |
| 58 void ReportPluginMissing(const std::string& plugin_mime_type, | 66 void ReportPluginMissing(const std::string& plugin_mime_type, |
| 59 const GURL& plugin_src); | 67 const GURL& plugin_src); |
| 60 | 68 |
| 61 void ReportPluginDisabled(const std::string& plugin_mime_type, | 69 void ReportPluginDisabled(const std::string& plugin_mime_type, |
| 62 const GURL& plugin_src); | 70 const GURL& plugin_src); |
| 63 | 71 |
| 72 static void ReportPDFLoadStatus(PDFLoadStatus status); | |
|
Lei Zhang
2017/05/03 23:50:34
Keep the static methods together.
tommycli
2017/05/04 00:08:31
Done.
| |
| 73 | |
| 64 private: | 74 private: |
| 65 friend struct base::DefaultSingletonTraits<PluginUMAReporter>; | 75 friend struct base::DefaultSingletonTraits<PluginUMAReporter>; |
| 66 friend class PluginUMATest; | 76 friend class PluginUMATest; |
| 67 | 77 |
| 68 PluginUMAReporter(); | 78 PluginUMAReporter(); |
| 69 ~PluginUMAReporter(); | 79 ~PluginUMAReporter(); |
| 70 | 80 |
| 71 static bool CompareCStrings(const char* first, const char* second); | 81 static bool CompareCStrings(const char* first, const char* second); |
| 72 bool CStringArrayContainsCString(const char* const* array, | 82 bool CStringArrayContainsCString(const char* const* array, |
| 73 size_t array_size, | 83 size_t array_size, |
| 74 const char* str); | 84 const char* str); |
| 75 // Extracts file extension from url. | 85 // Extracts file extension from url. |
| 76 void ExtractFileExtension(const GURL& src, std::string* extension); | 86 void ExtractFileExtension(const GURL& src, std::string* extension); |
| 77 | 87 |
| 78 PluginType GetPluginType(const std::string& plugin_mime_type, | 88 PluginType GetPluginType(const std::string& plugin_mime_type, |
| 79 const GURL& plugin_src); | 89 const GURL& plugin_src); |
| 80 | 90 |
| 81 // Converts plugin's src to plugin type. | 91 // Converts plugin's src to plugin type. |
| 82 PluginType SrcToPluginType(const GURL& src); | 92 PluginType SrcToPluginType(const GURL& src); |
| 83 // Converts plugin's mime type to plugin type. | 93 // Converts plugin's mime type to plugin type. |
| 84 PluginType MimeTypeToPluginType(const std::string& mime_type); | 94 PluginType MimeTypeToPluginType(const std::string& mime_type); |
| 85 | 95 |
| 86 std::unique_ptr<UMASender> report_sender_; | 96 std::unique_ptr<UMASender> report_sender_; |
| 87 | 97 |
| 88 DISALLOW_COPY_AND_ASSIGN(PluginUMAReporter); | 98 DISALLOW_COPY_AND_ASSIGN(PluginUMAReporter); |
| 89 }; | 99 }; |
| 90 | 100 |
| 91 #endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ | 101 #endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ |
| OLD | NEW |