Index: chrome/browser/permissions/permission_util.cc |
diff --git a/chrome/browser/permissions/permission_util.cc b/chrome/browser/permissions/permission_util.cc |
index 46ab398ee943b3140578bbae7517f609ad64676d..35c087e51c8d7770c113d6faca99f9efe6e67f68 100644 |
--- a/chrome/browser/permissions/permission_util.cc |
+++ b/chrome/browser/permissions/permission_util.cc |
@@ -78,33 +78,41 @@ bool PermissionUtil::GetPermissionType(ContentSettingsType type, |
return true; |
} |
-void PermissionUtil::SetContentSettingAndRecordRevocation( |
+PermissionUtil::ScopedRevocationReporter::ScopedRevocationReporter( |
Profile* profile, |
const GURL& primary_url, |
const GURL& secondary_url, |
ContentSettingsType content_type, |
- std::string resource_identifier, |
- ContentSetting setting) { |
+ PermissionSourceUI source_ui) |
+ : profile_(profile), |
+ primary_url_(primary_url), |
+ secondary_url_(secondary_url), |
+ content_type_(content_type), |
+ source_ui_(source_ui) { |
+ if (!primary_url_.is_valid() || |
+ (!secondary_url_.is_valid() && !secondary_url_.is_empty())) { |
+ is_initially_allowed_ = false; |
+ return; |
+ } |
HostContentSettingsMap* map = |
- HostContentSettingsMapFactory::GetForProfile(profile); |
- ContentSetting previous_value = map->GetContentSetting( |
- primary_url, secondary_url, content_type, resource_identifier); |
- |
- map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type, |
- resource_identifier, setting); |
- |
- ContentSetting final_value = map->GetContentSetting( |
- primary_url, secondary_url, content_type, resource_identifier); |
+ HostContentSettingsMapFactory::GetForProfile(profile_); |
+ ContentSetting initial_content_setting = map->GetContentSetting( |
+ primary_url_, secondary_url_, content_type_, std::string()); |
+ is_initially_allowed_ = initial_content_setting == CONTENT_SETTING_ALLOW; |
+} |
- if (previous_value == CONTENT_SETTING_ALLOW && |
- final_value != CONTENT_SETTING_ALLOW) { |
+PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() { |
+ if (!is_initially_allowed_) |
+ return; |
+ HostContentSettingsMap* map = |
+ HostContentSettingsMapFactory::GetForProfile(profile_); |
+ ContentSetting final_content_setting = map->GetContentSetting( |
+ primary_url_, secondary_url_, content_type_, std::string()); |
+ if (final_content_setting != CONTENT_SETTING_ALLOW) { |
PermissionType permission_type; |
- if (PermissionUtil::GetPermissionType(content_type, &permission_type)) { |
- // TODO(stefanocs): Report revocations from page action as PAGE_ACTION |
- // source UI instead of SITE_SETTINGS source UI. |
- PermissionUmaUtil::PermissionRevoked(permission_type, |
- PermissionSourceUI::SITE_SETTINGS, |
- primary_url, profile); |
+ if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { |
+ PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, |
+ primary_url_, profile_); |
} |
} |
} |