summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 00:33:24 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 00:33:24 +0000
commit42a1c17896d599a86112bcecffe71df27434611c (patch)
tree9913457741114b2cfa49dcdffabef09546603b8b /chrome/browser/notifications
parentba31e56dc1ef1f29ddd890df9943dffac7853477 (diff)
downloadchromium_src-42a1c17896d599a86112bcecffe71df27434611c.zip
chromium_src-42a1c17896d599a86112bcecffe71df27434611c.tar.gz
chromium_src-42a1c17896d599a86112bcecffe71df27434611c.tar.bz2
This DCHECK occurs when an installed extension that declares the notification permission is loaded.
Review URL: http://codereview.chromium.org/842002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41368 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc2
-rw-r--r--chrome/browser/notifications/notifications_prefs_cache.cc19
-rw-r--r--chrome/browser/notifications/notifications_prefs_cache.h14
3 files changed, 28 insertions, 7 deletions
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 8096379..55613f5 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -240,6 +240,8 @@ void DesktopNotificationService::InitPrefs() {
}
}
}
+
+ prefs_cache_->set_is_initialized(true);
}
void DesktopNotificationService::Observe(NotificationType type,
diff --git a/chrome/browser/notifications/notifications_prefs_cache.cc b/chrome/browser/notifications/notifications_prefs_cache.cc
index 67edeb6..b127282 100644
--- a/chrome/browser/notifications/notifications_prefs_cache.cc
+++ b/chrome/browser/notifications/notifications_prefs_cache.cc
@@ -11,7 +11,8 @@
#include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
NotificationsPrefsCache::NotificationsPrefsCache(
- const ListValue* allowed, const ListValue* denied) {
+ const ListValue* allowed, const ListValue* denied)
+ : is_initialized_(false) {
ListValue::const_iterator i;
std::wstring origin;
if (allowed) {
@@ -30,7 +31,7 @@ NotificationsPrefsCache::NotificationsPrefsCache(
void NotificationsPrefsCache::CacheAllowedOrigin(
const GURL& origin) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ CheckThreadAccess();
std::set<GURL>::iterator iter;
allowed_origins_.insert(origin);
if ((iter = denied_origins_.find(origin)) != denied_origins_.end())
@@ -39,7 +40,7 @@ void NotificationsPrefsCache::CacheAllowedOrigin(
void NotificationsPrefsCache::CacheDeniedOrigin(
const GURL& origin) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ CheckThreadAccess();
std::set<GURL>::iterator iter;
denied_origins_.insert(origin);
if ((iter = allowed_origins_.find(origin)) != allowed_origins_.end())
@@ -56,12 +57,20 @@ int NotificationsPrefsCache::HasPermission(const GURL& origin) {
bool NotificationsPrefsCache::IsOriginAllowed(
const GURL& origin) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ CheckThreadAccess();
return (allowed_origins_.find(origin) != allowed_origins_.end());
}
bool NotificationsPrefsCache::IsOriginDenied(
const GURL& origin) {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ CheckThreadAccess();
return (denied_origins_.find(origin) != denied_origins_.end());
}
+
+void NotificationsPrefsCache::CheckThreadAccess() {
+ if (is_initialized_) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ } else {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ }
+}
diff --git a/chrome/browser/notifications/notifications_prefs_cache.h b/chrome/browser/notifications/notifications_prefs_cache.h
index f153e02..de00774 100644
--- a/chrome/browser/notifications/notifications_prefs_cache.h
+++ b/chrome/browser/notifications/notifications_prefs_cache.h
@@ -14,13 +14,16 @@ class ListValue;
// Class which caches notification preferences.
// Construction occurs on the UI thread when the contents
-// of the profile preferences are initially cached. Once constructed
-// this class should only be accessed on the IO thread.
+// of the profile preferences are initialized. Once is_initialized() is set,
+// access can only be done from the IO thread.
class NotificationsPrefsCache
: public base::RefCountedThreadSafe<NotificationsPrefsCache> {
public:
NotificationsPrefsCache(const ListValue* allowed, const ListValue* denied);
+ void set_is_initialized(bool val) { is_initialized_ = val; }
+ bool is_initialized() { return is_initialized_; }
+
// Checks to see if a given origin has permission to create desktop
// notifications. Returns a constant from WebNotificationPresenter
// class.
@@ -39,10 +42,17 @@ class NotificationsPrefsCache
bool IsOriginAllowed(const GURL& origin);
bool IsOriginDenied(const GURL& origin);
+ // Helper that ensures we are running on the expected thread.
+ void CheckThreadAccess();
+
// Storage of the actual preferences.
std::set<GURL> allowed_origins_;
std::set<GURL> denied_origins_;
+ // Set to true once the initial cached settings have been completely read.
+ // Once this is done, the class can no longer be accessed on the UI thread.
+ bool is_initialized_;
+
DISALLOW_COPY_AND_ASSIGN(NotificationsPrefsCache);
};