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

Side by Side Diff: chrome/browser/notifications/notifications_prefs_cache.h

Issue 1578023: Add notifications to allow desktop notification permissions to be synced. (Closed)
Patch Set: pre-commit Created 10 years, 8 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 10
10 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
12 13
13 class ListValue; 14 class ListValue;
14 15
15 // Class which caches notification preferences. 16 // Class which caches notification preferences.
16 // Construction occurs on the UI thread when the contents 17 // Construction occurs on the UI thread when the contents
17 // of the profile preferences are initialized. Once is_initialized() is set, 18 // of the profile preferences are initialized. Once is_initialized() is set,
18 // access can only be done from the IO thread. 19 // access can only be done from the IO thread.
19 class NotificationsPrefsCache 20 class NotificationsPrefsCache
20 : public base::RefCountedThreadSafe<NotificationsPrefsCache> { 21 : public base::RefCountedThreadSafe<NotificationsPrefsCache> {
21 public: 22 public:
22 NotificationsPrefsCache(const ListValue* allowed, const ListValue* denied); 23 NotificationsPrefsCache();
23 24
24 void set_is_initialized(bool val) { is_initialized_ = val; } 25 void set_is_initialized(bool val) { is_initialized_ = val; }
25 bool is_initialized() { return is_initialized_; } 26 bool is_initialized() { return is_initialized_; }
26 27
27 // Checks to see if a given origin has permission to create desktop 28 // Checks to see if a given origin has permission to create desktop
28 // notifications. Returns a constant from WebNotificationPresenter 29 // notifications. Returns a constant from WebNotificationPresenter
29 // class. 30 // class.
30 int HasPermission(const GURL& origin); 31 int HasPermission(const GURL& origin);
31 32
32 // Updates the cache with a new origin allowed or denied. 33 // Updates the cache with a new origin allowed or denied.
33 void CacheAllowedOrigin(const GURL& origin); 34 void CacheAllowedOrigin(const GURL& origin);
34 void CacheDeniedOrigin(const GURL& origin); 35 void CacheDeniedOrigin(const GURL& origin);
35 36
37 // Set the cache to the supplied values. This clears the current
38 // contents of the cache.
39 void SetCacheAllowedOrigins(const std::vector<GURL>& allowed);
40 void SetCacheDeniedOrigins(const std::vector<GURL>& denied);
41
42 static void ListValueToGurlVector(const ListValue& origin_list,
43 std::vector<GURL>* origin_vector);
44
36 private: 45 private:
37 friend class base::RefCountedThreadSafe<NotificationsPrefsCache>; 46 friend class base::RefCountedThreadSafe<NotificationsPrefsCache>;
38 47
39 ~NotificationsPrefsCache() {} 48 ~NotificationsPrefsCache() {}
40 49
41 // Helper functions which read preferences. 50 // Helper functions which read preferences.
42 bool IsOriginAllowed(const GURL& origin); 51 bool IsOriginAllowed(const GURL& origin);
43 bool IsOriginDenied(const GURL& origin); 52 bool IsOriginDenied(const GURL& origin);
44 53
45 // Helper that ensures we are running on the expected thread. 54 // Helper that ensures we are running on the expected thread.
46 void CheckThreadAccess(); 55 void CheckThreadAccess();
47 56
48 // Storage of the actual preferences. 57 // Storage of the actual preferences.
49 std::set<GURL> allowed_origins_; 58 std::set<GURL> allowed_origins_;
50 std::set<GURL> denied_origins_; 59 std::set<GURL> denied_origins_;
51 60
52 // Set to true once the initial cached settings have been completely read. 61 // Set to true once the initial cached settings have been completely read.
53 // Once this is done, the class can no longer be accessed on the UI thread. 62 // Once this is done, the class can no longer be accessed on the UI thread.
54 bool is_initialized_; 63 bool is_initialized_;
55 64
56 DISALLOW_COPY_AND_ASSIGN(NotificationsPrefsCache); 65 DISALLOW_COPY_AND_ASSIGN(NotificationsPrefsCache);
57 }; 66 };
58 67
59 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_ 68 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698