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

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

Issue 7655019: Migrate Obsolete NotificationsSettings and remove content_settings::NotificationsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_
7 #pragma once
8
9 #include <set>
10 #include <vector>
11
12 #include "base/memory/ref_counted.h"
13 #include "chrome/common/content_settings.h"
14 #include "googleurl/src/gurl.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresen ter.h"
16
17 namespace base {
18 class ListValue;
19 }
20
21 // Class which caches notification preferences.
22 // Construction occurs on the UI thread when the contents
23 // of the profile preferences are initialized. Once is_initialized() is set,
24 // access can only be done from the IO thread.
25 class NotificationsPrefsCache
26 : public base::RefCountedThreadSafe<NotificationsPrefsCache> {
27 public:
28 NotificationsPrefsCache();
29
30 // Once is_initialized() is set, all accesses must happen on the IO thread.
31 // Before that, all accesses need to happen on the UI thread.
32 void set_is_initialized(bool val) { is_initialized_ = val; }
33 bool is_initialized() { return is_initialized_; }
34
35 // Checks to see if a given origin has permission to create desktop
36 // notifications.
37 WebKit::WebNotificationPresenter::Permission
38 HasPermission(const GURL& origin);
39
40 // Updates the cache with a new origin allowed or denied.
41 void CacheAllowedOrigin(const GURL& origin);
42 void CacheDeniedOrigin(const GURL& origin);
43
44 // Set the cache to the supplied values. This clears the current
45 // contents of the cache.
46 void SetCacheAllowedOrigins(const std::vector<GURL>& allowed);
47 void SetCacheDeniedOrigins(const std::vector<GURL>& denied);
48 void SetCacheDefaultContentSetting(ContentSetting setting);
49
50 static void ListValueToGurlVector(const base::ListValue& origin_list,
51 std::vector<GURL>* origin_vector);
52
53 // Exposed for testing.
54 ContentSetting CachedDefaultContentSetting() {
55 return default_content_setting_;
56 }
57
58 private:
59 friend class base::RefCountedThreadSafe<NotificationsPrefsCache>;
60
61 virtual ~NotificationsPrefsCache();
62
63 // Helper functions which read preferences.
64 bool IsOriginAllowed(const GURL& origin);
65 bool IsOriginDenied(const GURL& origin);
66
67 // Helper that ensures we are running on the expected thread.
68 void CheckThreadAccess();
69
70 // Storage of the actual preferences.
71 std::set<GURL> allowed_origins_;
72 std::set<GURL> denied_origins_;
73
74 // The default setting, used for origins that are neither in
75 // |allowed_origins_| nor |denied_origins_|.
76 ContentSetting default_content_setting_;
77
78 // Set to true once the initial cached settings have been completely read.
79 // Once this is done, the class can no longer be accessed on the UI thread.
80 bool is_initialized_;
81
82 DISALLOW_COPY_AND_ASSIGN(NotificationsPrefsCache);
83 };
84
85 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATIONS_PREFS_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698