summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications
diff options
context:
space:
mode:
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);
};