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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 | 13 |
14 // Used to send UMA data about missing plugins to UMA histogram server. Method | 14 // Used to send UMA data about missing plugins to UMA histogram server. Method |
15 // ReportPluginMissing should be called whenever plugin that is not available or | 15 // ReportPluginMissing should be called whenever plugin that is not available or |
16 // enabled is called. We try to determine plugin's type by requested mime type, | 16 // enabled is called. We try to determine plugin's type by requested mime type, |
17 // or, if mime type is unknown, by plugin's src url. | 17 // or, if mime type is unknown, by plugin's src url. |
18 class MissingPluginReporter { | 18 class PluginUMAReporter { |
19 public: | 19 public: |
| 20 enum ReportType { |
| 21 MISSING_PLUGIN, |
| 22 DISABLED_PLUGIN |
| 23 }; |
| 24 |
20 // This must be sync'd with histogram values. | 25 // This must be sync'd with histogram values. |
21 enum PluginType { | 26 enum PluginType { |
22 WINDOWS_MEDIA_PLAYER = 0, | 27 WINDOWS_MEDIA_PLAYER = 0, |
23 SILVERLIGHT = 1, | 28 SILVERLIGHT = 1, |
24 REALPLAYER = 2, | 29 REALPLAYER = 2, |
25 JAVA = 3, | 30 JAVA = 3, |
26 QUICKTIME = 4, | 31 QUICKTIME = 4, |
27 OTHER = 5 | 32 OTHER = 5 |
28 }; | 33 }; |
29 | 34 |
30 // Sends UMA data, i.e. plugin's type. | 35 // Sends UMA data, i.e. plugin's type. |
31 class UMASender { | 36 class UMASender { |
32 public: | 37 public: |
33 virtual ~UMASender() {} | 38 virtual ~UMASender() {} |
34 virtual void SendPluginUMA(PluginType plugin_type) = 0; | 39 virtual void SendPluginUMA(ReportType report_type, |
| 40 PluginType plugin_type) = 0; |
35 }; | 41 }; |
36 | 42 |
37 // Returns singleton instance. | 43 // Returns singleton instance. |
38 static MissingPluginReporter* GetInstance(); | 44 static PluginUMAReporter* GetInstance(); |
39 | 45 |
40 void ReportPluginMissing(std::string plugin_mime_type, | 46 void ReportPluginMissing(const std::string& plugin_mime_type, |
41 const GURL& plugin_src); | 47 const GURL& plugin_src); |
42 | 48 |
43 // Used in testing. | 49 void ReportPluginDisabled(const std::string& plugin_mime_type, |
44 void SetUMASender(UMASender* sender); | 50 const GURL& plugin_src); |
45 | 51 |
46 private: | 52 private: |
47 friend struct DefaultSingletonTraits<MissingPluginReporter>; | 53 friend struct DefaultSingletonTraits<PluginUMAReporter>; |
| 54 friend class PluginUMATest; |
48 | 55 |
49 MissingPluginReporter(); | 56 PluginUMAReporter(); |
50 ~MissingPluginReporter(); | 57 ~PluginUMAReporter(); |
51 | 58 |
52 static bool CompareCStrings(const char* first, const char* second); | 59 static bool CompareCStrings(const char* first, const char* second); |
53 bool CStringArrayContainsCString(const char** array, | 60 bool CStringArrayContainsCString(const char** array, |
54 size_t array_size, | 61 size_t array_size, |
55 const char* str); | 62 const char* str); |
56 // Extracts file extension from url. | 63 // Extracts file extension from url. |
57 void ExtractFileExtension(const GURL& src, std::string* extension); | 64 void ExtractFileExtension(const GURL& src, std::string* extension); |
58 | 65 |
| 66 PluginType GetPluginType(const std::string& plugin_mime_type, |
| 67 const GURL& plugin_src); |
| 68 |
59 // Converts plugin's src to plugin type. | 69 // Converts plugin's src to plugin type. |
60 PluginType SrcToPluginType(const GURL& src); | 70 PluginType SrcToPluginType(const GURL& src); |
61 // Converts plugin's mime type to plugin type. | 71 // Converts plugin's mime type to plugin type. |
62 PluginType MimeTypeToPluginType(const std::string& mime_type); | 72 PluginType MimeTypeToPluginType(const std::string& mime_type); |
63 | 73 |
64 scoped_ptr<UMASender> report_sender_; | 74 scoped_ptr<UMASender> report_sender_; |
65 | 75 |
66 DISALLOW_COPY_AND_ASSIGN(MissingPluginReporter); | 76 DISALLOW_COPY_AND_ASSIGN(PluginUMAReporter); |
67 }; | 77 }; |
68 | 78 |
69 #endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ | 79 #endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ |
70 | 80 |
OLD | NEW |