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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 rvalue references deliberately. These should only |
103 // ever be used by generated code, and we ensure that in each call, the new | 104 // ever be used by generated code, and we ensure that in each call, the new |
104 // value is constructed in-place. This allows us to avoid a copy when we | 105 // value is constructed in-place. This allows us to avoid a copy when we |
105 // assign it to the value in this class, and results in noticable improvements | 106 // assign it to the value in this class, and results in noticable improvements |
106 // in both speed and binary size. | 107 // in both speed and binary size. |
107 void set_blacklist(std::vector<std::string>&& blacklist); | 108 // TODO(dcheng): Not sure why this needs a style exception, we can still move |
109 // when we pass by value? Perhaps codegen is still worse. | |
Devlin
2016/07/27 15:36:49
Passing by rvalue reference reduced binary size an
| |
110 void set_blacklist(std::initializer_list<const char* const> blacklist); | |
108 void set_channel(version_info::Channel channel) { | 111 void set_channel(version_info::Channel channel) { |
109 channel_.reset(new version_info::Channel(channel)); | 112 channel_.reset(new version_info::Channel(channel)); |
110 } | 113 } |
111 void set_command_line_switch(std::string&& command_line_switch); | 114 void set_command_line_switch(std::string&& command_line_switch); |
dcheng
2016/07/27 09:48:50
This is the last thing that passes by rvalue: what
Devlin
2016/07/27 16:43:59
Sure. Any reason not to?
dcheng
2016/07/27 17:02:36
Done.
| |
112 void set_component_extensions_auto_granted(bool granted) { | 115 void set_component_extensions_auto_granted(bool granted) { |
113 component_extensions_auto_granted_ = granted; | 116 component_extensions_auto_granted_ = granted; |
114 } | 117 } |
115 void set_contexts(std::vector<Context>&& contexts); | 118 void set_contexts(std::initializer_list<Context> contexts); |
116 void set_dependencies(std::vector<std::string>&& dependencies); | 119 void set_dependencies(std::initializer_list<const char* const> dependencies); |
117 void set_extension_types(std::vector<Manifest::Type>&& types); | 120 void set_extension_types(std::initializer_list<Manifest::Type> types); |
118 void set_internal(bool is_internal) { is_internal_ = is_internal; } | 121 void set_internal(bool is_internal) { is_internal_ = is_internal; } |
119 void set_location(Location location) { location_ = location; } | 122 void set_location(Location location) { location_ = location; } |
120 // set_matches() is an exception to pass-by-value since we construct an | 123 // set_matches() is an exception to pass-by-value since we construct an |
121 // URLPatternSet from the vector of strings. | 124 // URLPatternSet from the vector of strings. |
122 // TODO(devlin): Pass in an URLPatternSet directly. | 125 // TODO(devlin): Pass in an URLPatternSet directly. |
123 void set_matches(const std::vector<std::string>& matches); | 126 void set_matches(std::initializer_list<const char* const> matches); |
124 void set_max_manifest_version(int max_manifest_version) { | 127 void set_max_manifest_version(int max_manifest_version) { |
125 max_manifest_version_ = max_manifest_version; | 128 max_manifest_version_ = max_manifest_version; |
126 } | 129 } |
127 void set_min_manifest_version(int min_manifest_version) { | 130 void set_min_manifest_version(int min_manifest_version) { |
128 min_manifest_version_ = min_manifest_version; | 131 min_manifest_version_ = min_manifest_version; |
129 } | 132 } |
130 void set_noparent(bool no_parent) { no_parent_ = no_parent; } | 133 void set_noparent(bool no_parent) { no_parent_ = no_parent; } |
131 void set_platforms(std::vector<Platform>&& platforms); | 134 void set_platforms(std::initializer_list<Platform> platforms); |
132 void set_whitelist(std::vector<std::string>&& whitelist); | 135 void set_whitelist(std::initializer_list<const char* const> whitelist); |
133 | 136 |
134 protected: | 137 protected: |
135 // Accessors used by subclasses in feature verification. | 138 // Accessors used by subclasses in feature verification. |
136 const std::vector<std::string>& blacklist() const { return blacklist_; } | 139 const std::vector<std::string>& blacklist() const { return blacklist_; } |
137 const std::vector<std::string>& whitelist() const { return whitelist_; } | 140 const std::vector<std::string>& whitelist() const { return whitelist_; } |
138 const std::vector<Manifest::Type>& extension_types() const { | 141 const std::vector<Manifest::Type>& extension_types() const { |
139 return extension_types_; | 142 return extension_types_; |
140 } | 143 } |
141 const std::vector<Platform>& platforms() const { return platforms_; } | 144 const std::vector<Platform>& platforms() const { return platforms_; } |
142 const std::vector<Context>& contexts() const { return contexts_; } | 145 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_; | 235 bool is_internal_; |
233 std::string command_line_switch_; | 236 std::string command_line_switch_; |
234 std::unique_ptr<version_info::Channel> channel_; | 237 std::unique_ptr<version_info::Channel> channel_; |
235 | 238 |
236 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); | 239 DISALLOW_COPY_AND_ASSIGN(SimpleFeature); |
237 }; | 240 }; |
238 | 241 |
239 } // namespace extensions | 242 } // namespace extensions |
240 | 243 |
241 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ | 244 #endif // EXTENSIONS_COMMON_FEATURES_SIMPLE_FEATURE_H_ |
OLD | NEW |