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

Unified Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 455004: Keep incognito notification preferences separate from regular ones, and don't... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service.h ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service.h ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698