Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "chrome/common/content_settings.h" | |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 | 14 |
| 14 class ListValue; | 15 class ListValue; |
| 15 | 16 |
| 16 // Class which caches notification preferences. | 17 // Class which caches notification preferences. |
| 17 // Construction occurs on the UI thread when the contents | 18 // Construction occurs on the UI thread when the contents |
| 18 // of the profile preferences are initialized. Once is_initialized() is set, | 19 // of the profile preferences are initialized. Once is_initialized() is set, |
| 19 // access can only be done from the IO thread. | 20 // access can only be done from the IO thread. |
| 20 class NotificationsPrefsCache | 21 class NotificationsPrefsCache |
| 21 : public base::RefCountedThreadSafe<NotificationsPrefsCache> { | 22 : public base::RefCountedThreadSafe<NotificationsPrefsCache> { |
| 22 public: | 23 public: |
| 23 NotificationsPrefsCache(); | 24 NotificationsPrefsCache(); |
| 24 | 25 |
| 26 // Once is_initialized_() is set, all accesses must happen on the IO thread. | |
|
bulach
2010/07/05 09:54:54
s/is_initialized_()/is_initialized()/
Nico
2010/07/05 15:50:14
Done.
| |
| 27 // Before that, all accesses need to happen on the UI thread. | |
| 25 void set_is_initialized(bool val) { is_initialized_ = val; } | 28 void set_is_initialized(bool val) { is_initialized_ = val; } |
| 26 bool is_initialized() { return is_initialized_; } | 29 bool is_initialized() { return is_initialized_; } |
| 27 | 30 |
| 28 // Checks to see if a given origin has permission to create desktop | 31 // Checks to see if a given origin has permission to create desktop |
| 29 // notifications. Returns a constant from WebNotificationPresenter | 32 // notifications. Returns a constant from WebNotificationPresenter |
| 30 // class. | 33 // class. |
| 31 int HasPermission(const GURL& origin); | 34 int HasPermission(const GURL& origin); |
| 32 | 35 |
| 33 // Updates the cache with a new origin allowed or denied. | 36 // Updates the cache with a new origin allowed or denied. |
| 34 void CacheAllowedOrigin(const GURL& origin); | 37 void CacheAllowedOrigin(const GURL& origin); |
| 35 void CacheDeniedOrigin(const GURL& origin); | 38 void CacheDeniedOrigin(const GURL& origin); |
| 36 | 39 |
| 37 // Set the cache to the supplied values. This clears the current | 40 // Set the cache to the supplied values. This clears the current |
| 38 // contents of the cache. | 41 // contents of the cache. |
| 39 void SetCacheAllowedOrigins(const std::vector<GURL>& allowed); | 42 void SetCacheAllowedOrigins(const std::vector<GURL>& allowed); |
| 40 void SetCacheDeniedOrigins(const std::vector<GURL>& denied); | 43 void SetCacheDeniedOrigins(const std::vector<GURL>& denied); |
| 44 void SetCacheDefaultContentSetting(ContentSetting setting); | |
| 41 | 45 |
| 42 static void ListValueToGurlVector(const ListValue& origin_list, | 46 static void ListValueToGurlVector(const ListValue& origin_list, |
| 43 std::vector<GURL>* origin_vector); | 47 std::vector<GURL>* origin_vector); |
| 44 | 48 |
| 49 // Exposed for testing. | |
| 50 ContentSetting CachedDefaultContentSetting() { | |
| 51 return default_content_setting_; | |
| 52 } | |
| 53 | |
| 45 private: | 54 private: |
| 46 friend class base::RefCountedThreadSafe<NotificationsPrefsCache>; | 55 friend class base::RefCountedThreadSafe<NotificationsPrefsCache>; |
| 47 | 56 |
| 48 ~NotificationsPrefsCache() {} | 57 ~NotificationsPrefsCache() {} |
| 49 | 58 |
| 50 // Helper functions which read preferences. | 59 // Helper functions which read preferences. |
| 51 bool IsOriginAllowed(const GURL& origin); | 60 bool IsOriginAllowed(const GURL& origin); |
| 52 bool IsOriginDenied(const GURL& origin); | 61 bool IsOriginDenied(const GURL& origin); |
| 53 | 62 |
| 54 // Helper that ensures we are running on the expected thread. | 63 // Helper that ensures we are running on the expected thread. |
| 55 void CheckThreadAccess(); | 64 void CheckThreadAccess(); |
| 56 | 65 |
| 57 // Storage of the actual preferences. | 66 // Storage of the actual preferences. |
| 58 std::set<GURL> allowed_origins_; | 67 std::set<GURL> allowed_origins_; |
| 59 std::set<GURL> denied_origins_; | 68 std::set<GURL> denied_origins_; |
| 60 | 69 |
| 70 // The default setting, used for origins that are neither in | |
| 71 // |allowed_origins_| nor |denied_origins_|. | |
| 72 ContentSetting default_content_setting_; | |
| 73 | |
| 61 // Set to true once the initial cached settings have been completely read. | 74 // Set to true once the initial cached settings have been completely read. |
| 62 // Once this is done, the class can no longer be accessed on the UI thread. | 75 // Once this is done, the class can no longer be accessed on the UI thread. |
| 63 bool is_initialized_; | 76 bool is_initialized_; |
| 64 | 77 |
| 65 DISALLOW_COPY_AND_ASSIGN(NotificationsPrefsCache); | 78 DISALLOW_COPY_AND_ASSIGN(NotificationsPrefsCache); |
| 66 }; | 79 }; |
| 67 | 80 |
| 68 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ | 81 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ |
| OLD | NEW |