| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // Whether the user clicked one of the buttons. | 203 // Whether the user clicked one of the buttons. |
| 204 bool action_taken_; | 204 bool action_taken_; |
| 205 | 205 |
| 206 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate); | 206 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate); |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 DesktopNotificationService::DesktopNotificationService(Profile* profile, | 209 DesktopNotificationService::DesktopNotificationService(Profile* profile, |
| 210 NotificationUIManager* ui_manager) | 210 NotificationUIManager* ui_manager) |
| 211 : profile_(profile), | 211 : profile_(profile), |
| 212 ui_manager_(ui_manager) { | 212 ui_manager_(ui_manager) { |
| 213 registrar_.Init(profile_->GetPrefs()); |
| 213 InitPrefs(); | 214 InitPrefs(); |
| 214 StartObserving(); | 215 StartObserving(); |
| 215 } | 216 } |
| 216 | 217 |
| 217 DesktopNotificationService::~DesktopNotificationService() { | 218 DesktopNotificationService::~DesktopNotificationService() { |
| 218 StopObserving(); | 219 StopObserving(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) { | 222 void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) { |
| 222 if (!user_prefs->FindPreference( | 223 if (!user_prefs->FindPreference( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 247 | 248 |
| 248 prefs_cache_ = new NotificationsPrefsCache(); | 249 prefs_cache_ = new NotificationsPrefsCache(); |
| 249 prefs_cache_->SetCacheDefaultContentSetting(default_content_setting); | 250 prefs_cache_->SetCacheDefaultContentSetting(default_content_setting); |
| 250 prefs_cache_->SetCacheAllowedOrigins(allowed_origins); | 251 prefs_cache_->SetCacheAllowedOrigins(allowed_origins); |
| 251 prefs_cache_->SetCacheDeniedOrigins(denied_origins); | 252 prefs_cache_->SetCacheDeniedOrigins(denied_origins); |
| 252 prefs_cache_->set_is_initialized(true); | 253 prefs_cache_->set_is_initialized(true); |
| 253 } | 254 } |
| 254 | 255 |
| 255 void DesktopNotificationService::StartObserving() { | 256 void DesktopNotificationService::StartObserving() { |
| 256 if (!profile_->IsOffTheRecord()) { | 257 if (!profile_->IsOffTheRecord()) { |
| 257 PrefService* prefs = profile_->GetPrefs(); | 258 registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting, this); |
| 258 prefs->AddPrefObserver(prefs::kDesktopNotificationDefaultContentSetting, | 259 registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); |
| 259 this); | 260 registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); |
| 260 prefs->AddPrefObserver(prefs::kDesktopNotificationAllowedOrigins, this); | |
| 261 prefs->AddPrefObserver(prefs::kDesktopNotificationDeniedOrigins, this); | |
| 262 } | 261 } |
| 263 } | 262 } |
| 264 | 263 |
| 265 void DesktopNotificationService::StopObserving() { | 264 void DesktopNotificationService::StopObserving() { |
| 266 if (!profile_->IsOffTheRecord()) { | 265 if (!profile_->IsOffTheRecord()) { |
| 267 PrefService* prefs = profile_->GetPrefs(); | 266 registrar_.RemoveAll(); |
| 268 prefs->RemovePrefObserver(prefs::kDesktopNotificationDefaultContentSetting, | |
| 269 this); | |
| 270 prefs->RemovePrefObserver(prefs::kDesktopNotificationAllowedOrigins, this); | |
| 271 prefs->RemovePrefObserver(prefs::kDesktopNotificationDeniedOrigins, this); | |
| 272 } | 267 } |
| 273 } | 268 } |
| 274 | 269 |
| 275 void DesktopNotificationService::GrantPermission(const GURL& origin) { | 270 void DesktopNotificationService::GrantPermission(const GURL& origin) { |
| 276 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 271 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 277 PersistPermissionChange(origin, true); | 272 PersistPermissionChange(origin, true); |
| 278 | 273 |
| 279 // Schedule a cache update on the IO thread. | 274 // Schedule a cache update on the IO thread. |
| 280 ChromeThread::PostTask( | 275 ChromeThread::PostTask( |
| 281 ChromeThread::IO, FROM_HERE, | 276 ChromeThread::IO, FROM_HERE, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 581 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
| 587 ExtensionsService* ext_service = profile_->GetExtensionsService(); | 582 ExtensionsService* ext_service = profile_->GetExtensionsService(); |
| 588 if (ext_service) { | 583 if (ext_service) { |
| 589 Extension* extension = ext_service->GetExtensionByURL(origin); | 584 Extension* extension = ext_service->GetExtensionByURL(origin); |
| 590 if (extension) | 585 if (extension) |
| 591 return UTF8ToUTF16(extension->name()); | 586 return UTF8ToUTF16(extension->name()); |
| 592 } | 587 } |
| 593 } | 588 } |
| 594 return UTF8ToUTF16(origin.host()); | 589 return UTF8ToUTF16(origin.host()); |
| 595 } | 590 } |
| OLD | NEW |