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

Side by Side Diff: chrome/common/extensions/permissions/api_permission_set.h

Issue 10692160: Support socket endpoint permissions for AppsV2 Socket API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix review issues Created 8 years, 4 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
(Empty)
1 // Copyright (c) 2012 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_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_SET_H_
7
8 #include <iterator>
9 #include <map>
10
11 #include "chrome/common/extensions/permissions/api_permission.h"
12
13 namespace extensions {
14
15 typedef std::map<APIPermission::ID,
16 scoped_refptr<APIPermissionDetail> > APIPermissionMap;
17
18 class APIPermissionSet {
19 public:
20 class const_iterator :
21 public std::iterator<
22 std::input_iterator_tag,
23 scoped_refptr<APIPermissionDetail> > {
24 public:
25 const_iterator(const APIPermissionMap::const_iterator& it)
26 : it_(it) {}
27
28 const_iterator(const const_iterator& ids_it) : it_(ids_it.it_) {}
29
30 const_iterator& operator++() {
31 it_++;
32 return *this;
33 }
34
35 const_iterator operator++(int) {
36 const_iterator tmp(*this);
37 operator++();
38 return tmp;
39 }
40
41 bool operator==(const const_iterator& rhs) const {
42 return it_ == rhs.it_;
43 }
44
45 bool operator!=(const const_iterator& rhs) const {
46 return it_ != rhs.it_;
47 }
48
49 const scoped_refptr<APIPermissionDetail>& operator*() const {
50 return it_->second;
51 }
52
53 const scoped_refptr<APIPermissionDetail>& operator->() const {
54 return it_->second;
55 }
56
57 private:
58 APIPermissionMap::const_iterator it_;
59 };
60
61 APIPermissionSet();
62
63 ~APIPermissionSet();
64
65 const_iterator begin() const {
66 return const_iterator(map().begin());
67 }
68
69 const_iterator end() const {
70 return map().end();
71 }
72
73 const_iterator find(APIPermission::ID id) const {
74 return map().find(id);
75 }
76
77 const APIPermissionMap& map() const {
78 return map_;
79 }
80
81 APIPermissionMap& map() {
82 return map_;
83 }
84
85 void clear() {
86 map_.clear();
87 }
88
89 size_t count(APIPermission::ID id) const {
90 return map().count(id);
91 }
92
93 bool empty() const {
94 return map().empty();
95 }
96
97 size_t erase(APIPermission::ID id) {
98 return map().erase(id);
99 }
100
101 size_t size() const {
102 return map().size();
103 }
104
105 bool operator==(const APIPermissionSet& rhs) const;
106
107 bool operator!=(const APIPermissionSet& rhs) const {
108 return !operator==(rhs);
109 }
110
111 void insert(APIPermission::ID id);
112 void insert(const scoped_refptr<APIPermissionDetail>& detail);
113
114 bool Contains(const APIPermissionSet& rhs) const;
115
116 static void Difference(
117 const APIPermissionSet& set1,
118 const APIPermissionSet& set2,
119 APIPermissionSet* set3);
120
121 static void Intersection(
122 const APIPermissionSet& set1,
123 const APIPermissionSet& set2,
124 APIPermissionSet* set3);
125
126 static void Union(
127 const APIPermissionSet& set1,
128 const APIPermissionSet& set2,
129 APIPermissionSet* set3);
130
131 private:
132 APIPermissionMap map_;
133 };
134
135 } // namespace extensions
136
137 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698