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

Side by Side Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 12631017: Remove notifications when apps and OTR Profiles are removed. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/notifications/desktop_notification_service.h" 5 #include "chrome/browser/notifications/desktop_notification_service.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 void DesktopNotificationService::RemoveNotification( 307 void DesktopNotificationService::RemoveNotification(
308 const std::string& notification_id) { 308 const std::string& notification_id) {
309 g_browser_process->notification_ui_manager()->CancelById(notification_id); 309 g_browser_process->notification_ui_manager()->CancelById(notification_id);
310 } 310 }
311 311
312 DesktopNotificationService::DesktopNotificationService( 312 DesktopNotificationService::DesktopNotificationService(
313 Profile* profile, 313 Profile* profile,
314 NotificationUIManager* ui_manager) 314 NotificationUIManager* ui_manager)
315 : profile_(profile), 315 : profile_(profile),
316 ui_manager_(ui_manager) { 316 ui_manager_(ui_manager) {
317 StartObserving();
318 }
319
320 DesktopNotificationService::~DesktopNotificationService() {
321 StopObserving();
322 }
323
324 void DesktopNotificationService::StartObserving() {
325 if (!profile_->IsOffTheRecord()) {
326 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
327 content::Source<Profile>(profile_));
328 }
329 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
330 content::Source<Profile>(profile_));
331 #if defined(ENABLE_MESSAGE_CENTER) 317 #if defined(ENABLE_MESSAGE_CENTER)
332 OnDisabledExtensionIdsChanged(); 318 OnDisabledExtensionIdsChanged();
333 disabled_extension_id_pref_.Init( 319 disabled_extension_id_pref_.Init(
334 prefs::kMessageCenterDisabledExtensionIds, 320 prefs::kMessageCenterDisabledExtensionIds,
335 profile_->GetPrefs(), 321 profile_->GetPrefs(),
336 base::Bind( 322 base::Bind(
337 &DesktopNotificationService::OnDisabledExtensionIdsChanged, 323 &DesktopNotificationService::OnDisabledExtensionIdsChanged,
338 base::Unretained(this))); 324 base::Unretained(this)));
339 #endif 325 #endif
340 } 326 }
341 327
342 void DesktopNotificationService::StopObserving() { 328 DesktopNotificationService::~DesktopNotificationService() {
343 notification_registrar_.RemoveAll();
344 #if defined(ENABLE_MESSAGE_CENTER) 329 #if defined(ENABLE_MESSAGE_CENTER)
345 disabled_extension_id_pref_.Destroy(); 330 disabled_extension_id_pref_.Destroy();
346 #endif 331 #endif
347 } 332 }
348 333
349 void DesktopNotificationService::GrantPermission(const GURL& origin) { 334 void DesktopNotificationService::GrantPermission(const GURL& origin) {
350 ContentSettingsPattern primary_pattern = 335 ContentSettingsPattern primary_pattern =
351 ContentSettingsPattern::FromURLNoWildcard(origin); 336 ContentSettingsPattern::FromURLNoWildcard(origin);
352 profile_->GetHostContentSettingsMap()->SetContentSetting( 337 profile_->GetHostContentSettingsMap()->SetContentSetting(
353 primary_pattern, 338 primary_pattern,
354 ContentSettingsPattern::Wildcard(), 339 ContentSettingsPattern::Wildcard(),
355 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 340 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
356 NO_RESOURCE_IDENTIFIER, 341 NO_RESOURCE_IDENTIFIER,
357 CONTENT_SETTING_ALLOW); 342 CONTENT_SETTING_ALLOW);
358 } 343 }
359 344
360 void DesktopNotificationService::DenyPermission(const GURL& origin) { 345 void DesktopNotificationService::DenyPermission(const GURL& origin) {
361 ContentSettingsPattern primary_pattern = 346 ContentSettingsPattern primary_pattern =
362 ContentSettingsPattern::FromURLNoWildcard(origin); 347 ContentSettingsPattern::FromURLNoWildcard(origin);
363 profile_->GetHostContentSettingsMap()->SetContentSetting( 348 profile_->GetHostContentSettingsMap()->SetContentSetting(
364 primary_pattern, 349 primary_pattern,
365 ContentSettingsPattern::Wildcard(), 350 ContentSettingsPattern::Wildcard(),
366 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 351 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
367 NO_RESOURCE_IDENTIFIER, 352 NO_RESOURCE_IDENTIFIER,
368 CONTENT_SETTING_BLOCK); 353 CONTENT_SETTING_BLOCK);
369 } 354 }
370 355
371 void DesktopNotificationService::Observe(
372 int type,
373 const content::NotificationSource& source,
374 const content::NotificationDetails& details) {
375 // This may get called during shutdown, so don't use GetUIManager() here,
376 // and don't do anything if ui_manager_ hasn't already been set.
377 if (!ui_manager_)
378 return;
379
380 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
381 // Remove all notifications currently shown or queued by the extension
382 // which was unloaded.
383 const extensions::Extension* extension =
384 content::Details<extensions::UnloadedExtensionInfo>(details)->extension;
385 if (extension &&
386 g_browser_process && g_browser_process->notification_ui_manager()) {
387 g_browser_process->notification_ui_manager()->
388 CancelAllBySourceOrigin(extension->url());
389 }
390 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) {
391 if (g_browser_process && g_browser_process->notification_ui_manager()) {
392 g_browser_process->notification_ui_manager()->
393 CancelAllByProfile(profile_);
394 }
395 StopObserving();
396 }
397 }
398
399 ContentSetting DesktopNotificationService::GetDefaultContentSetting( 356 ContentSetting DesktopNotificationService::GetDefaultContentSetting(
400 std::string* provider_id) { 357 std::string* provider_id) {
401 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( 358 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
402 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, provider_id); 359 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, provider_id);
403 } 360 }
404 361
405 void DesktopNotificationService::SetDefaultContentSetting( 362 void DesktopNotificationService::SetDefaultContentSetting(
406 ContentSetting setting) { 363 ContentSetting setting) {
407 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( 364 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
408 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); 365 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 559
603 if (setting == CONTENT_SETTING_ALLOW) 560 if (setting == CONTENT_SETTING_ALLOW)
604 return WebKit::WebNotificationPresenter::PermissionAllowed; 561 return WebKit::WebNotificationPresenter::PermissionAllowed;
605 if (setting == CONTENT_SETTING_BLOCK) 562 if (setting == CONTENT_SETTING_BLOCK)
606 return WebKit::WebNotificationPresenter::PermissionDenied; 563 return WebKit::WebNotificationPresenter::PermissionDenied;
607 if (setting == CONTENT_SETTING_ASK) 564 if (setting == CONTENT_SETTING_ASK)
608 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 565 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
609 NOTREACHED() << "Invalid notifications settings value: " << setting; 566 NOTREACHED() << "Invalid notifications settings value: " << setting;
610 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 567 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
611 } 568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698