Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/renderer/plugins/plugin_uma.cc

Issue 27197004: Move renderer plugin code into a new component (re-land) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move renderer plugin code into a new component (re-land) - fix nit and rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/plugins/plugin_uma.h ('k') | chrome/renderer/plugins/plugin_uma_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "content/public/common/content_constants.h" 12 #include "content/public/common/content_constants.h"
13 #include "third_party/widevine/cdm/widevine_cdm_common.h" 13 #include "third_party/widevine/cdm/widevine_cdm_common.h"
14 14
15 namespace { 15 namespace {
16 16
17 // String we will use to convert mime type to plugin type. 17 // String we will use to convert mime type to plugin type.
18 const char kWindowsMediaPlayerType[] = "application/x-mplayer2"; 18 const char kWindowsMediaPlayerType[] = "application/x-mplayer2";
19 const char kSilverlightTypePrefix[] = "application/x-silverlight"; 19 const char kSilverlightTypePrefix[] = "application/x-silverlight";
20 const char kRealPlayerTypePrefix[] = "audio/x-pn-realaudio"; 20 const char kRealPlayerTypePrefix[] = "audio/x-pn-realaudio";
21 const char kJavaTypeSubstring[] = "application/x-java-applet"; 21 const char kJavaTypeSubstring[] = "application/x-java-applet";
22 const char kQuickTimeType[] = "video/quicktime"; 22 const char kQuickTimeType[] = "video/quicktime";
23 23
24 // Arrays containing file extensions connected with specific plugins. 24 // Arrays containing file extensions connected with specific plugins.
25 // Note: THE ARRAYS MUST BE SORTED BECAUSE BINARY SEARCH IS USED ON THEM! 25 // Note: THE ARRAYS MUST BE SORTED BECAUSE BINARY SEARCH IS USED ON THEM!
26 const char* kWindowsMediaPlayerExtensions[] = { 26 const char* kWindowsMediaPlayerExtensions[] = {".asx"};
27 ".asx"
28 };
29 27
30 const char* kRealPlayerExtensions[] = { 28 const char* kRealPlayerExtensions[] = {".ra", ".ram", ".rm",
31 ".ra", 29 ".rmm", ".rmp", ".rpm"};
32 ".ram",
33 ".rm",
34 ".rmm",
35 ".rmp",
36 ".rpm"
37 };
38 30
39 const char* kQuickTimeExtensions[] = { 31 const char* kQuickTimeExtensions[] = {".moov", ".mov", ".qif",
40 ".moov", 32 ".qt", ".qti", ".qtif"};
41 ".mov",
42 ".qif",
43 ".qt",
44 ".qti",
45 ".qtif"
46 };
47 33
48 const char* kShockwaveFlashExtensions[] = { 34 const char* kShockwaveFlashExtensions[] = {".spl", ".swf"};
49 ".spl",
50 ".swf"
51 };
52 35
53 } // namespace. 36 } // namespace.
54 37
55 class UMASenderImpl : public PluginUMAReporter::UMASender { 38 class UMASenderImpl : public PluginUMAReporter::UMASender {
56 virtual void SendPluginUMA( 39 virtual void SendPluginUMA(
57 PluginUMAReporter::ReportType report_type, 40 PluginUMAReporter::ReportType report_type,
58 PluginUMAReporter::PluginType plugin_type) OVERRIDE; 41 PluginUMAReporter::PluginType plugin_type) OVERRIDE;
59 }; 42 };
60 43
61 void UMASenderImpl::SendPluginUMA(PluginUMAReporter::ReportType report_type, 44 void UMASenderImpl::SendPluginUMA(PluginUMAReporter::ReportType report_type,
(...skipping 14 matching lines...) Expand all
76 default: 59 default:
77 NOTREACHED(); 60 NOTREACHED();
78 } 61 }
79 } 62 }
80 63
81 // static. 64 // static.
82 PluginUMAReporter* PluginUMAReporter::GetInstance() { 65 PluginUMAReporter* PluginUMAReporter::GetInstance() {
83 return Singleton<PluginUMAReporter>::get(); 66 return Singleton<PluginUMAReporter>::get();
84 } 67 }
85 68
86 void PluginUMAReporter::ReportPluginMissing( 69 void PluginUMAReporter::ReportPluginMissing(const std::string& plugin_mime_type,
87 const std::string& plugin_mime_type, const GURL& plugin_src) { 70 const GURL& plugin_src) {
88 report_sender_->SendPluginUMA(MISSING_PLUGIN, 71 report_sender_->SendPluginUMA(MISSING_PLUGIN,
89 GetPluginType(plugin_mime_type, plugin_src)); 72 GetPluginType(plugin_mime_type, plugin_src));
90 } 73 }
91 74
92 void PluginUMAReporter::ReportPluginDisabled( 75 void PluginUMAReporter::ReportPluginDisabled(
93 const std::string& plugin_mime_type, const GURL& plugin_src) { 76 const std::string& plugin_mime_type,
77 const GURL& plugin_src) {
94 report_sender_->SendPluginUMA(DISABLED_PLUGIN, 78 report_sender_->SendPluginUMA(DISABLED_PLUGIN,
95 GetPluginType(plugin_mime_type, plugin_src)); 79 GetPluginType(plugin_mime_type, plugin_src));
96 } 80 }
97 81
98 PluginUMAReporter::PluginUMAReporter() : report_sender_(new UMASenderImpl()) { 82 PluginUMAReporter::PluginUMAReporter() : report_sender_(new UMASenderImpl()) {}
99 }
100 83
101 PluginUMAReporter::~PluginUMAReporter() { 84 PluginUMAReporter::~PluginUMAReporter() {}
102 }
103 85
104 // static. 86 // static.
105 bool PluginUMAReporter::CompareCStrings(const char* first, const char* second) { 87 bool PluginUMAReporter::CompareCStrings(const char* first, const char* second) {
106 return strcmp(first, second) < 0; 88 return strcmp(first, second) < 0;
107 } 89 }
108 90
109 bool PluginUMAReporter::CStringArrayContainsCString(const char** array, 91 bool PluginUMAReporter::CStringArrayContainsCString(const char** array,
110 size_t array_size, 92 size_t array_size,
111 const char* str) { 93 const char* str) {
112 return std::binary_search(array, array + array_size, str, CompareCStrings); 94 return std::binary_search(array, array + array_size, str, CompareCStrings);
113 } 95 }
114 96
115 void PluginUMAReporter::ExtractFileExtension(const GURL& src, 97 void PluginUMAReporter::ExtractFileExtension(const GURL& src,
116 std::string* extension) { 98 std::string* extension) {
117 std::string extension_file_path(src.ExtractFileName()); 99 std::string extension_file_path(src.ExtractFileName());
118 if (extension_file_path.empty()) 100 if (extension_file_path.empty())
119 extension_file_path = src.host(); 101 extension_file_path = src.host();
120 102
121 size_t last_dot = extension_file_path.find_last_of('.'); 103 size_t last_dot = extension_file_path.find_last_of('.');
122 if (last_dot != std::string::npos) { 104 if (last_dot != std::string::npos) {
123 *extension = extension_file_path.substr(last_dot); 105 *extension = extension_file_path.substr(last_dot);
124 } else { 106 } else {
125 extension->clear(); 107 extension->clear();
126 } 108 }
127 109
128 StringToLowerASCII(extension); 110 StringToLowerASCII(extension);
129 } 111 }
130 112
131 PluginUMAReporter::PluginType PluginUMAReporter::GetPluginType( 113 PluginUMAReporter::PluginType PluginUMAReporter::GetPluginType(
132 const std::string& plugin_mime_type, const GURL& plugin_src) { 114 const std::string& plugin_mime_type,
115 const GURL& plugin_src) {
133 // If we know plugin's mime type, we use it to determine plugin's type. Else, 116 // If we know plugin's mime type, we use it to determine plugin's type. Else,
134 // we try to determine plugin type using plugin source's extension. 117 // we try to determine plugin type using plugin source's extension.
135 if (!plugin_mime_type.empty()) 118 if (!plugin_mime_type.empty())
136 return MimeTypeToPluginType(StringToLowerASCII(plugin_mime_type)); 119 return MimeTypeToPluginType(StringToLowerASCII(plugin_mime_type));
137 120
138 return SrcToPluginType(plugin_src); 121 return SrcToPluginType(plugin_src);
139 } 122 }
140 123
141 PluginUMAReporter::PluginType PluginUMAReporter::SrcToPluginType( 124 PluginUMAReporter::PluginType PluginUMAReporter::SrcToPluginType(
142 const GURL& src) { 125 const GURL& src) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return SHOCKWAVE_FLASH; 179 return SHOCKWAVE_FLASH;
197 } 180 }
198 181
199 #if defined(ENABLE_PEPPER_CDMS) 182 #if defined(ENABLE_PEPPER_CDMS)
200 if (mime_type == kWidevineCdmPluginMimeType) 183 if (mime_type == kWidevineCdmPluginMimeType)
201 return WIDEVINE_CDM; 184 return WIDEVINE_CDM;
202 #endif 185 #endif
203 186
204 return UNSUPPORTED_MIMETYPE; 187 return UNSUPPORTED_MIMETYPE;
205 } 188 }
OLDNEW
« no previous file with comments | « chrome/renderer/plugins/plugin_uma.h ('k') | chrome/renderer/plugins/plugin_uma_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698