OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ |
6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ |
7 | 7 |
8 | 8 |
9 #include "extensions/common/permissions/api_permission.h" | 9 #include "extensions/common/permissions/api_permission.h" |
10 #include "extensions/common/permissions/base_set_operators.h" | 10 #include "extensions/common/permissions/base_set_operators.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // p.insertPermission(APIPermission::kHostReadOnly, | 104 // p.insertPermission(APIPermission::kHostReadOnly, |
105 // base::ASCIIToUTF16("http://www.google.com")); | 105 // base::ASCIIToUTF16("http://www.google.com")); |
106 // | 106 // |
107 // TODO(sashab): Move this to its own file and rename it to PermissionSet after | 107 // TODO(sashab): Move this to its own file and rename it to PermissionSet after |
108 // APIPermission is removed, the current PermissionSet is no longer used, and | 108 // APIPermission is removed, the current PermissionSet is no longer used, and |
109 // APIPermission::ID is the only type of Permission ID. | 109 // APIPermission::ID is the only type of Permission ID. |
110 // TODO(sashab): Change BaseSetOperators to support storing plain objects | 110 // TODO(sashab): Change BaseSetOperators to support storing plain objects |
111 // instead of pointers and change this to extend BaseSetOperators<PermissionID>. | 111 // instead of pointers and change this to extend BaseSetOperators<PermissionID>. |
112 class PermissionIDSet { | 112 class PermissionIDSet { |
113 public: | 113 public: |
| 114 using const_iterator = std::set<PermissionID>::const_iterator; |
| 115 |
114 PermissionIDSet(); | 116 PermissionIDSet(); |
115 virtual ~PermissionIDSet(); | 117 virtual ~PermissionIDSet(); |
116 | 118 |
117 // Adds the given permission, and an optional parameter, to the set. | 119 // Adds the given permission, and an optional parameter, to the set. |
118 void insert(APIPermission::ID permission_id); | 120 void insert(APIPermission::ID permission_id); |
119 void insert(APIPermission::ID permission_id, | 121 void insert(APIPermission::ID permission_id, |
120 base::string16 permission_parameter); | 122 base::string16 permission_parameter); |
121 void InsertAll(const PermissionIDSet& permission_set); | 123 void InsertAll(const PermissionIDSet& permission_set); |
122 | 124 |
123 // Returns the parameters for all PermissionIDs in this set. | 125 // Returns the parameters for all PermissionIDs in this set. |
124 std::vector<base::string16> GetAllPermissionParameters() const; | 126 std::vector<base::string16> GetAllPermissionParameters() const; |
125 | 127 |
126 // Check if the set contains permissions with all the given IDs. | 128 // Check if the set contains permissions with all the given IDs. |
127 bool ContainsAllIDs(std::set<APIPermission::ID> permission_ids); | 129 bool ContainsAllIDs(std::set<APIPermission::ID> permission_ids); |
128 | 130 |
129 // Returns all the permissions in this set with one of the given IDs. | 131 // Returns all the permissions in this set with one of the given IDs. |
130 PermissionIDSet GetAllPermissionsWithIDs( | 132 PermissionIDSet GetAllPermissionsWithIDs( |
131 const std::set<APIPermission::ID>& permission_ids) const; | 133 const std::set<APIPermission::ID>& permission_ids) const; |
132 | 134 |
133 // Convenience functions that call their stl_util counterparts. | 135 // Convenience functions that call their stl_util counterparts. |
134 bool Includes(const PermissionIDSet& subset) const; | 136 bool Includes(const PermissionIDSet& subset) const; |
| 137 bool Equals(const PermissionIDSet& set) const; |
135 static PermissionIDSet Difference(const PermissionIDSet& set_1, | 138 static PermissionIDSet Difference(const PermissionIDSet& set_1, |
136 const PermissionIDSet& set_2); | 139 const PermissionIDSet& set_2); |
137 static PermissionIDSet Intersection(const PermissionIDSet& set_1, | 140 static PermissionIDSet Intersection(const PermissionIDSet& set_1, |
138 const PermissionIDSet& set_2); | 141 const PermissionIDSet& set_2); |
139 static PermissionIDSet Union(const PermissionIDSet& set_1, | 142 static PermissionIDSet Union(const PermissionIDSet& set_1, |
140 const PermissionIDSet& set_2); | 143 const PermissionIDSet& set_2); |
141 | 144 |
142 size_t size() const; | 145 size_t size() const; |
143 bool empty() const; | 146 bool empty() const; |
144 | 147 |
| 148 const_iterator begin() const { return permissions_.begin(); } |
| 149 const_iterator end() const { return permissions_.end(); } |
| 150 |
145 private: | 151 private: |
146 PermissionIDSet(std::set<PermissionID> permissions); | 152 PermissionIDSet(const std::set<PermissionID>& permissions); |
147 | 153 |
148 // Check if the set contains a permission with the given ID. | 154 // Check if the set contains a permission with the given ID. |
149 bool ContainsID(APIPermission::ID permission_id); | 155 bool ContainsID(APIPermission::ID permission_id); |
150 | 156 |
151 std::set<PermissionID> permissions_; | 157 std::set<PermissionID> permissions_; |
152 }; | 158 }; |
153 | 159 |
154 } // namespace extensions | 160 } // namespace extensions |
155 | 161 |
156 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ | 162 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_ |
OLD | NEW |