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

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

Issue 1312453005: Removed Profile::GetHostContentSettingsMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed Notification Subscription from SupervisedProvider Created 5 years, 3 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 "base/callback.h" 7 #include "base/callback.h"
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
8 #include "chrome/browser/permissions/permission_context.h" 9 #include "chrome/browser/permissions/permission_context.h"
9 #include "chrome/browser/permissions/permission_context_base.h" 10 #include "chrome/browser/permissions/permission_context_base.h"
10 #include "chrome/browser/permissions/permission_request_id.h" 11 #include "chrome/browser/permissions/permission_request_id.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
13 #include "components/content_settings/core/browser/host_content_settings_map.h" 14 #include "components/content_settings/core/browser/host_content_settings_map.h"
14 #include "content/public/browser/permission_type.h" 15 #include "content/public/browser/permission_type.h"
15 #include "content/public/browser/render_frame_host.h" 16 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 base::Callback<void(PermissionStatus)> callback; 129 base::Callback<void(PermissionStatus)> callback;
129 ContentSetting current_value; 130 ContentSetting current_value;
130 }; 131 };
131 132
132 PermissionManager::PermissionManager(Profile* profile) 133 PermissionManager::PermissionManager(Profile* profile)
133 : profile_(profile) { 134 : profile_(profile) {
134 } 135 }
135 136
136 PermissionManager::~PermissionManager() { 137 PermissionManager::~PermissionManager() {
137 if (!subscriptions_.IsEmpty()) 138 if (!subscriptions_.IsEmpty())
138 profile_->GetHostContentSettingsMap()->RemoveObserver(this); 139 HostContentSettingsMapFactory::GetForProfile(profile_)
140 ->RemoveObserver(this);
139 } 141 }
140 142
141 void PermissionManager::RequestPermission( 143 void PermissionManager::RequestPermission(
142 PermissionType permission, 144 PermissionType permission,
143 content::RenderFrameHost* render_frame_host, 145 content::RenderFrameHost* render_frame_host,
144 int request_id, 146 int request_id,
145 const GURL& requesting_origin, 147 const GURL& requesting_origin,
146 bool user_gesture, 148 bool user_gesture,
147 const base::Callback<void(PermissionStatus)>& callback) { 149 const base::Callback<void(PermissionStatus)>& callback) {
148 if (IsConstantPermission(permission)) { 150 if (IsConstantPermission(permission)) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 230 }
229 231
230 void PermissionManager::RegisterPermissionUsage(PermissionType permission, 232 void PermissionManager::RegisterPermissionUsage(PermissionType permission,
231 const GURL& requesting_origin, 233 const GURL& requesting_origin,
232 const GURL& embedding_origin) { 234 const GURL& embedding_origin) {
233 // This is required because constant permissions don't have a 235 // This is required because constant permissions don't have a
234 // ContentSettingsType. 236 // ContentSettingsType.
235 if (IsConstantPermission(permission)) 237 if (IsConstantPermission(permission))
236 return; 238 return;
237 239
238 profile_->GetHostContentSettingsMap()->UpdateLastUsage( 240 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage(
239 requesting_origin, 241 requesting_origin,
240 embedding_origin, 242 embedding_origin,
241 PermissionTypeToContentSetting(permission)); 243 PermissionTypeToContentSetting(permission));
242 } 244 }
243 245
244 int PermissionManager::SubscribePermissionStatusChange( 246 int PermissionManager::SubscribePermissionStatusChange(
245 PermissionType permission, 247 PermissionType permission,
246 const GURL& requesting_origin, 248 const GURL& requesting_origin,
247 const GURL& embedding_origin, 249 const GURL& embedding_origin,
248 const base::Callback<void(PermissionStatus)>& callback) { 250 const base::Callback<void(PermissionStatus)>& callback) {
249 if (subscriptions_.IsEmpty()) 251 if (subscriptions_.IsEmpty())
250 profile_->GetHostContentSettingsMap()->AddObserver(this); 252 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
251 253
252 Subscription* subscription = new Subscription(); 254 Subscription* subscription = new Subscription();
253 subscription->permission = permission; 255 subscription->permission = permission;
254 subscription->requesting_origin = requesting_origin; 256 subscription->requesting_origin = requesting_origin;
255 subscription->embedding_origin = embedding_origin; 257 subscription->embedding_origin = embedding_origin;
256 subscription->callback = callback; 258 subscription->callback = callback;
257 259
258 if (IsConstantPermission(permission)) { 260 if (IsConstantPermission(permission)) {
259 subscription->current_value = GetContentSettingForConstantPermission( 261 subscription->current_value = GetContentSettingForConstantPermission(
260 permission); 262 permission);
261 } else { 263 } else {
262 subscription->current_value = PermissionContext::Get(profile_, permission) 264 subscription->current_value = PermissionContext::Get(profile_, permission)
263 ->GetPermissionStatus(subscription->requesting_origin, 265 ->GetPermissionStatus(subscription->requesting_origin,
264 subscription->embedding_origin); 266 subscription->embedding_origin);
265 } 267 }
266 268
267 return subscriptions_.Add(subscription); 269 return subscriptions_.Add(subscription);
268 } 270 }
269 271
270 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { 272 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) {
271 // Whether |subscription_id| is known will be checked by the Remove() call. 273 // Whether |subscription_id| is known will be checked by the Remove() call.
272 subscriptions_.Remove(subscription_id); 274 subscriptions_.Remove(subscription_id);
273 275
274 if (subscriptions_.IsEmpty()) 276 if (subscriptions_.IsEmpty())
275 profile_->GetHostContentSettingsMap()->RemoveObserver(this); 277 HostContentSettingsMapFactory::GetForProfile(profile_)
278 ->RemoveObserver(this);
276 } 279 }
277 280
278 bool PermissionManager::IsPermissionBubbleManagerMissing( 281 bool PermissionManager::IsPermissionBubbleManagerMissing(
279 content::WebContents* web_contents) { 282 content::WebContents* web_contents) {
280 // Can't be missing if it isn't needed to begin with. 283 // Can't be missing if it isn't needed to begin with.
281 if (!PermissionBubbleManager::Enabled()) 284 if (!PermissionBubbleManager::Enabled())
282 return false; 285 return false;
283 286
284 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; 287 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr;
285 } 288 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // Add the callback to |callbacks| which will be run after the loop to 321 // Add the callback to |callbacks| which will be run after the loop to
319 // prevent re-entrance issues. 322 // prevent re-entrance issues.
320 callbacks.push_back( 323 callbacks.push_back(
321 base::Bind(subscription->callback, 324 base::Bind(subscription->callback,
322 ContentSettingToPermissionStatus(new_value))); 325 ContentSettingToPermissionStatus(new_value)));
323 } 326 }
324 327
325 for (const auto& callback : callbacks) 328 for (const auto& callback : callbacks)
326 callback.Run(); 329 callback.Run();
327 } 330 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698