OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
ddorwin
2013/04/04 19:09:50
same
xhwang
2013/04/04 23:10:33
Done.
| |
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( |
80 report_sender_.reset(sender); | 86 const std::string& plugin_mime_type, const GURL& plugin_src) { |
87 report_sender_->SendPluginUMA(DISABLED_PLUGIN, | |
88 GetPluginType(plugin_mime_type, plugin_src)); | |
81 } | 89 } |
82 | 90 |
83 MissingPluginReporter::MissingPluginReporter() | 91 PluginUMAReporter::PluginUMAReporter() : report_sender_(new UMASenderImpl()) { |
84 : report_sender_(new UMASenderImpl()) { | |
85 } | 92 } |
86 | 93 |
87 MissingPluginReporter::~MissingPluginReporter() { | 94 PluginUMAReporter::~PluginUMAReporter() { |
88 } | 95 } |
89 | 96 |
90 // static. | 97 // static. |
91 bool MissingPluginReporter::CompareCStrings(const char* first, | 98 bool PluginUMAReporter::CompareCStrings(const char* first, const char* second) { |
92 const char* second) { | |
93 return strcmp(first, second) < 0; | 99 return strcmp(first, second) < 0; |
94 } | 100 } |
95 | 101 |
96 bool MissingPluginReporter::CStringArrayContainsCString(const char** array, | 102 bool PluginUMAReporter::CStringArrayContainsCString(const char** array, |
97 size_t array_size, | 103 size_t array_size, |
98 const char* str) { | 104 const char* str) { |
99 return std::binary_search(array, array + array_size, str, CompareCStrings); | 105 return std::binary_search(array, array + array_size, str, CompareCStrings); |
100 } | 106 } |
101 | 107 |
102 void MissingPluginReporter::ExtractFileExtension(const GURL& src, | 108 void PluginUMAReporter::ExtractFileExtension(const GURL& src, |
103 std::string* extension) { | 109 std::string* extension) { |
104 std::string extension_file_path(src.ExtractFileName()); | 110 std::string extension_file_path(src.ExtractFileName()); |
105 if (extension_file_path.empty()) | 111 if (extension_file_path.empty()) |
106 extension_file_path = src.host(); | 112 extension_file_path = src.host(); |
107 | 113 |
108 size_t last_dot = extension_file_path.find_last_of('.'); | 114 size_t last_dot = extension_file_path.find_last_of('.'); |
109 if (last_dot != std::string::npos) { | 115 if (last_dot != std::string::npos) { |
110 *extension = extension_file_path.substr(last_dot); | 116 *extension = extension_file_path.substr(last_dot); |
111 } else { | 117 } else { |
112 extension->clear(); | 118 extension->clear(); |
113 } | 119 } |
114 | 120 |
115 StringToLowerASCII(extension); | 121 StringToLowerASCII(extension); |
116 } | 122 } |
117 | 123 |
118 MissingPluginReporter::PluginType MissingPluginReporter::SrcToPluginType( | 124 PluginUMAReporter::PluginType PluginUMAReporter::GetPluginType( |
125 const std::string& plugin_mime_type, const GURL& plugin_src) { | |
126 // If we know plugin's mime type, we use it to determine plugin's type. Else, | |
127 // we try to determine plugin type using plugin source's extension. | |
128 if (!plugin_mime_type.empty()) | |
129 return MimeTypeToPluginType(StringToLowerASCII(plugin_mime_type)); | |
130 | |
131 return SrcToPluginType(plugin_src); | |
132 } | |
133 | |
134 PluginUMAReporter::PluginType PluginUMAReporter::SrcToPluginType( | |
119 const GURL& src) { | 135 const GURL& src) { |
120 std::string file_extension; | 136 std::string file_extension; |
121 ExtractFileExtension(src, &file_extension); | 137 ExtractFileExtension(src, &file_extension); |
122 if (CStringArrayContainsCString(kWindowsMediaPlayerExtensions, | 138 if (CStringArrayContainsCString(kWindowsMediaPlayerExtensions, |
123 arraysize(kWindowsMediaPlayerExtensions), | 139 arraysize(kWindowsMediaPlayerExtensions), |
124 file_extension.c_str())) { | 140 file_extension.c_str())) { |
125 return WINDOWS_MEDIA_PLAYER; | 141 return WINDOWS_MEDIA_PLAYER; |
126 } | 142 } |
127 | 143 |
128 if (CStringArrayContainsCString(kQuickTimeExtensions, | 144 if (CStringArrayContainsCString(kQuickTimeExtensions, |
129 arraysize(kQuickTimeExtensions), | 145 arraysize(kQuickTimeExtensions), |
130 file_extension.c_str())) { | 146 file_extension.c_str())) { |
131 return QUICKTIME; | 147 return QUICKTIME; |
132 } | 148 } |
133 | 149 |
134 if (CStringArrayContainsCString(kRealPlayerExtensions, | 150 if (CStringArrayContainsCString(kRealPlayerExtensions, |
135 arraysize(kRealPlayerExtensions), | 151 arraysize(kRealPlayerExtensions), |
136 file_extension.c_str())) { | 152 file_extension.c_str())) { |
137 return REALPLAYER; | 153 return REALPLAYER; |
138 } | 154 } |
139 | 155 |
140 return OTHER; | 156 return OTHER; |
141 } | 157 } |
142 | 158 |
143 MissingPluginReporter::PluginType MissingPluginReporter::MimeTypeToPluginType( | 159 PluginUMAReporter::PluginType PluginUMAReporter::MimeTypeToPluginType( |
144 const std::string& mime_type) { | 160 const std::string& mime_type) { |
145 if (strcmp(mime_type.c_str(), kWindowsMediaPlayerType) == 0) | 161 if (strcmp(mime_type.c_str(), kWindowsMediaPlayerType) == 0) |
146 return WINDOWS_MEDIA_PLAYER; | 162 return WINDOWS_MEDIA_PLAYER; |
147 | 163 |
148 size_t prefix_length = strlen(kSilverlightTypePrefix); | 164 size_t prefix_length = strlen(kSilverlightTypePrefix); |
149 if (strncmp(mime_type.c_str(), kSilverlightTypePrefix, prefix_length) == 0) | 165 if (strncmp(mime_type.c_str(), kSilverlightTypePrefix, prefix_length) == 0) |
150 return SILVERLIGHT; | 166 return SILVERLIGHT; |
151 | 167 |
152 prefix_length = strlen(kRealPlayerTypePrefix); | 168 prefix_length = strlen(kRealPlayerTypePrefix); |
153 if (strncmp(mime_type.c_str(), kRealPlayerTypePrefix, prefix_length) == 0) | 169 if (strncmp(mime_type.c_str(), kRealPlayerTypePrefix, prefix_length) == 0) |
154 return REALPLAYER; | 170 return REALPLAYER; |
155 | 171 |
156 if (strstr(mime_type.c_str(), kJavaTypeSubstring)) | 172 if (strstr(mime_type.c_str(), kJavaTypeSubstring)) |
157 return JAVA; | 173 return JAVA; |
158 | 174 |
159 if (strcmp(mime_type.c_str(), kQuickTimeType) == 0) | 175 if (strcmp(mime_type.c_str(), kQuickTimeType) == 0) |
160 return QUICKTIME; | 176 return QUICKTIME; |
161 | 177 |
162 return OTHER; | 178 return OTHER; |
163 } | 179 } |
164 | |
OLD | NEW |