Chromium Code Reviews| Index: components/content_settings/core/browser/content_settings_pref.cc |
| diff --git a/components/content_settings/core/browser/content_settings_pref.cc b/components/content_settings/core/browser/content_settings_pref.cc |
| index e1e2b332e5ac1b509780d02a937c906cf4c583a8..8c2f4705461b02cf74b325ed0031c8606be459cd 100644 |
| --- a/components/content_settings/core/browser/content_settings_pref.cc |
| +++ b/components/content_settings/core/browser/content_settings_pref.cc |
| @@ -27,6 +27,59 @@ const char kSettingPath[] = "setting"; |
| const char kPerResourceIdentifierPrefName[] = "per_resource"; |
| const char kLastUsed[] = "last_used"; |
| +struct ExceptionUmaStats { |
| + ContentSettingsType settings_type; |
| + const char* allow_exception_metrics_name; |
| + size_t allow_exception_count; |
| + const char* block_exception_metrics_name; |
| + size_t block_exception_count; |
| + const char* ask_exception_metrics_name; |
| + size_t ask_exception_count; |
| + const char* important_content_exception_metrics_name; |
| + size_t important_content_exception_count; |
| + const char* session_only_exception_metrics_name; |
| + size_t session_only_exception_count; |
| +}; |
| + |
| +ExceptionUmaStats ContentSettingExceptionUmaMap[] = { |
| + { |
| + CONTENT_SETTINGS_TYPE_COOKIES, |
| + "ContentSettings.NumberOfAllowCookiesExceptions", 0, |
| + "ContentSettings.NumberOfBlockCookiesExceptions", 0, "", 0, "", 0, |
| + "ContentSettings.NumberOfSessionOnlyCookiesExceptions", 0, |
| + }, |
| + { |
| + CONTENT_SETTINGS_TYPE_IMAGES, |
| + "ContentSettings.NumberOfAllowImagesExceptions", 0, |
| + "ContentSettings.NumberOfBlockImagesExceptions", 0, "", 0, "", 0, "", 0, |
| + }, |
| + { |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| + "ContentSettings.NumberOfAllowJavaScriptExceptions", 0, |
| + "ContentSettings.NumberOfBlockJavaScriptExceptions", 0, "", 0, "", 0, |
| + "", 0, |
| + }, |
| + { |
| + CONTENT_SETTINGS_TYPE_PLUGINS, |
| + "ContentSettings.NumberOfAllowPluginsExceptions", 0, |
| + "ContentSettings.NumberOfBlockPluginsExceptions", 0, |
| + "ContentSettings.NumberOfAskPluginsExceptions", 0, |
| + "ContentSettings.NumberOfDetectImportantContentPluginsExceptions", 0, |
| + "", 0, |
| + }, |
| + { |
| + CONTENT_SETTINGS_TYPE_POPUPS, |
| + "ContentSettings.NumberOfAllowPopupsExceptions", 0, |
| + "ContentSettings.NumberOfBlockPopupsExceptions", 0, "", 0, "", 0, "", 0, |
| + }, |
| + { |
| + CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| + "ContentSettings.NumberOfAllowAutomaticDownloadsExceptions", 0, |
| + "ContentSettings.NumberOfBlockAutomaticDownloadsExceptions", 0, |
| + "ContentSettings.NumberOfAskAutomaticDownloadsExceptions", 0, "", 0, "", |
| + 0, |
| + }}; |
| + |
| // If the given content type supports resource identifiers in user preferences, |
| // returns true and sets |pref_key| to the key in the content settings |
| // dictionary under which per-resource content settings are stored. |
| @@ -280,9 +333,6 @@ void ContentSettingsPref::ReadContentSettingsFromPref() { |
| // Convert all Unicode patterns into punycode form, then read. |
| CanonicalizeContentSettingsExceptions(mutable_settings); |
| - size_t cookies_block_exception_count = 0; |
| - size_t cookies_allow_exception_count = 0; |
| - size_t cookies_session_only_exception_count = 0; |
| for (base::DictionaryValue::Iterator i(*mutable_settings); !i.IsAtEnd(); |
| i.Advance()) { |
| const std::string& pattern_str(i.key()); |
| @@ -334,34 +384,55 @@ void ContentSettingsPref::ReadContentSettingsFromPref() { |
| content_type_, |
| ResourceIdentifier(), |
| value->DeepCopy()); |
| - if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { |
| - ContentSetting s = ValueToContentSetting(value); |
| - switch (s) { |
| - case CONTENT_SETTING_ALLOW : |
| - ++cookies_allow_exception_count; |
| - break; |
| - case CONTENT_SETTING_BLOCK : |
| - ++cookies_block_exception_count; |
| - break; |
| - case CONTENT_SETTING_SESSION_ONLY : |
| - ++cookies_session_only_exception_count; |
| - break; |
| - default: |
| - NOTREACHED(); |
| - break; |
| + |
| + for (ExceptionUmaStats stats : ContentSettingExceptionUmaMap) { |
|
raymes
2016/04/07 04:57:59
I think that perhaps we can just measure all types
raymes
2016/04/07 04:57:59
Can we move this code higher up the stack? Perhaps
lshang
2016/04/11 06:31:07
Done.
lshang
2016/04/11 06:31:07
Done.
|
| + if (stats.settings_type == content_type_) { |
| + ContentSetting s = ValueToContentSetting(value); |
| + switch (s) { |
| + case CONTENT_SETTING_ALLOW: |
| + ++stats.allow_exception_count; |
| + break; |
| + case CONTENT_SETTING_BLOCK: |
| + ++stats.block_exception_count; |
|
raymes
2016/04/07 04:57:59
I think we should probably only worry about allow/
lshang
2016/04/11 06:31:07
Done.
|
| + break; |
| + case CONTENT_SETTING_ASK: |
| + ++stats.ask_exception_count; |
| + break; |
| + case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: |
| + ++stats.important_content_exception_count; |
| + break; |
| + case CONTENT_SETTING_SESSION_ONLY: |
| + ++stats.session_only_exception_count; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| } |
| } |
| } |
| } |
| - if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { |
| - UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfBlockCookiesExceptions", |
| - cookies_block_exception_count); |
| - UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfAllowCookiesExceptions", |
| - cookies_allow_exception_count); |
| - UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfSessionOnlyCookiesExceptions", |
| - cookies_session_only_exception_count); |
| + for (ExceptionUmaStats stats : ContentSettingExceptionUmaMap) { |
| + if (stats.settings_type == content_type_) { |
| + UMA_HISTOGRAM_COUNTS(stats.allow_exception_metrics_name, |
| + stats.allow_exception_count); |
| + UMA_HISTOGRAM_COUNTS(stats.block_exception_metrics_name, |
| + stats.block_exception_count); |
| + if (content_type_ == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) { |
| + UMA_HISTOGRAM_COUNTS(stats.ask_exception_metrics_name, |
| + stats.ask_exception_count); |
| + } else if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| + UMA_HISTOGRAM_COUNTS(stats.ask_exception_metrics_name, |
| + stats.ask_exception_count); |
| + UMA_HISTOGRAM_COUNTS(stats.important_content_exception_metrics_name, |
| + stats.important_content_exception_count); |
| + } else if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { |
| + UMA_HISTOGRAM_COUNTS(stats.session_only_exception_metrics_name, |
| + stats.session_only_exception_count); |
| + } |
| + } |
| } |
| } |