OLD | NEW |
---|---|
(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 const_iterator(const const_iterator& ids_it) : it_(ids_it.it_) {} | |
28 const_iterator& operator++() { | |
miket_OOO
2012/07/31 18:18:37
the vertical whitespace here is inconsistent. If y
Peng
2012/07/31 19:32:28
Done.
| |
29 it_++; | |
30 return *this; | |
31 } | |
32 | |
33 const_iterator operator++(int) { | |
34 const_iterator tmp(*this); | |
35 operator++(); | |
36 return tmp; | |
37 } | |
38 | |
39 bool operator==(const const_iterator& rhs) const { | |
40 return it_ == rhs.it_; | |
41 } | |
42 | |
43 bool operator!=(const const_iterator& rhs) const { | |
44 return it_ != rhs.it_; | |
45 } | |
46 | |
47 const scoped_refptr<APIPermissionDetail>& operator*() const { | |
48 return it_->second; | |
49 } | |
50 | |
51 const scoped_refptr<APIPermissionDetail>& operator->() const { | |
52 return it_->second; | |
53 } | |
54 | |
55 private: | |
56 APIPermissionMap::const_iterator it_; | |
57 }; | |
58 | |
59 const_iterator begin() const { | |
60 return const_iterator(map().begin()); | |
61 } | |
62 | |
63 const_iterator end() const { | |
64 return map().end(); | |
65 } | |
66 | |
67 const_iterator find(APIPermission::ID id) const { | |
68 return map().find(id); | |
69 } | |
70 | |
71 const APIPermissionMap& map() const { | |
72 return map_; | |
73 } | |
74 | |
75 APIPermissionMap& map() { | |
76 return map_; | |
77 } | |
78 | |
79 void clear() { | |
80 map_.clear(); | |
81 } | |
82 | |
83 size_t count(APIPermission::ID id) const { | |
84 return map().count(id); | |
85 } | |
86 | |
87 bool empty() const { | |
88 return map().empty(); | |
89 } | |
90 | |
91 size_t erase(APIPermission::ID id) { | |
92 return map().erase(id); | |
93 } | |
94 | |
95 size_t size() const { | |
96 return map().size(); | |
97 } | |
98 | |
99 bool operator==(const APIPermissionSet& rhs) const; | |
100 | |
101 bool operator!=(const APIPermissionSet& rhs) const { | |
102 return !operator==(rhs); | |
103 } | |
104 | |
105 void insert(APIPermission::ID id); | |
106 void insert(const scoped_refptr<APIPermissionDetail>& detail); | |
107 | |
108 static void Difference( | |
109 const APIPermissionSet& set1, | |
110 const APIPermissionSet& set2, | |
111 APIPermissionSet* set3); | |
112 | |
113 static void Intersection( | |
114 const APIPermissionSet& set1, | |
115 const APIPermissionSet& set2, | |
116 APIPermissionSet* set3); | |
117 | |
118 static void Union( | |
119 const APIPermissionSet& set1, | |
120 const APIPermissionSet& set2, | |
121 APIPermissionSet* set3); | |
122 | |
123 private: | |
124 APIPermissionMap map_; | |
125 }; | |
126 | |
127 } // namespace extensions | |
128 | |
129 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_SET_H_ | |
OLD | NEW |