| 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 #include "chrome/renderer/plugins/plugin_uma.h" | 5 #include "chrome/renderer/plugins/plugin_uma.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // String we will use to convert mime tyoe to plugin type. | 15 // String we will use to convert mime type to plugin type. |
| 16 const char kWindowsMediaPlayerType[] = "application/x-mplayer2"; | 16 const char kWindowsMediaPlayerType[] = "application/x-mplayer2"; |
| 17 const char kSilverlightTypePrefix[] = "application/x-silverlight"; | 17 const char kSilverlightTypePrefix[] = "application/x-silverlight"; |
| 18 const char kRealPlayerTypePrefix[] = "audio/x-pn-realaudio"; | 18 const char kRealPlayerTypePrefix[] = "audio/x-pn-realaudio"; |
| 19 const char kJavaTypeSubstring[] = "application/x-java-applet"; | 19 const char kJavaTypeSubstring[] = "application/x-java-applet"; |
| 20 const char kQuickTimeType[] = "video/quicktime"; | 20 const char kQuickTimeType[] = "video/quicktime"; |
| 21 | 21 |
| 22 // Arrays containing file extensions connected with specific plugins. | 22 // Arrays containing file extensions connected with specific plugins. |
| 23 // The arrays must be sorted because binary search is used on them. | 23 // The arrays must be sorted because binary search is used on them. |
| 24 const char* kWindowsMediaPlayerExtensions[] = { | 24 const char* kWindowsMediaPlayerExtensions[] = { |
| 25 ".asx" | 25 ".asx" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 ".moov", | 38 ".moov", |
| 39 ".mov", | 39 ".mov", |
| 40 ".qif", | 40 ".qif", |
| 41 ".qt", | 41 ".qt", |
| 42 ".qti", | 42 ".qti", |
| 43 ".qtif" | 43 ".qtif" |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 } // namespace. | 46 } // namespace. |
| 47 | 47 |
| 48 class UMASenderImpl : public MissingPluginReporter::UMASender { | 48 class UMASenderImpl : public PluginUMAReporter::UMASender { |
| 49 virtual void SendPluginUMA(MissingPluginReporter::PluginType plugin_type) | 49 virtual void SendPluginUMA( |
| 50 OVERRIDE; | 50 PluginUMAReporter::ReportType report_type, |
| 51 PluginUMAReporter::PluginType plugin_type) OVERRIDE; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 void UMASenderImpl::SendPluginUMA( | 54 void UMASenderImpl::SendPluginUMA(PluginUMAReporter::ReportType report_type, |
| 54 MissingPluginReporter::PluginType plugin_type) { | 55 PluginUMAReporter::PluginType plugin_type) { |
| 55 UMA_HISTOGRAM_ENUMERATION("Plugin.MissingPlugins", | 56 // UMA_HISTOGRAM_ENUMERATION requires constant histogram name. Use string |
| 56 plugin_type, | 57 // constants explicitly instead of trying to use variables for names. |
| 57 MissingPluginReporter::OTHER); | 58 switch (report_type) { |
| 59 case PluginUMAReporter::MISSING_PLUGIN: |
| 60 UMA_HISTOGRAM_ENUMERATION("Plugin.MissingPlugins", |
| 61 plugin_type, |
| 62 PluginUMAReporter::OTHER); |
| 63 break; |
| 64 case PluginUMAReporter::DISABLED_PLUGIN: |
| 65 UMA_HISTOGRAM_ENUMERATION("Plugin.DisabledPlugins", |
| 66 plugin_type, |
| 67 PluginUMAReporter::OTHER); |
| 68 break; |
| 69 default: |
| 70 NOTREACHED(); |
| 71 } |
| 58 } | 72 } |
| 59 | 73 |
| 60 // static. | 74 // static. |
| 61 MissingPluginReporter* MissingPluginReporter::GetInstance() { | 75 PluginUMAReporter* PluginUMAReporter::GetInstance() { |
| 62 return Singleton<MissingPluginReporter>::get(); | 76 return Singleton<PluginUMAReporter>::get(); |
| 63 } | 77 } |
| 64 | 78 |
| 65 void MissingPluginReporter::ReportPluginMissing( | 79 void PluginUMAReporter::ReportPluginMissing( |
| 66 std::string plugin_mime_type, const GURL& plugin_src) { | 80 const std::string& plugin_mime_type, const GURL& plugin_src) { |
| 67 PluginType plugin_type; | 81 report_sender_->SendPluginUMA(MISSING_PLUGIN, |
| 68 // If we know plugin's mime type, we use it to determine plugin's type. Else, | 82 GetPluginType(plugin_mime_type, plugin_src)); |
| 69 // we try to determine plugin type using plugin source's extension. | |
| 70 if (!plugin_mime_type.empty()) { | |
| 71 StringToLowerASCII(&plugin_mime_type); | |
| 72 plugin_type = MimeTypeToPluginType(plugin_mime_type); | |
| 73 } else { | |
| 74 plugin_type = SrcToPluginType(plugin_src); | |
| 75 } | |
| 76 report_sender_->SendPluginUMA(plugin_type); | |
| 77 } | 83 } |
| 78 | 84 |
| 79 void MissingPluginReporter::SetUMASender(UMASender* sender) { | 85 void PluginUMAReporter::ReportPluginDisabled( |
| 86 const std::string& plugin_mime_type, const GURL& plugin_src) { |
| 87 report_sender_->SendPluginUMA(DISABLED_PLUGIN, |
| 88 GetPluginType(plugin_mime_type, plugin_src)); |
| 89 } |
| 90 |
| 91 void PluginUMAReporter::SetUMASender(UMASender* sender) { |
| 80 report_sender_.reset(sender); | 92 report_sender_.reset(sender); |
| 81 } | 93 } |
| 82 | 94 |
| 83 MissingPluginReporter::MissingPluginReporter() | 95 PluginUMAReporter::PluginUMAReporter() : report_sender_(new UMASenderImpl()) { |
| 84 : report_sender_(new UMASenderImpl()) { | |
| 85 } | 96 } |
| 86 | 97 |
| 87 MissingPluginReporter::~MissingPluginReporter() { | 98 PluginUMAReporter::~PluginUMAReporter() { |
| 88 } | 99 } |
| 89 | 100 |
| 90 // static. | 101 // static. |
| 91 bool MissingPluginReporter::CompareCStrings(const char* first, | 102 bool PluginUMAReporter::CompareCStrings(const char* first, const char* second) { |
| 92 const char* second) { | |
| 93 return strcmp(first, second) < 0; | 103 return strcmp(first, second) < 0; |
| 94 } | 104 } |
| 95 | 105 |
| 96 bool MissingPluginReporter::CStringArrayContainsCString(const char** array, | 106 bool PluginUMAReporter::CStringArrayContainsCString(const char** array, |
| 97 size_t array_size, | 107 size_t array_size, |
| 98 const char* str) { | 108 const char* str) { |
| 99 return std::binary_search(array, array + array_size, str, CompareCStrings); | 109 return std::binary_search(array, array + array_size, str, CompareCStrings); |
| 100 } | 110 } |
| 101 | 111 |
| 102 void MissingPluginReporter::ExtractFileExtension(const GURL& src, | 112 void PluginUMAReporter::ExtractFileExtension(const GURL& src, |
| 103 std::string* extension) { | 113 std::string* extension) { |
| 104 std::string extension_file_path(src.ExtractFileName()); | 114 std::string extension_file_path(src.ExtractFileName()); |
| 105 if (extension_file_path.empty()) | 115 if (extension_file_path.empty()) |
| 106 extension_file_path = src.host(); | 116 extension_file_path = src.host(); |
| 107 | 117 |
| 108 size_t last_dot = extension_file_path.find_last_of('.'); | 118 size_t last_dot = extension_file_path.find_last_of('.'); |
| 109 if (last_dot != std::string::npos) { | 119 if (last_dot != std::string::npos) { |
| 110 *extension = extension_file_path.substr(last_dot); | 120 *extension = extension_file_path.substr(last_dot); |
| 111 } else { | 121 } else { |
| 112 extension->clear(); | 122 extension->clear(); |
| 113 } | 123 } |
| 114 | 124 |
| 115 StringToLowerASCII(extension); | 125 StringToLowerASCII(extension); |
| 116 } | 126 } |
| 117 | 127 |
| 118 MissingPluginReporter::PluginType MissingPluginReporter::SrcToPluginType( | 128 PluginUMAReporter::PluginType PluginUMAReporter::GetPluginType( |
| 129 const std::string& plugin_mime_type, const GURL& plugin_src) { |
| 130 // If we know plugin's mime type, we use it to determine plugin's type. Else, |
| 131 // we try to determine plugin type using plugin source's extension. |
| 132 if (!plugin_mime_type.empty()) |
| 133 return MimeTypeToPluginType(StringToLowerASCII(plugin_mime_type)); |
| 134 |
| 135 return SrcToPluginType(plugin_src); |
| 136 } |
| 137 |
| 138 PluginUMAReporter::PluginType PluginUMAReporter::SrcToPluginType( |
| 119 const GURL& src) { | 139 const GURL& src) { |
| 120 std::string file_extension; | 140 std::string file_extension; |
| 121 ExtractFileExtension(src, &file_extension); | 141 ExtractFileExtension(src, &file_extension); |
| 122 if (CStringArrayContainsCString(kWindowsMediaPlayerExtensions, | 142 if (CStringArrayContainsCString(kWindowsMediaPlayerExtensions, |
| 123 arraysize(kWindowsMediaPlayerExtensions), | 143 arraysize(kWindowsMediaPlayerExtensions), |
| 124 file_extension.c_str())) { | 144 file_extension.c_str())) { |
| 125 return WINDOWS_MEDIA_PLAYER; | 145 return WINDOWS_MEDIA_PLAYER; |
| 126 } | 146 } |
| 127 | 147 |
| 128 if (CStringArrayContainsCString(kQuickTimeExtensions, | 148 if (CStringArrayContainsCString(kQuickTimeExtensions, |
| 129 arraysize(kQuickTimeExtensions), | 149 arraysize(kQuickTimeExtensions), |
| 130 file_extension.c_str())) { | 150 file_extension.c_str())) { |
| 131 return QUICKTIME; | 151 return QUICKTIME; |
| 132 } | 152 } |
| 133 | 153 |
| 134 if (CStringArrayContainsCString(kRealPlayerExtensions, | 154 if (CStringArrayContainsCString(kRealPlayerExtensions, |
| 135 arraysize(kRealPlayerExtensions), | 155 arraysize(kRealPlayerExtensions), |
| 136 file_extension.c_str())) { | 156 file_extension.c_str())) { |
| 137 return REALPLAYER; | 157 return REALPLAYER; |
| 138 } | 158 } |
| 139 | 159 |
| 140 return OTHER; | 160 return OTHER; |
| 141 } | 161 } |
| 142 | 162 |
| 143 MissingPluginReporter::PluginType MissingPluginReporter::MimeTypeToPluginType( | 163 PluginUMAReporter::PluginType PluginUMAReporter::MimeTypeToPluginType( |
| 144 const std::string& mime_type) { | 164 const std::string& mime_type) { |
| 145 if (strcmp(mime_type.c_str(), kWindowsMediaPlayerType) == 0) | 165 if (strcmp(mime_type.c_str(), kWindowsMediaPlayerType) == 0) |
| 146 return WINDOWS_MEDIA_PLAYER; | 166 return WINDOWS_MEDIA_PLAYER; |
| 147 | 167 |
| 148 size_t prefix_length = strlen(kSilverlightTypePrefix); | 168 size_t prefix_length = strlen(kSilverlightTypePrefix); |
| 149 if (strncmp(mime_type.c_str(), kSilverlightTypePrefix, prefix_length) == 0) | 169 if (strncmp(mime_type.c_str(), kSilverlightTypePrefix, prefix_length) == 0) |
| 150 return SILVERLIGHT; | 170 return SILVERLIGHT; |
| 151 | 171 |
| 152 prefix_length = strlen(kRealPlayerTypePrefix); | 172 prefix_length = strlen(kRealPlayerTypePrefix); |
| 153 if (strncmp(mime_type.c_str(), kRealPlayerTypePrefix, prefix_length) == 0) | 173 if (strncmp(mime_type.c_str(), kRealPlayerTypePrefix, prefix_length) == 0) |
| 154 return REALPLAYER; | 174 return REALPLAYER; |
| 155 | 175 |
| 156 if (strstr(mime_type.c_str(), kJavaTypeSubstring)) | 176 if (strstr(mime_type.c_str(), kJavaTypeSubstring)) |
| 157 return JAVA; | 177 return JAVA; |
| 158 | 178 |
| 159 if (strcmp(mime_type.c_str(), kQuickTimeType) == 0) | 179 if (strcmp(mime_type.c_str(), kQuickTimeType) == 0) |
| 160 return QUICKTIME; | 180 return QUICKTIME; |
| 161 | 181 |
| 162 return OTHER; | 182 return OTHER; |
| 163 } | 183 } |
| 164 | |
| OLD | NEW |