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

Unified Diff: chrome/browser/permissions/permission_util.cc

Issue 2165733003: Add revocation reporter to permission util (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add-source-ui-to-permission-report
Patch Set: Rebase Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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_);
}
}
}
« no previous file with comments | « chrome/browser/permissions/permission_util.h ('k') | chrome/browser/permissions/permission_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698