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

Side by Side Diff: extensions/common/permissions/set_disjunction_permission.h

Issue 1104543004: Update {virtual,override} to follow C++11 style in extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « extensions/browser/mock_extension_system.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 // APIPermission::CheckParam matches any of the conditions in the set, the 24 // APIPermission::CheckParam matches any of the conditions in the set, the
25 // permission is granted. 25 // permission is granted.
26 // 26 //
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() override {}
35 35
36 // APIPermission overrides 36 // APIPermission overrides
37 virtual bool HasMessages() const override { return !data_set_.empty(); } 37 bool HasMessages() const override { return !data_set_.empty(); }
38 38
39 virtual bool Check(const APIPermission::CheckParam* param) const override { 39 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 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 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 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 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 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 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 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;
(...skipping 18 matching lines...) Expand all
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 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 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 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 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_
OLDNEW
« no previous file with comments | « extensions/browser/mock_extension_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698