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

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: Fixed patch conflict 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 228 }
227 229
228 void PermissionManager::RegisterPermissionUsage(PermissionType permission, 230 void PermissionManager::RegisterPermissionUsage(PermissionType permission,
229 const GURL& requesting_origin, 231 const GURL& requesting_origin,
230 const GURL& embedding_origin) { 232 const GURL& embedding_origin) {
231 // This is required because constant permissions don't have a 233 // This is required because constant permissions don't have a
232 // ContentSettingsType. 234 // ContentSettingsType.
233 if (IsConstantPermission(permission)) 235 if (IsConstantPermission(permission))
234 return; 236 return;
235 237
236 profile_->GetHostContentSettingsMap()->UpdateLastUsage( 238 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage(
237 requesting_origin, 239 requesting_origin,
238 embedding_origin, 240 embedding_origin,
239 PermissionTypeToContentSetting(permission)); 241 PermissionTypeToContentSetting(permission));
240 } 242 }
241 243
242 int PermissionManager::SubscribePermissionStatusChange( 244 int PermissionManager::SubscribePermissionStatusChange(
243 PermissionType permission, 245 PermissionType permission,
244 const GURL& requesting_origin, 246 const GURL& requesting_origin,
245 const GURL& embedding_origin, 247 const GURL& embedding_origin,
246 const base::Callback<void(PermissionStatus)>& callback) { 248 const base::Callback<void(PermissionStatus)>& callback) {
247 if (subscriptions_.IsEmpty()) 249 if (subscriptions_.IsEmpty())
248 profile_->GetHostContentSettingsMap()->AddObserver(this); 250 HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
249 251
250 Subscription* subscription = new Subscription(); 252 Subscription* subscription = new Subscription();
251 subscription->permission = permission; 253 subscription->permission = permission;
252 subscription->requesting_origin = requesting_origin; 254 subscription->requesting_origin = requesting_origin;
253 subscription->embedding_origin = embedding_origin; 255 subscription->embedding_origin = embedding_origin;
254 subscription->callback = callback; 256 subscription->callback = callback;
255 257
256 if (IsConstantPermission(permission)) { 258 if (IsConstantPermission(permission)) {
257 subscription->current_value = GetContentSettingForConstantPermission( 259 subscription->current_value = GetContentSettingForConstantPermission(
258 permission); 260 permission);
259 } else { 261 } else {
260 subscription->current_value = PermissionContext::Get(profile_, permission) 262 subscription->current_value = PermissionContext::Get(profile_, permission)
261 ->GetPermissionStatus(subscription->requesting_origin, 263 ->GetPermissionStatus(subscription->requesting_origin,
262 subscription->embedding_origin); 264 subscription->embedding_origin);
263 } 265 }
264 266
265 return subscriptions_.Add(subscription); 267 return subscriptions_.Add(subscription);
266 } 268 }
267 269
268 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { 270 void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) {
269 // Whether |subscription_id| is known will be checked by the Remove() call. 271 // Whether |subscription_id| is known will be checked by the Remove() call.
270 subscriptions_.Remove(subscription_id); 272 subscriptions_.Remove(subscription_id);
271 273
272 if (subscriptions_.IsEmpty()) 274 if (subscriptions_.IsEmpty())
273 profile_->GetHostContentSettingsMap()->RemoveObserver(this); 275 HostContentSettingsMapFactory::GetForProfile(profile_)
276 ->RemoveObserver(this);
274 } 277 }
275 278
276 bool PermissionManager::IsPermissionBubbleManagerMissing( 279 bool PermissionManager::IsPermissionBubbleManagerMissing(
277 content::WebContents* web_contents) { 280 content::WebContents* web_contents) {
278 // Can't be missing if it isn't needed to begin with. 281 // Can't be missing if it isn't needed to begin with.
279 if (!PermissionBubbleManager::Enabled()) 282 if (!PermissionBubbleManager::Enabled())
280 return false; 283 return false;
281 284
282 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr; 285 return PermissionBubbleManager::FromWebContents(web_contents) == nullptr;
283 } 286 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Add the callback to |callbacks| which will be run after the loop to 319 // Add the callback to |callbacks| which will be run after the loop to
317 // prevent re-entrance issues. 320 // prevent re-entrance issues.
318 callbacks.push_back( 321 callbacks.push_back(
319 base::Bind(subscription->callback, 322 base::Bind(subscription->callback,
320 ContentSettingToPermissionStatus(new_value))); 323 ContentSettingToPermissionStatus(new_value)));
321 } 324 }
322 325
323 for (const auto& callback : callbacks) 326 for (const auto& callback : callbacks)
324 callback.Run(); 327 callback.Run();
325 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698