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_FEATURES_FEATURE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 friend class Feature; | 76 friend class Feature; |
77 | 77 |
78 // Instances should be created via Feature::CreateAvailability. | 78 // Instances should be created via Feature::CreateAvailability. |
79 Availability(AvailabilityResult result, const std::string& message) | 79 Availability(AvailabilityResult result, const std::string& message) |
80 : result_(result), message_(message) { } | 80 : result_(result), message_(message) { } |
81 | 81 |
82 const AvailabilityResult result_; | 82 const AvailabilityResult result_; |
83 const std::string message_; | 83 const std::string message_; |
84 }; | 84 }; |
85 | 85 |
86 Feature(); | 86 Feature() {} |
not at google - send to devlin
2012/12/14 19:10:42
If the constructor is just this then it can be lef
justinlin
2012/12/14 21:07:52
Done.
| |
87 Feature(const Feature& other); | 87 virtual ~Feature() {} |
not at google - send to devlin
2012/12/14 19:10:42
IIRC virtual constructors in non-pure-virtual clas
justinlin
2012/12/14 21:07:52
Done. Right, put it in the cc for now.
I moved the
| |
88 virtual ~Feature(); | |
89 | 88 |
90 // Gets the current channel as seen by the Feature system. | 89 // Gets the current channel as seen by the Feature system. |
91 static chrome::VersionInfo::Channel GetCurrentChannel(); | 90 static chrome::VersionInfo::Channel GetCurrentChannel(); |
92 | 91 |
93 // Sets the current channel as seen by the Feature system. In the browser | 92 // Sets the current channel as seen by the Feature system. In the browser |
94 // process this should be chrome::VersionInfo::GetChannel(), and in the | 93 // process this should be chrome::VersionInfo::GetChannel(), and in the |
95 // renderer this will need to come from an IPC. | 94 // renderer this will need to come from an IPC. |
96 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); | 95 static void SetCurrentChannel(chrome::VersionInfo::Channel channel); |
97 | 96 |
98 // Gets the default channel as seen by the Feature system. | 97 // Gets the default channel as seen by the Feature system. |
(...skipping 18 matching lines...) Expand all Loading... | |
117 | 116 |
118 const std::string& name() const { return name_; } | 117 const std::string& name() const { return name_; } |
119 void set_name(const std::string& name) { name_ = name; } | 118 void set_name(const std::string& name) { name_ = name; } |
120 | 119 |
121 // Gets the platform the code is currently running on. | 120 // Gets the platform the code is currently running on. |
122 static Platform GetCurrentPlatform(); | 121 static Platform GetCurrentPlatform(); |
123 | 122 |
124 // Gets the Feature::Location value for the specified Extension::Location. | 123 // Gets the Feature::Location value for the specified Extension::Location. |
125 static Location ConvertLocation(Extension::Location extension_location); | 124 static Location ConvertLocation(Extension::Location extension_location); |
126 | 125 |
127 std::set<std::string>* whitelist() { return &whitelist_; } | 126 virtual std::set<Context>* contexts() = 0; |
not at google - send to devlin
2012/12/14 19:10:42
Generally speaking you can't guarantee that virtua
justinlin
2012/12/14 21:07:52
extension_api.cc needs this method in a couple pla
| |
128 std::set<Extension::Type>* extension_types() { return &extension_types_; } | |
129 std::set<Context>* contexts() { return &contexts_; } | |
130 | |
131 Location location() const { return location_; } | |
132 void set_location(Location location) { location_ = location; } | |
133 | |
134 Platform platform() const { return platform_; } | |
135 void set_platform(Platform platform) { platform_ = platform; } | |
136 | |
137 int min_manifest_version() const { return min_manifest_version_; } | |
138 void set_min_manifest_version(int min_manifest_version) { | |
139 min_manifest_version_ = min_manifest_version; | |
140 } | |
141 | |
142 int max_manifest_version() const { return max_manifest_version_; } | |
143 void set_max_manifest_version(int max_manifest_version) { | |
144 max_manifest_version_ = max_manifest_version; | |
145 } | |
146 | |
147 // Parses the JSON representation of a feature into the fields of this object. | |
148 // Unspecified values in the JSON are not modified in the object. This allows | |
149 // us to implement inheritance by parsing one value after another. | |
150 void Parse(const DictionaryValue* value); | |
151 | |
152 // Returns true if the feature contains the same values as another. | |
153 bool Equals(const Feature& other) const; | |
154 | 127 |
155 // Returns true if the feature is available to be parsed into a new extension | 128 // Returns true if the feature is available to be parsed into a new extension |
156 // manifest. | 129 // manifest. |
157 Availability IsAvailableToManifest(const std::string& extension_id, | 130 Availability IsAvailableToManifest(const std::string& extension_id, |
158 Extension::Type type, | 131 Extension::Type type, |
159 Location location, | 132 Location location, |
160 int manifest_version) const { | 133 int manifest_version) const { |
161 return IsAvailableToManifest(extension_id, type, location, manifest_version, | 134 return IsAvailableToManifest(extension_id, type, location, manifest_version, |
162 GetCurrentPlatform()); | 135 GetCurrentPlatform()); |
163 } | 136 } |
164 Availability IsAvailableToManifest(const std::string& extension_id, | 137 virtual Availability IsAvailableToManifest(const std::string& extension_id, |
165 Extension::Type type, | 138 Extension::Type type, |
166 Location location, | 139 Location location, |
167 int manifest_version, | 140 int manifest_version, |
168 Platform platform) const; | 141 Platform platform) const = 0; |
169 | 142 |
170 // Returns true if the feature is available to be used in the specified | 143 // Returns true if the feature is available to be used in the specified |
171 // extension and context. | 144 // extension and context. |
172 Availability IsAvailableToContext(const Extension* extension, | 145 Availability IsAvailableToContext(const Extension* extension, |
173 Context context) const { | 146 Context context) const { |
174 return IsAvailableToContext(extension, context, GetCurrentPlatform()); | 147 return IsAvailableToContext(extension, context, GetCurrentPlatform()); |
175 } | 148 } |
176 virtual Availability IsAvailableToContext(const Extension* extension, | 149 virtual Availability IsAvailableToContext(const Extension* extension, |
177 Context context, | 150 Context context, |
178 Platform platform) const; | 151 Platform platform) const = 0; |
179 | 152 |
180 protected: | 153 protected: |
181 Availability CreateAvailability(AvailabilityResult result) const; | 154 Availability CreateAvailability(AvailabilityResult result) const; |
182 Availability CreateAvailability(AvailabilityResult result, | 155 Availability CreateAvailability(AvailabilityResult result, |
183 Extension::Type type) const; | 156 Extension::Type type) const; |
184 | 157 |
185 private: | 158 virtual std::string GetAvailabilityMessage( |
186 std::string GetAvailabilityMessage( | 159 AvailabilityResult result, Extension::Type type) const = 0; |
187 AvailabilityResult result, Extension::Type type) const; | |
188 | 160 |
189 std::string name_; | 161 std::string name_; |
190 | |
191 // For clarify and consistency, we handle the default value of each of these | |
192 // members the same way: it matches everything. It is up to the higher level | |
193 // code that reads Features out of static data to validate that data and set | |
194 // sensible defaults. | |
195 std::set<std::string> whitelist_; | |
196 std::set<Extension::Type> extension_types_; | |
197 std::set<Context> contexts_; | |
198 Location location_; // we only care about component/not-component now | |
199 Platform platform_; // we only care about chromeos/not-chromeos now | |
200 int min_manifest_version_; | |
201 int max_manifest_version_; | |
202 chrome::VersionInfo::Channel channel_; | |
203 }; | 162 }; |
204 | 163 |
205 } // namespace extensions | 164 } // namespace extensions |
206 | 165 |
207 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ | 166 #endif // CHROME_COMMON_EXTENSIONS_FEATURES_FEATURE_H_ |
OLD | NEW |