Chromium Code Reviews| Index: chrome/browser/notifications/desktop_notification_service.cc |
| =================================================================== |
| --- chrome/browser/notifications/desktop_notification_service.cc (revision 33305) |
| +++ chrome/browser/notifications/desktop_notification_service.cc (working copy) |
| @@ -205,16 +205,18 @@ |
| // create the preferences if they don't exist yet. |
| void DesktopNotificationService::InitPrefs() { |
| PrefService* prefs = profile_->GetPrefs(); |
| - const ListValue* allowed_sites; |
| - const ListValue* denied_sites; |
| + const ListValue* allowed_sites = NULL; |
| + const ListValue* denied_sites = NULL; |
| - if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) |
| - prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); |
| - allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
| + if (!profile_->IsOffTheRecord()) { |
| + if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) |
| + prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); |
| + allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
| - if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) |
| - prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); |
| - denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); |
| + if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) |
| + prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); |
| + denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); |
| + } |
| prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites); |
| @@ -246,18 +248,10 @@ |
| void DesktopNotificationService::GrantPermission(const GURL& origin) { |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| - PrefService* prefs = profile_->GetPrefs(); |
| - ListValue* allowed_sites = |
| - prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); |
| - ListValue* denied_sites = |
| - prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); |
| - // Remove from the black-list and add to the white-list. |
| - StringValue* value = new StringValue(origin.spec()); |
| - denied_sites->Remove(*value); |
| - allowed_sites->Append(value); |
| - prefs->ScheduleSavePersistentPrefs(); |
| - // Schedule a cache update on the IO thread. |
| + if (!profile_->IsOffTheRecord()) |
| + PersistPermissionChange(origin, true); |
| + |
| ChromeThread::PostTask( |
| ChromeThread::IO, FROM_HERE, |
| NewRunnableMethod( |
| @@ -267,17 +261,10 @@ |
| void DesktopNotificationService::DenyPermission(const GURL& origin) { |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| - PrefService* prefs = profile_->GetPrefs(); |
| - ListValue* allowed_sites = |
| - prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); |
| - ListValue* denied_sites = |
| - prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); |
| - StringValue* value = new StringValue(origin.spec()); |
| - // Remove from the white-list and add to the black-list. |
| - allowed_sites->Remove(*value); |
| - denied_sites->Append(value); |
| - prefs->ScheduleSavePersistentPrefs(); |
| + if (!profile_->IsOffTheRecord()) |
| + PersistPermissionChange(origin, false); |
| + |
| // Schedule a cache update on the IO thread. |
| ChromeThread::PostTask( |
| ChromeThread::IO, FROM_HERE, |
| @@ -286,6 +273,25 @@ |
| origin)); |
| } |
| +void DesktopNotificationService::PersistPermissionChange( |
| + const GURL& origin, bool is_allowed) { |
|
michaeln
2009/12/01 00:00:07
maybe DCHECK(!profile_->IsOffTheRecord()), or push
|
| + PrefService* prefs = profile_->GetPrefs(); |
| + ListValue* allowed_sites = |
| + prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); |
| + ListValue* denied_sites = |
| + prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); |
| + StringValue* value = new StringValue(origin.spec()); |
| + // Remove from one list and add to the other. |
| + if (is_allowed) { |
| + allowed_sites->Append(value); |
| + denied_sites->Remove(*value); |
| + } else { |
| + allowed_sites->Remove(*value); |
| + denied_sites->Append(value); |
| + } |
| + prefs->ScheduleSavePersistentPrefs(); |
| +} |
| + |
| void DesktopNotificationService::RequestPermission( |
| const GURL& origin, int process_id, int route_id, int callback_context) { |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |