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

Side by Side Diff: chrome/browser/permissions/permission_manager.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: Add test 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_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
12 #include "chrome/browser/permissions/permission_context.h" 12 #include "chrome/browser/permissions/permission_context.h"
13 #include "chrome/browser/permissions/permission_context_base.h" 13 #include "chrome/browser/permissions/permission_context_base.h"
14 #include "chrome/browser/permissions/permission_request_id.h" 14 #include "chrome/browser/permissions/permission_request_id.h"
15 #include "chrome/browser/permissions/permission_uma_util.h"
16 #include "chrome/browser/permissions/permission_util.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/tab_contents/tab_util.h" 18 #include "chrome/browser/tab_contents/tab_util.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 19 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "content/public/browser/permission_type.h" 20 #include "content/public/browser/permission_type.h"
19 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
22 24
23 #if !defined(OS_ANDROID) 25 #if !defined(OS_ANDROID)
24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 PermissionType permission; 193 PermissionType permission;
192 GURL requesting_origin; 194 GURL requesting_origin;
193 GURL embedding_origin; 195 GURL embedding_origin;
194 base::Callback<void(PermissionStatus)> callback; 196 base::Callback<void(PermissionStatus)> callback;
195 ContentSetting current_value; 197 ContentSetting current_value;
196 }; 198 };
197 199
198 PermissionManager::PermissionManager(Profile* profile) 200 PermissionManager::PermissionManager(Profile* profile)
199 : profile_(profile), 201 : profile_(profile),
200 weak_ptr_factory_(this) { 202 weak_ptr_factory_(this) {
203 HostContentSettingsMapFactory::GetForProfile(profile_)->AddRevocationObserver(
204 this);
201 } 205 }
202 206
203 PermissionManager::~PermissionManager() { 207 PermissionManager::~PermissionManager() {
208 HostContentSettingsMap* map =
209 HostContentSettingsMapFactory::GetForProfile(profile_);
210 map->RemoveRevocationObserver(this);
204 if (!subscriptions_.IsEmpty()) 211 if (!subscriptions_.IsEmpty())
205 HostContentSettingsMapFactory::GetForProfile(profile_) 212 map->RemoveObserver(this);
206 ->RemoveObserver(this);
207 } 213 }
208 214
209 int PermissionManager::RequestPermission( 215 int PermissionManager::RequestPermission(
210 PermissionType permission, 216 PermissionType permission,
211 content::RenderFrameHost* render_frame_host, 217 content::RenderFrameHost* render_frame_host,
212 const GURL& requesting_origin, 218 const GURL& requesting_origin,
213 const base::Callback<void(PermissionStatus)>& callback) { 219 const base::Callback<void(PermissionStatus)>& callback) {
214 return RequestPermissions( 220 return RequestPermissions(
215 std::vector<PermissionType>(1, permission), 221 std::vector<PermissionType>(1, permission),
216 render_frame_host, 222 render_frame_host,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 // Add the callback to |callbacks| which will be run after the loop to 428 // Add the callback to |callbacks| which will be run after the loop to
423 // prevent re-entrance issues. 429 // prevent re-entrance issues.
424 callbacks.push_back( 430 callbacks.push_back(
425 base::Bind(subscription->callback, 431 base::Bind(subscription->callback,
426 ContentSettingToPermissionStatus(new_value))); 432 ContentSettingToPermissionStatus(new_value)));
427 } 433 }
428 434
429 for (const auto& callback : callbacks) 435 for (const auto& callback : callbacks)
430 callback.Run(); 436 callback.Run();
431 } 437 }
438
439 void PermissionManager::OnContentSettingRevoked(
440 const GURL& primary_url,
441 const GURL& secondary_url,
442 ContentSettingsType content_type,
443 std::string resource_identifier) {
444 PermissionType permission_type;
445 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) {
raymes 2016/03/17 02:05:43 nit: no {}
tsergeant 2016/03/17 06:25:40 Done.
446 PermissionUmaUtil::PermissionRevoked(permission_type, primary_url);
kcarattini 2016/03/17 02:51:22 Is going to change how often revocation is reporte
tsergeant 2016/03/17 06:25:40 Good idea, done.
447 }
448 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698