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

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

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
« no previous file with comments | « chrome/browser/notifications/notifications_prefs_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/notifications/notifications_prefs_cache.h" 5 #include "chrome/browser/notifications/notifications_prefs_cache.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/pref_service.h" 10 #include "chrome/browser/pref_service.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
12 12
13 NotificationsPrefsCache::NotificationsPrefsCache( 13 NotificationsPrefsCache::NotificationsPrefsCache()
14 const ListValue* allowed, const ListValue* denied)
15 : is_initialized_(false) { 14 : is_initialized_(false) {
16 ListValue::const_iterator i;
17 std::wstring origin;
18 if (allowed) {
19 for (i = allowed->begin(); i != allowed->end(); ++i) {
20 (*i)->GetAsString(&origin);
21 allowed_origins_.insert(GURL(WideToUTF8(origin)));
22 }
23 }
24 if (denied) {
25 for (i = denied->begin(); i != denied->end(); ++i) {
26 (*i)->GetAsString(&origin);
27 denied_origins_.insert(GURL(WideToUTF8(origin)));
28 }
29 }
30 } 15 }
31 16
32 void NotificationsPrefsCache::CacheAllowedOrigin( 17 void NotificationsPrefsCache::CacheAllowedOrigin(
33 const GURL& origin) { 18 const GURL& origin) {
34 CheckThreadAccess(); 19 CheckThreadAccess();
35 std::set<GURL>::iterator iter; 20 std::set<GURL>::iterator iter;
36 allowed_origins_.insert(origin); 21 allowed_origins_.insert(origin);
37 if ((iter = denied_origins_.find(origin)) != denied_origins_.end()) 22 if ((iter = denied_origins_.find(origin)) != denied_origins_.end())
38 denied_origins_.erase(iter); 23 denied_origins_.erase(iter);
39 } 24 }
40 25
41 void NotificationsPrefsCache::CacheDeniedOrigin( 26 void NotificationsPrefsCache::CacheDeniedOrigin(
42 const GURL& origin) { 27 const GURL& origin) {
43 CheckThreadAccess(); 28 CheckThreadAccess();
44 std::set<GURL>::iterator iter; 29 std::set<GURL>::iterator iter;
45 denied_origins_.insert(origin); 30 denied_origins_.insert(origin);
46 if ((iter = allowed_origins_.find(origin)) != allowed_origins_.end()) 31 if ((iter = allowed_origins_.find(origin)) != allowed_origins_.end())
47 allowed_origins_.erase(iter); 32 allowed_origins_.erase(iter);
48 } 33 }
49 34
35 void NotificationsPrefsCache::SetCacheAllowedOrigins(
36 const std::vector<GURL>& allowed) {
37 allowed_origins_.clear();
38 allowed_origins_.insert(allowed.begin(), allowed.end());
39 }
40
41 void NotificationsPrefsCache::SetCacheDeniedOrigins(
42 const std::vector<GURL>& denied) {
43 denied_origins_.clear();
44 denied_origins_.insert(denied.begin(), denied.end());
45 }
46
47 // static
48 void NotificationsPrefsCache::ListValueToGurlVector(
49 const ListValue& origin_list,
50 std::vector<GURL>* origin_vector) {
51 ListValue::const_iterator i;
52 std::wstring origin;
53 for (i = origin_list.begin(); i != origin_list.end(); ++i) {
54 (*i)->GetAsString(&origin);
55 origin_vector->push_back(GURL(WideToUTF8(origin)));
56 }
57 }
58
50 int NotificationsPrefsCache::HasPermission(const GURL& origin) { 59 int NotificationsPrefsCache::HasPermission(const GURL& origin) {
51 if (IsOriginAllowed(origin)) 60 if (IsOriginAllowed(origin))
52 return WebKit::WebNotificationPresenter::PermissionAllowed; 61 return WebKit::WebNotificationPresenter::PermissionAllowed;
53 if (IsOriginDenied(origin)) 62 if (IsOriginDenied(origin))
54 return WebKit::WebNotificationPresenter::PermissionDenied; 63 return WebKit::WebNotificationPresenter::PermissionDenied;
55 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 64 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
56 } 65 }
57 66
58 bool NotificationsPrefsCache::IsOriginAllowed( 67 bool NotificationsPrefsCache::IsOriginAllowed(
59 const GURL& origin) { 68 const GURL& origin) {
60 CheckThreadAccess(); 69 CheckThreadAccess();
61 return (allowed_origins_.find(origin) != allowed_origins_.end()); 70 return (allowed_origins_.find(origin) != allowed_origins_.end());
62 } 71 }
63 72
64 bool NotificationsPrefsCache::IsOriginDenied( 73 bool NotificationsPrefsCache::IsOriginDenied(
65 const GURL& origin) { 74 const GURL& origin) {
66 CheckThreadAccess(); 75 CheckThreadAccess();
67 return (denied_origins_.find(origin) != denied_origins_.end()); 76 return (denied_origins_.find(origin) != denied_origins_.end());
68 } 77 }
69 78
70 void NotificationsPrefsCache::CheckThreadAccess() { 79 void NotificationsPrefsCache::CheckThreadAccess() {
71 if (is_initialized_) { 80 if (is_initialized_) {
72 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 81 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
73 } else { 82 } else {
74 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 83 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
75 } 84 }
76 } 85 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notifications_prefs_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698