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

Side by Side Diff: chrome/browser/permissions/permission_util.cc

Issue 1803973002: Content Settings: Add RevocationObserver to measure when permissions are revoked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewrite patch in permissions layer Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "chrome/browser/permissions/permission_util.h" 5 #include "chrome/browser/permissions/permission_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9 #include "chrome/browser/permissions/permission_uma_util.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h"
8 #include "content/public/browser/permission_type.h" 11 #include "content/public/browser/permission_type.h"
9 12
13
Bernhard Bauer 2016/03/22 10:13:29 Nit: This empty line is unnecessary.
tsergeant 2016/03/22 23:55:20 Done.
10 using content::PermissionType; 14 using content::PermissionType;
11 15
12 // The returned strings must match the RAPPOR metrics in rappor.xml, 16 // The returned strings must match the RAPPOR metrics in rappor.xml,
13 // and any Field Trial configs for the Permissions kill switch e.g. 17 // and any Field Trial configs for the Permissions kill switch e.g.
14 // Permissions.Action.Geolocation etc.. 18 // Permissions.Action.Geolocation etc..
15 std::string PermissionUtil::GetPermissionString( 19 std::string PermissionUtil::GetPermissionString(
16 content::PermissionType permission) { 20 content::PermissionType permission) {
17 switch (permission) { 21 switch (permission) {
18 case content::PermissionType::GEOLOCATION: 22 case content::PermissionType::GEOLOCATION:
19 return "Geolocation"; 23 return "Geolocation";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 *out = PermissionType::BACKGROUND_SYNC; 66 *out = PermissionType::BACKGROUND_SYNC;
63 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 67 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
64 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { 68 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
65 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; 69 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER;
66 #endif 70 #endif
67 } else { 71 } else {
68 return false; 72 return false;
69 } 73 }
70 return true; 74 return true;
71 } 75 }
76
77 bool PermissionUtil::SetContentSettingRecordRevocation(
78 Profile* profile,
79 const GURL& primary_url,
80 const GURL& secondary_url,
81 ContentSettingsType content_type,
82 std::string resource_identifier,
83 ContentSetting setting) {
84 HostContentSettingsMap* map =
85 HostContentSettingsMapFactory::GetForProfile(profile);
86 ContentSetting previous_value = map->GetContentSetting(
87 primary_url, secondary_url, content_type, resource_identifier);
88
89 map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type,
90 resource_identifier, setting);
91
92 ContentSetting final_value = map->GetContentSetting(
93 primary_url, secondary_url, content_type, resource_identifier);
94
95 if (previous_value == CONTENT_SETTING_ALLOW &&
96 final_value != CONTENT_SETTING_ALLOW) {
97 PermissionType permission_type;
98 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) {
99 PermissionUmaUtil::PermissionRevoked(permission_type, primary_url);
100 return true;
101 }
102 }
103 return false;
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698