| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_COMMON_EXTENSIONS_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 static_cast<const SetDisjunctionPermission*>(rhs); | 103 static_cast<const SetDisjunctionPermission*>(rhs); |
| 104 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); | 104 scoped_ptr<SetDisjunctionPermission> result(new DerivedType(info())); |
| 105 std::set_intersection( | 105 std::set_intersection( |
| 106 data_set_.begin(), data_set_.end(), | 106 data_set_.begin(), data_set_.end(), |
| 107 perm->data_set_.begin(), perm->data_set_.end(), | 107 perm->data_set_.begin(), perm->data_set_.end(), |
| 108 std::inserter<std::set<PermissionDataType> >( | 108 std::inserter<std::set<PermissionDataType> >( |
| 109 result->data_set_, result->data_set_.begin())); | 109 result->data_set_, result->data_set_.begin())); |
| 110 return result->data_set_.empty() ? NULL : result.release(); | 110 return result->data_set_.empty() ? NULL : result.release(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 virtual bool FromValue(const base::Value* value) OVERRIDE { | 113 virtual bool FromValue(const base::Value* value, |
| 114 std::string* error) OVERRIDE { |
| 114 data_set_.clear(); | 115 data_set_.clear(); |
| 115 const base::ListValue* list = NULL; | 116 const base::ListValue* list = NULL; |
| 116 | 117 |
| 117 if (!value) | 118 if (!value || !value->GetAsList(&list) || list->GetSize() == 0) { |
| 119 if (error) |
| 120 *error = "NULL or empty permission list"; |
| 118 return false; | 121 return false; |
| 119 | 122 } |
| 120 if (!value->GetAsList(&list) || list->GetSize() == 0) | |
| 121 return false; | |
| 122 | 123 |
| 123 for (size_t i = 0; i < list->GetSize(); ++i) { | 124 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 124 const base::Value* item_value; | 125 const base::Value* item_value = NULL; |
| 125 if (!list->Get(i, &item_value)) | 126 bool got_item = list->Get(i, &item_value); |
| 126 return false; | 127 DCHECK(got_item); |
| 128 DCHECK(item_value); |
| 127 | 129 |
| 128 PermissionDataType data; | 130 PermissionDataType data; |
| 129 if (!data.FromValue(item_value)) | 131 if (!data.FromValue(item_value)) { |
| 132 if (error) |
| 133 *error = "Cannot parse an item from the permission list"; |
| 130 return false; | 134 return false; |
| 135 } |
| 131 | 136 |
| 132 data_set_.insert(data); | 137 data_set_.insert(data); |
| 133 } | 138 } |
| 134 return true; | 139 return true; |
| 135 } | 140 } |
| 136 | 141 |
| 137 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE { | 142 virtual scoped_ptr<base::Value> ToValue() const OVERRIDE { |
| 138 base::ListValue* list = new base::ListValue(); | 143 base::ListValue* list = new base::ListValue(); |
| 139 typename std::set<PermissionDataType>::const_iterator i; | 144 typename std::set<PermissionDataType>::const_iterator i; |
| 140 for (i = data_set_.begin(); i != data_set_.end(); ++i) { | 145 for (i = data_set_.begin(); i != data_set_.end(); ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 156 IPC::LogParam(data_set_, log); | 161 IPC::LogParam(data_set_, log); |
| 157 } | 162 } |
| 158 | 163 |
| 159 protected: | 164 protected: |
| 160 std::set<PermissionDataType> data_set_; | 165 std::set<PermissionDataType> data_set_; |
| 161 }; | 166 }; |
| 162 | 167 |
| 163 } // namespace extensions | 168 } // namespace extensions |
| 164 | 169 |
| 165 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ | 170 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SET_DISJUNCTION_PERMISSION_H_ |
| OLD | NEW |