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_FEATURES_SIMPLE_FEATURE_H_ | 5 #ifndef EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
6 #define EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 6 #define EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <initializer_list> |
10 #include <memory> | 11 #include <memory> |
11 #include <set> | 12 #include <set> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
18 #include "base/macros.h" | 19 #include "base/macros.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // supported in feature files. These should only be used in this class and in | 93 // supported in feature files. These should only be used in this class and in |
93 // generated files. | 94 // generated files. |
94 enum Location { | 95 enum Location { |
95 UNSPECIFIED_LOCATION, | 96 UNSPECIFIED_LOCATION, |
96 COMPONENT_LOCATION, | 97 COMPONENT_LOCATION, |
97 EXTERNAL_COMPONENT_LOCATION, | 98 EXTERNAL_COMPONENT_LOCATION, |
98 POLICY_LOCATION, | 99 POLICY_LOCATION, |
99 }; | 100 }; |
100 | 101 |
101 // Setters used by generated code to create the feature. | 102 // Setters used by generated code to create the feature. |
102 // NOTE: These setters use rvalue references deliberately. These should only | 103 // NOTE: These setters use base::StringPiece and std::initalizer_list rather |
103 // ever be used by generated code, and we ensure that in each call, the new | 104 // than std::string and std::vector for binary size reasons. Using STL types |
104 // value is constructed in-place. This allows us to avoid a copy when we | 105 // directly in the header means that code that doesn't already have that exact |
105 // assign it to the value in this class, and results in noticable improvements | 106 // type ends up triggering many implicit conversions which are all inlined. |
106 // in both speed and binary size. | 107 void set_blacklist(std::initializer_list<const char* const> blacklist); |
107 void set_blacklist(std::vector<std::string>&& blacklist); | |
108 void set_channel(version_info::Channel channel) { | 108 void set_channel(version_info::Channel channel) { |
109 channel_.reset(new version_info::Channel(channel)); | 109 channel_.reset(new version_info::Channel(channel)); |
110 } | 110 } |
111 void set_command_line_switch(std::string&& command_line_switch); | 111 void set_command_line_switch(base::StringPiece command_line_switch); |
112 void set_component_extensions_auto_granted(bool granted) { | 112 void set_component_extensions_auto_granted(bool granted) { |
113 component_extensions_auto_granted_ = granted; | 113 component_extensions_auto_granted_ = granted; |
114 } | 114 } |
115 void set_contexts(std::vector<Context>&& contexts); | 115 void set_contexts(std::initializer_list<Context> contexts); |
116 void set_dependencies(std::vector<std::string>&& dependencies); | 116 void set_dependencies(std::initializer_list<const char* const> dependencies); |
117 void set_extension_types(std::vector<Manifest::Type>&& types); | 117 void set_extension_types(std::initializer_list<Manifest::Type> types); |
118 void set_internal(bool is_internal) { is_internal_ = is_internal; } | 118 void set_internal(bool is_internal) { is_internal_ = is_internal; } |
119 void set_location(Location location) { location_ = location; } | 119 void set_location(Location location) { location_ = location; } |
120 // set_matches() is an exception to pass-by-value since we construct an | 120 // set_matches() is an exception to pass-by-value since we construct an |
121 // URLPatternSet from the vector of strings. | 121 // URLPatternSet from the vector of strings. |
122 // TODO(devlin): Pass in an URLPatternSet directly. | 122 // TODO(devlin): Pass in an URLPatternSet directly. |
123 void set_matches(const std::vector<std::string>& matches); | 123 void set_matches(std::initializer_list<const char* const> matches); |
124 void set_max_manifest_version(int max_manifest_version) { | 124 void set_max_manifest_version(int max_manifest_version) { |
125 max_manifest_version_ = max_manifest_version; | 125 max_manifest_version_ = max_manifest_version; |
126 } | 126 } |
127 void set_min_manifest_version(int min_manifest_version) { | 127 void set_min_manifest_version(int min_manifest_version) { |
128 min_manifest_version_ = min_manifest_version; | 128 min_manifest_version_ = min_manifest_version; |
129 } | 129 } |
130 void set_noparent(bool no_parent) { no_parent_ = no_parent; } | 130 void set_noparent(bool no_parent) { no_parent_ = no_parent; } |
131 void set_platforms(std::vector<Platform>&& platforms); | 131 void set_platforms(std::initializer_list<Platform> platforms); |
132 void set_whitelist(std::vector<std::string>&& whitelist); | 132 void set_whitelist(std::initializer_list<const char* const> whitelist); |
133 | 133 |
134 protected: | 134 protected: |
135 // Accessors used by subclasses in feature verification. | 135 // Accessors used by subclasses in feature verification. |
136 const std::vector<std::string>& blacklist() const { return blacklist_; } | 136 const std::vector<std::string>& blacklist() const { return blacklist_; } |
137 const std::vector<std::string>& whitelist() const { return whitelist_; } | 137 const std::vector<std::string>& whitelist() const { return whitelist_; } |
138 const std::vector<Manifest::Type>& extension_types() const { | 138 const std::vector<Manifest::Type>& extension_types() const { |
139 return extension_types_; | 139 return extension_types_; |
140 } | 140 } |
141 const std::vector<Platform>& platforms() const { return platforms_; } | 141 const std::vector<Platform>& platforms() const { return platforms_; } |
142 const std::vector<Context>& contexts() const { return contexts_; } | 142 const std::vector<Context>& contexts() const { return contexts_; } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 bool is_internal_; | 232 bool is_internal_; |
233 std::string command_line_switch_; | 233 std::string command_line_switch_; |
234 std::unique_ptr<version_info::Channel> channel_; | 234 std::unique_ptr<version_info::Channel> channel_; |
235 | 235 |
236 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); | 236 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); |
237 }; | 237 }; |
238 | 238 |
239 } // namespace extensions | 239 } // namespace extensions |
240 | 240 |
241 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 241 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
OLD | NEW |