| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SET_DISJUNCTION_PERMISSION_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| 6 #define EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // For an example of how to use this class, see SocketPermission. | 27 // For an example of how to use this class, see SocketPermission. |
| 28 template <class PermissionDataType, class DerivedType> | 28 template <class PermissionDataType, class DerivedType> |
| 29 class SetDisjunctionPermission : public APIPermission { | 29 class SetDisjunctionPermission : public APIPermission { |
| 30 public: | 30 public: |
| 31 explicit SetDisjunctionPermission(const APIPermissionInfo* info) | 31 explicit SetDisjunctionPermission(const APIPermissionInfo* info) |
| 32 : APIPermission(info) {} | 32 : APIPermission(info) {} |
| 33 | 33 |
| 34 ~SetDisjunctionPermission() {} | 34 ~SetDisjunctionPermission() {} |
| 35 | 35 |
| 36 // APIPermission overrides | 36 // APIPermission overrides |
| 37 virtual bool HasMessages() const OVERRIDE { return !data_set_.empty(); } | 37 virtual bool HasMessages() const override { return !data_set_.empty(); } |
| 38 | 38 |
| 39 virtual bool Check(const APIPermission::CheckParam* param) const OVERRIDE { | 39 virtual bool Check(const APIPermission::CheckParam* param) const override { |
| 40 for (typename std::set<PermissionDataType>::const_iterator i = | 40 for (typename std::set<PermissionDataType>::const_iterator i = |
| 41 data_set_.begin(); | 41 data_set_.begin(); |
| 42 i != data_set_.end(); | 42 i != data_set_.end(); |
| 43 ++i) { | 43 ++i) { |
| 44 if (i->Check(param)) | 44 if (i->Check(param)) |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual bool Contains(const APIPermission* rhs) const OVERRIDE { | 50 virtual bool Contains(const APIPermission* rhs) const override { |
| 51 CHECK(rhs->info() == info()); | 51 CHECK(rhs->info() == info()); |
| 52 const SetDisjunctionPermission* perm = | 52 const SetDisjunctionPermission* perm = |
| 53 static_cast<const SetDisjunctionPermission*>(rhs); | 53 static_cast<const SetDisjunctionPermission*>(rhs); |
| 54 return base::STLIncludes<std::set<PermissionDataType> >( | 54 return base::STLIncludes<std::set<PermissionDataType> >( |
| 55 data_set_, perm->data_set_); | 55 data_set_, perm->data_set_); |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual bool Equal(const APIPermission* rhs) const OVERRIDE { | 58 virtual bool Equal(const APIPermission* rhs) const override { |
| 59 CHECK(rhs->info() == info()); | 59 CHECK(rhs->info() == info()); |
| 60 const SetDisjunctionPermission* perm = | 60 const SetDisjunctionPermission* perm = |
| 61 static_cast<const SetDisjunctionPermission*>(rhs); | 61 static_cast<const SetDisjunctionPermission*>(rhs); |
| 62 return data_set_ == perm->data_set_; | 62 return data_set_ == perm->data_set_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual APIPermission* Clone() const OVERRIDE { | 65 virtual APIPermission* Clone() const override { |
| 66 SetDisjunctionPermission* result = new DerivedType(info()); | 66 SetDisjunctionPermission* result = new DerivedType(info()); |
| 67 result->data_set_ = data_set_; | 67 result->data_set_ = data_set_; |
| 68 return result; | 68 return result; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual APIPermission* Diff(const APIPermission* rhs) const OVERRIDE { | 71 virtual APIPermission* Diff(const APIPermission* rhs) const override { |
| 72 CHECK(rhs->info() == info()); | 72 CHECK(rhs->info() == info()); |
| 73 const SetDisjunctionPermission* perm = | 73 const SetDisjunctionPermission* perm = |
| 74 static_cast<const SetDisjunctionPermission*>(rhs); | 74 static_cast<const SetDisjunctionPermission*>(rhs); |
| 75 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); | 75 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); |
| 76 result->data_set_ = base::STLSetDifference<std::set<PermissionDataType> >( | 76 result->data_set_ = base::STLSetDifference<std::set<PermissionDataType> >( |
| 77 data_set_, perm->data_set_); | 77 data_set_, perm->data_set_); |
| 78 return result->data_set_.empty() ? NULL : result.release(); | 78 return result->data_set_.empty() ? NULL : result.release(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 virtual APIPermission* Union(const APIPermission* rhs) const OVERRIDE { | 81 virtual APIPermission* Union(const APIPermission* rhs) const override { |
| 82 CHECK(rhs->info() == info()); | 82 CHECK(rhs->info() == info()); |
| 83 const SetDisjunctionPermission* perm = | 83 const SetDisjunctionPermission* perm = |
| 84 static_cast<const SetDisjunctionPermission*>(rhs); | 84 static_cast<const SetDisjunctionPermission*>(rhs); |
| 85 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); | 85 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); |
| 86 result->data_set_ = base::STLSetUnion<std::set<PermissionDataType> >( | 86 result->data_set_ = base::STLSetUnion<std::set<PermissionDataType> >( |
| 87 data_set_, perm->data_set_); | 87 data_set_, perm->data_set_); |
| 88 return result.release(); | 88 return result.release(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 virtual APIPermission* Intersect(const APIPermission* rhs) const OVERRIDE { | 91 virtual APIPermission* Intersect(const APIPermission* rhs) const override { |
| 92 CHECK(rhs->info() == info()); | 92 CHECK(rhs->info() == info()); |
| 93 const SetDisjunctionPermission* perm = | 93 const SetDisjunctionPermission* perm = |
| 94 static_cast<const SetDisjunctionPermission*>(rhs); | 94 static_cast<const SetDisjunctionPermission*>(rhs); |
| 95 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); | 95 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); |
| 96 result->data_set_ = base::STLSetIntersection<std::set<PermissionDataType> >( | 96 result->data_set_ = base::STLSetIntersection<std::set<PermissionDataType> >( |
| 97 data_set_, perm->data_set_); | 97 data_set_, perm->data_set_); |
| 98 return result->data_set_.empty() ? NULL : result.release(); | 98 return result->data_set_.empty() ? NULL : result.release(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 virtual bool FromValue( | 101 virtual bool FromValue( |
| 102 const base::Value* value, | 102 const base::Value* value, |
| 103 std::string* error, | 103 std::string* error, |
| 104 std::vector<std::string>* unhandled_permissions) OVERRIDE { | 104 std::vector<std::string>* unhandled_permissions) override { |
| 105 data_set_.clear(); | 105 data_set_.clear(); |
| 106 const base::ListValue* list = NULL; | 106 const base::ListValue* list = NULL; |
| 107 | 107 |
| 108 if (!value || !value->GetAsList(&list) || list->GetSize() == 0) { | 108 if (!value || !value->GetAsList(&list) || list->GetSize() == 0) { |
| 109 if (error) | 109 if (error) |
| 110 *error = "NULL or empty permission list"; | 110 *error = "NULL or empty permission list"; |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 | 113 |
| 114 for (size_t i = 0; i < list->GetSize(); ++i) { | 114 for (size_t i = 0; i < list->GetSize(); ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 *error = "Cannot parse an item from the permission list: " + | 130 *error = "Cannot parse an item from the permission list: " + |
| 131 unknown_permission; | 131 unknown_permission; |
| 132 } | 132 } |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE { | 140 virtual scoped_ptr<base::Value> ToValue() const override { |
| 141 base::ListValue* list = new base::ListValue(); | 141 base::ListValue* list = new base::ListValue(); |
| 142 typename std::set<PermissionDataType>::const_iterator i; | 142 typename std::set<PermissionDataType>::const_iterator i; |
| 143 for (i = data_set_.begin(); i != data_set_.end(); ++i) { | 143 for (i = data_set_.begin(); i != data_set_.end(); ++i) { |
| 144 scoped_ptr<base::Value> item_value(i->ToValue()); | 144 scoped_ptr<base::Value> item_value(i->ToValue()); |
| 145 list->Append(item_value.release()); | 145 list->Append(item_value.release()); |
| 146 } | 146 } |
| 147 return scoped_ptr<base::Value>(list); | 147 return scoped_ptr<base::Value>(list); |
| 148 } | 148 } |
| 149 | 149 |
| 150 virtual void Write(IPC::Message* m) const OVERRIDE { | 150 virtual void Write(IPC::Message* m) const override { |
| 151 IPC::WriteParam(m, data_set_); | 151 IPC::WriteParam(m, data_set_); |
| 152 } | 152 } |
| 153 | 153 |
| 154 virtual bool Read(const IPC::Message* m, PickleIterator* iter) OVERRIDE { | 154 virtual bool Read(const IPC::Message* m, PickleIterator* iter) override { |
| 155 return IPC::ReadParam(m, iter, &data_set_); | 155 return IPC::ReadParam(m, iter, &data_set_); |
| 156 } | 156 } |
| 157 | 157 |
| 158 virtual void Log(std::string* log) const OVERRIDE { | 158 virtual void Log(std::string* log) const override { |
| 159 IPC::LogParam(data_set_, log); | 159 IPC::LogParam(data_set_, log); |
| 160 } | 160 } |
| 161 | 161 |
| 162 protected: | 162 protected: |
| 163 std::set<PermissionDataType> data_set_; | 163 std::set<PermissionDataType> data_set_; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 } // namespace extensions | 166 } // namespace extensions |
| 167 | 167 |
| 168 #endif // EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 168 #endif // EXTENSIONS_COMMON_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| OLD | NEW |