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

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

Issue 2180723002: Add revocation metrics from OIB and content setting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@revocation-reporter
Patch Set: Add setter for settings map 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 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" 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9 #include "chrome/browser/permissions/permission_uma_util.h" 9 #include "chrome/browser/permissions/permission_uma_util.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h" 10 #include "components/content_settings/core/browser/host_content_settings_map.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return true; 78 return true;
79 } 79 }
80 80
81 PermissionUtil::ScopedRevocationReporter::ScopedRevocationReporter( 81 PermissionUtil::ScopedRevocationReporter::ScopedRevocationReporter(
82 Profile* profile, 82 Profile* profile,
83 const GURL& primary_url, 83 const GURL& primary_url,
84 const GURL& secondary_url, 84 const GURL& secondary_url,
85 ContentSettingsType content_type, 85 ContentSettingsType content_type,
86 PermissionSourceUI source_ui) 86 PermissionSourceUI source_ui)
87 : profile_(profile), 87 : profile_(profile),
88 settings_map_(HostContentSettingsMapFactory::GetForProfile(profile_)),
88 primary_url_(primary_url), 89 primary_url_(primary_url),
89 secondary_url_(secondary_url), 90 secondary_url_(secondary_url),
90 content_type_(content_type), 91 content_type_(content_type),
91 source_ui_(source_ui) { 92 source_ui_(source_ui) {
92 if (!primary_url_.is_valid() || 93 if (!primary_url_.is_valid() ||
93 (!secondary_url_.is_valid() && !secondary_url_.is_empty())) { 94 (!secondary_url_.is_valid() && !secondary_url_.is_empty())) {
94 is_initially_allowed_ = false; 95 is_initially_allowed_ = false;
95 return; 96 return;
96 } 97 }
97 HostContentSettingsMap* map = 98 ContentSetting initial_content_setting = settings_map_->GetContentSetting(
98 HostContentSettingsMapFactory::GetForProfile(profile_);
99 ContentSetting initial_content_setting = map->GetContentSetting(
100 primary_url_, secondary_url_, content_type_, std::string()); 99 primary_url_, secondary_url_, content_type_, std::string());
101 is_initially_allowed_ = initial_content_setting == CONTENT_SETTING_ALLOW; 100 is_initially_allowed_ = initial_content_setting == CONTENT_SETTING_ALLOW;
102 } 101 }
103 102
103 PermissionUtil::ScopedRevocationReporter::ScopedRevocationReporter(
104 Profile* profile,
105 const ContentSettingsPattern& primary_pattern,
106 const ContentSettingsPattern& secondary_pattern,
107 ContentSettingsType content_type,
108 PermissionSourceUI source_ui)
109 : ScopedRevocationReporter(
110 profile,
111 GURL(primary_pattern.ToString()),
112 GURL((secondary_pattern == ContentSettingsPattern::Wildcard())
113 ? primary_pattern.ToString()
114 : secondary_pattern.ToString()),
115 content_type,
116 source_ui) {}
117
104 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() { 118 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() {
105 if (!is_initially_allowed_) 119 if (!is_initially_allowed_)
106 return; 120 return;
107 HostContentSettingsMap* map = 121 ContentSetting final_content_setting = settings_map_->GetContentSetting(
108 HostContentSettingsMapFactory::GetForProfile(profile_);
109 ContentSetting final_content_setting = map->GetContentSetting(
110 primary_url_, secondary_url_, content_type_, std::string()); 122 primary_url_, secondary_url_, content_type_, std::string());
111 if (final_content_setting != CONTENT_SETTING_ALLOW) { 123 if (final_content_setting != CONTENT_SETTING_ALLOW) {
112 PermissionType permission_type; 124 PermissionType permission_type;
113 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { 125 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) {
114 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, 126 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_,
115 primary_url_, profile_); 127 primary_url_, profile_);
116 } 128 }
117 } 129 }
118 } 130 }
131
132 void PermissionUtil::ScopedRevocationReporter::SetCustomSettingsMap(
133 HostContentSettingsMap* settings_map) {
134 this->settings_map_ = settings_map;
135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698