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

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: Rebase Created 4 years, 8 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
10 using content::PermissionType; 13 using content::PermissionType;
11 14
12 // The returned strings must match the RAPPOR metrics in rappor.xml, 15 // The returned strings must match the RAPPOR metrics in rappor.xml,
13 // and any Field Trial configs for the Permissions kill switch e.g. 16 // and any Field Trial configs for the Permissions kill switch e.g.
14 // Permissions.Action.Geolocation etc.. 17 // Permissions.Action.Geolocation etc..
15 std::string PermissionUtil::GetPermissionString( 18 std::string PermissionUtil::GetPermissionString(
16 content::PermissionType permission) { 19 content::PermissionType permission) {
17 switch (permission) { 20 switch (permission) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 *out = PermissionType::BACKGROUND_SYNC; 65 *out = PermissionType::BACKGROUND_SYNC;
63 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 66 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
64 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { 67 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
65 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; 68 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER;
66 #endif 69 #endif
67 } else { 70 } else {
68 return false; 71 return false;
69 } 72 }
70 return true; 73 return true;
71 } 74 }
75
76 void PermissionUtil::SetContentSettingAndRecordRevocation(
77 Profile* profile,
78 const GURL& primary_url,
79 const GURL& secondary_url,
80 ContentSettingsType content_type,
81 std::string resource_identifier,
82 ContentSetting setting) {
83 HostContentSettingsMap* map =
84 HostContentSettingsMapFactory::GetForProfile(profile);
85 ContentSetting previous_value = map->GetContentSetting(
86 primary_url, secondary_url, content_type, resource_identifier);
87
88 map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type,
89 resource_identifier, setting);
90
91 ContentSetting final_value = map->GetContentSetting(
92 primary_url, secondary_url, content_type, resource_identifier);
93
94 if (previous_value == CONTENT_SETTING_ALLOW &&
95 final_value != CONTENT_SETTING_ALLOW) {
96 PermissionType permission_type;
97 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) {
98 PermissionUmaUtil::PermissionRevoked(permission_type, primary_url);
99 }
100 }
101 }
OLDNEW
« 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