Index: chrome/common/extensions/features/complex_feature.cc |
diff --git a/chrome/common/extensions/features/complex_feature.cc b/chrome/common/extensions/features/complex_feature.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b30c15b5de22e945ebe32228e3dfb9f70103e46a |
--- /dev/null |
+++ b/chrome/common/extensions/features/complex_feature.cc |
@@ -0,0 +1,75 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/common/extensions/features/complex_feature.h" |
+ |
+namespace extensions { |
+ |
+ComplexFeature::ComplexFeature() {} |
+ |
+ComplexFeature::~ComplexFeature() {} |
+ |
+void ComplexFeature::AddSimpleFeature(const PermissionFeature* feature) { |
+ simple_features_.push_back(*feature); |
+} |
+ |
+Feature::Availability ComplexFeature::IsAvailableToManifest( |
+ const std::string& extension_id, Extension::Type type, Location location, |
+ int manifest_version, Platform platform) const { |
+ DCHECK_GT(simple_features_.size(), 0UL); |
not at google - send to devlin
2012/12/12 17:42:41
hopefully you can pass these in in the constructor
justinlin
2012/12/14 12:26:26
Done.
|
+ Feature::Availability first_availability = |
+ simple_features_[0].IsAvailableToManifest(extension_id, |
+ type, |
+ location, |
+ manifest_version, |
+ platform); |
+ if (!first_availability.is_available()) { |
not at google - send to devlin
2012/12/12 17:42:41
nit: early exit here
justinlin
2012/12/14 12:26:26
Done.
|
+ for (SimpleFeatureList::const_iterator it = simple_features_.begin() + 1; |
+ it != simple_features_.end(); ++it) { |
+ Availability availability = |
+ it->IsAvailableToManifest(extension_id, |
+ type, |
+ location, |
+ manifest_version, |
+ platform); |
+ if (availability.is_available()) |
+ return availability; |
+ } |
+ } |
+ // If none of the SimpleFeatures are available, we return the availability |
+ // info of the first SimpleFeature (which, of course is not available). |
+ return first_availability; |
+} |
+ |
+Feature::Availability ComplexFeature::IsAvailableToContext( |
+ const Extension* extension, Context context, Platform platform) const { |
+ DCHECK_GT(simple_features_.size(), 0UL); |
+ Feature::Availability first_availability = |
+ simple_features_[0].IsAvailableToContext(extension, |
+ context, |
+ platform); |
+ if (!first_availability.is_available()) { |
not at google - send to devlin
2012/12/12 17:42:41
nit: early exit
justinlin
2012/12/14 12:26:26
Done.
|
+ for (SimpleFeatureList::const_iterator it = simple_features_.begin() + 1; |
+ it != simple_features_.end(); ++it) { |
+ Availability availability = |
+ it->IsAvailableToContext(extension, context, platform); |
+ if (availability.is_available()) |
+ return availability; |
+ } |
+ } |
+ // If none of the SimpleFeatures are available, we return the availability |
+ // info of the first SimpleFeature (which, of course is not available). |
+ return first_availability; |
+} |
+ |
+std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, |
+ Extension::Type type) const { |
+ DCHECK_GT(simple_features_.size(), 0UL); |
+ if (result == IS_AVAILABLE) |
+ return ""; |
+ |
+ return simple_features_[0].GetAvailabilityMessage(result, type); |
not at google - send to devlin
2012/12/12 17:42:41
it would be nice for all of these to actually form
justinlin
2012/12/14 12:26:26
Yea, I think this requires some thought. The UI in
|
+} |
+ |
+} // namespace extensions |