Commit ff173642 authored by xhwang@chromium.org's avatar xhwang@chromium.org

Report disabled plugin in CreatePlugin.

Currently we only get stats about missing plugins (including unregistered plugin and missing plugin file). It is also interesting to know how many plugin creation failed because it is disabled. User may forget that he/she disabled a particular plugin and he/she doesn't get an info bar in this case, which could cause confusion.

In this CL:

- Rename MissingPluginReporter to PluginUMAReporter.
- Add ReportPluginDisabled function.
- Call ReportPluginDisabled function if the plugin is disabled in CreatePlugin.
- Refactor PluginUMATest to remove duplicate code.

BUG=226107
TEST=Unittests pass.

Review URL: https://chromiumcodereview.appspot.com/13414007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192652 0039d316-1c4b-4281-b951-d872f2087c98
parent 4905b75c
...@@ -530,8 +530,7 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -530,8 +530,7 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
return PluginPlaceholder::CreateMobileYoutubePlugin(render_view, frame, return PluginPlaceholder::CreateMobileYoutubePlugin(render_view, frame,
original_params)->plugin(); original_params)->plugin();
#endif #endif
MissingPluginReporter::GetInstance()->ReportPluginMissing( PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url);
orig_mime_type, url);
placeholder = PluginPlaceholder::CreateMissingPlugin( placeholder = PluginPlaceholder::CreateMissingPlugin(
render_view, frame, original_params); render_view, frame, original_params);
} else { } else {
...@@ -655,6 +654,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( ...@@ -655,6 +654,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin(
break; break;
} }
case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled: { case ChromeViewHostMsg_GetPluginInfo_Status::kDisabled: {
PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type,
url);
placeholder = PluginPlaceholder::CreateBlockedPlugin( placeholder = PluginPlaceholder::CreateBlockedPlugin(
render_view, frame, params, plugin, identifier, group_name, render_view, frame, params, plugin, identifier, group_name,
IDR_DISABLED_PLUGIN_HTML, IDR_DISABLED_PLUGIN_HTML,
......
...@@ -313,7 +313,7 @@ bool PluginPlaceholder::OnMessageReceived(const IPC::Message& message) { ...@@ -313,7 +313,7 @@ bool PluginPlaceholder::OnMessageReceived(const IPC::Message& message) {
void PluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) { void PluginPlaceholder::ReplacePlugin(WebPlugin* new_plugin) {
CHECK(plugin_); CHECK(plugin_);
if (!new_plugin) { if (!new_plugin) {
MissingPluginReporter::GetInstance()->ReportPluginMissing( PluginUMAReporter::GetInstance()->ReportPluginMissing(
plugin_params_.mimeType.utf8(), plugin_params_.mimeType.utf8(),
plugin_params_.url); plugin_params_.url);
return; return;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace { namespace {
// String we will use to convert mime tyoe to plugin type. // String we will use to convert mime type to plugin type.
const char kWindowsMediaPlayerType[] = "application/x-mplayer2"; const char kWindowsMediaPlayerType[] = "application/x-mplayer2";
const char kSilverlightTypePrefix[] = "application/x-silverlight"; const char kSilverlightTypePrefix[] = "application/x-silverlight";
const char kRealPlayerTypePrefix[] = "audio/x-pn-realaudio"; const char kRealPlayerTypePrefix[] = "audio/x-pn-realaudio";
...@@ -45,61 +45,67 @@ const char* kQuickTimeExtensions[] = { ...@@ -45,61 +45,67 @@ const char* kQuickTimeExtensions[] = {
} // namespace. } // namespace.
class UMASenderImpl : public MissingPluginReporter::UMASender { class UMASenderImpl : public PluginUMAReporter::UMASender {
virtual void SendPluginUMA(MissingPluginReporter::PluginType plugin_type) virtual void SendPluginUMA(
OVERRIDE; PluginUMAReporter::ReportType report_type,
PluginUMAReporter::PluginType plugin_type) OVERRIDE;
}; };
void UMASenderImpl::SendPluginUMA( void UMASenderImpl::SendPluginUMA(PluginUMAReporter::ReportType report_type,
MissingPluginReporter::PluginType plugin_type) { PluginUMAReporter::PluginType plugin_type) {
// UMA_HISTOGRAM_ENUMERATION requires constant histogram name. Use string
// constants explicitly instead of trying to use variables for names.
switch (report_type) {
case PluginUMAReporter::MISSING_PLUGIN:
UMA_HISTOGRAM_ENUMERATION("Plugin.MissingPlugins", UMA_HISTOGRAM_ENUMERATION("Plugin.MissingPlugins",
plugin_type, plugin_type,
MissingPluginReporter::OTHER); PluginUMAReporter::OTHER);
break;
case PluginUMAReporter::DISABLED_PLUGIN:
UMA_HISTOGRAM_ENUMERATION("Plugin.DisabledPlugins",
plugin_type,
PluginUMAReporter::OTHER);
break;
default:
NOTREACHED();
}
} }
// static. // static.
MissingPluginReporter* MissingPluginReporter::GetInstance() { PluginUMAReporter* PluginUMAReporter::GetInstance() {
return Singleton<MissingPluginReporter>::get(); return Singleton<PluginUMAReporter>::get();
} }
void MissingPluginReporter::ReportPluginMissing( void PluginUMAReporter::ReportPluginMissing(
std::string plugin_mime_type, const GURL& plugin_src) { const std::string& plugin_mime_type, const GURL& plugin_src) {
PluginType plugin_type; report_sender_->SendPluginUMA(MISSING_PLUGIN,
// If we know plugin's mime type, we use it to determine plugin's type. Else, GetPluginType(plugin_mime_type, plugin_src));
// we try to determine plugin type using plugin source's extension.
if (!plugin_mime_type.empty()) {
StringToLowerASCII(&plugin_mime_type);
plugin_type = MimeTypeToPluginType(plugin_mime_type);
} else {
plugin_type = SrcToPluginType(plugin_src);
}
report_sender_->SendPluginUMA(plugin_type);
} }
void MissingPluginReporter::SetUMASender(UMASender* sender) { void PluginUMAReporter::ReportPluginDisabled(
report_sender_.reset(sender); const std::string& plugin_mime_type, const GURL& plugin_src) {
report_sender_->SendPluginUMA(DISABLED_PLUGIN,
GetPluginType(plugin_mime_type, plugin_src));
} }
MissingPluginReporter::MissingPluginReporter() PluginUMAReporter::PluginUMAReporter() : report_sender_(new UMASenderImpl()) {
: report_sender_(new UMASenderImpl()) {
} }
MissingPluginReporter::~MissingPluginReporter() { PluginUMAReporter::~PluginUMAReporter() {
} }
// static. // static.
bool MissingPluginReporter::CompareCStrings(const char* first, bool PluginUMAReporter::CompareCStrings(const char* first, const char* second) {
const char* second) {
return strcmp(first, second) < 0; return strcmp(first, second) < 0;
} }
bool MissingPluginReporter::CStringArrayContainsCString(const char** array, bool PluginUMAReporter::CStringArrayContainsCString(const char** array,
size_t array_size, size_t array_size,
const char* str) { const char* str) {
return std::binary_search(array, array + array_size, str, CompareCStrings); return std::binary_search(array, array + array_size, str, CompareCStrings);
} }
void MissingPluginReporter::ExtractFileExtension(const GURL& src, void PluginUMAReporter::ExtractFileExtension(const GURL& src,
std::string* extension) { std::string* extension) {
std::string extension_file_path(src.ExtractFileName()); std::string extension_file_path(src.ExtractFileName());
if (extension_file_path.empty()) if (extension_file_path.empty())
...@@ -115,7 +121,17 @@ void MissingPluginReporter::ExtractFileExtension(const GURL& src, ...@@ -115,7 +121,17 @@ void MissingPluginReporter::ExtractFileExtension(const GURL& src,
StringToLowerASCII(extension); StringToLowerASCII(extension);
} }
MissingPluginReporter::PluginType MissingPluginReporter::SrcToPluginType( PluginUMAReporter::PluginType PluginUMAReporter::GetPluginType(
const std::string& plugin_mime_type, const GURL& plugin_src) {
// If we know plugin's mime type, we use it to determine plugin's type. Else,
// we try to determine plugin type using plugin source's extension.
if (!plugin_mime_type.empty())
return MimeTypeToPluginType(StringToLowerASCII(plugin_mime_type));
return SrcToPluginType(plugin_src);
}
PluginUMAReporter::PluginType PluginUMAReporter::SrcToPluginType(
const GURL& src) { const GURL& src) {
std::string file_extension; std::string file_extension;
ExtractFileExtension(src, &file_extension); ExtractFileExtension(src, &file_extension);
...@@ -140,7 +156,7 @@ MissingPluginReporter::PluginType MissingPluginReporter::SrcToPluginType( ...@@ -140,7 +156,7 @@ MissingPluginReporter::PluginType MissingPluginReporter::SrcToPluginType(
return OTHER; return OTHER;
} }
MissingPluginReporter::PluginType MissingPluginReporter::MimeTypeToPluginType( PluginUMAReporter::PluginType PluginUMAReporter::MimeTypeToPluginType(
const std::string& mime_type) { const std::string& mime_type) {
if (strcmp(mime_type.c_str(), kWindowsMediaPlayerType) == 0) if (strcmp(mime_type.c_str(), kWindowsMediaPlayerType) == 0)
return WINDOWS_MEDIA_PLAYER; return WINDOWS_MEDIA_PLAYER;
...@@ -161,4 +177,3 @@ MissingPluginReporter::PluginType MissingPluginReporter::MimeTypeToPluginType( ...@@ -161,4 +177,3 @@ MissingPluginReporter::PluginType MissingPluginReporter::MimeTypeToPluginType(
return OTHER; return OTHER;
} }
...@@ -15,8 +15,13 @@ ...@@ -15,8 +15,13 @@
// ReportPluginMissing should be called whenever plugin that is not available or // ReportPluginMissing should be called whenever plugin that is not available or
// enabled is called. We try to determine plugin's type by requested mime type, // enabled is called. We try to determine plugin's type by requested mime type,
// or, if mime type is unknown, by plugin's src url. // or, if mime type is unknown, by plugin's src url.
class MissingPluginReporter { class PluginUMAReporter {
public: public:
enum ReportType {
MISSING_PLUGIN,
DISABLED_PLUGIN
};
// This must be sync'd with histogram values. // This must be sync'd with histogram values.
enum PluginType { enum PluginType {
WINDOWS_MEDIA_PLAYER = 0, WINDOWS_MEDIA_PLAYER = 0,
...@@ -31,23 +36,25 @@ class MissingPluginReporter { ...@@ -31,23 +36,25 @@ class MissingPluginReporter {
class UMASender { class UMASender {
public: public:
virtual ~UMASender() {} virtual ~UMASender() {}
virtual void SendPluginUMA(PluginType plugin_type) = 0; virtual void SendPluginUMA(ReportType report_type,
PluginType plugin_type) = 0;
}; };
// Returns singleton instance. // Returns singleton instance.
static MissingPluginReporter* GetInstance(); static PluginUMAReporter* GetInstance();
void ReportPluginMissing(std::string plugin_mime_type, void ReportPluginMissing(const std::string& plugin_mime_type,
const GURL& plugin_src); const GURL& plugin_src);
// Used in testing. void ReportPluginDisabled(const std::string& plugin_mime_type,
void SetUMASender(UMASender* sender); const GURL& plugin_src);
private: private:
friend struct DefaultSingletonTraits<MissingPluginReporter>; friend struct DefaultSingletonTraits<PluginUMAReporter>;
friend class PluginUMATest;
MissingPluginReporter(); PluginUMAReporter();
~MissingPluginReporter(); ~PluginUMAReporter();
static bool CompareCStrings(const char* first, const char* second); static bool CompareCStrings(const char* first, const char* second);
bool CStringArrayContainsCString(const char** array, bool CStringArrayContainsCString(const char** array,
...@@ -56,6 +63,9 @@ class MissingPluginReporter { ...@@ -56,6 +63,9 @@ class MissingPluginReporter {
// Extracts file extension from url. // Extracts file extension from url.
void ExtractFileExtension(const GURL& src, std::string* extension); void ExtractFileExtension(const GURL& src, std::string* extension);
PluginType GetPluginType(const std::string& plugin_mime_type,
const GURL& plugin_src);
// Converts plugin's src to plugin type. // Converts plugin's src to plugin type.
PluginType SrcToPluginType(const GURL& src); PluginType SrcToPluginType(const GURL& src);
// Converts plugin's mime type to plugin type. // Converts plugin's mime type to plugin type.
...@@ -63,7 +73,7 @@ class MissingPluginReporter { ...@@ -63,7 +73,7 @@ class MissingPluginReporter {
scoped_ptr<UMASender> report_sender_; scoped_ptr<UMASender> report_sender_;
DISALLOW_COPY_AND_ASSIGN(MissingPluginReporter); DISALLOW_COPY_AND_ASSIGN(PluginUMAReporter);
}; };
#endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_ #endif // CHROME_RENDERER_PLUGINS_PLUGIN_UMA_H_
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment