OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/common/extensions/features/complex_feature.h" | |
6 | |
7 #include "chrome/common/extensions/features/simple_feature.h" | |
8 | |
9 namespace extensions { | |
10 | |
11 ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) { | |
12 DCHECK_GT(features->size(), 0UL); | |
13 features_.swap(*features.get()); | |
not at google - send to devlin
2012/12/14 19:10:42
just *features is fine
justinlin
2012/12/14 21:07:52
Done.
| |
14 } | |
15 | |
16 ComplexFeature::~ComplexFeature() { | |
17 } | |
18 | |
19 Feature::Availability ComplexFeature::IsAvailableToManifest( | |
20 const std::string& extension_id, Extension::Type type, Location location, | |
21 int manifest_version, Platform platform) const { | |
22 Feature::Availability first_availability = | |
23 features_[0]->IsAvailableToManifest( | |
24 extension_id, type, location, manifest_version, platform); | |
25 if (first_availability.is_available()) { | |
26 return first_availability; | |
27 } | |
not at google - send to devlin
2012/12/14 19:10:42
no {} for single-line if blocks.
justinlin
2012/12/14 21:07:52
Done.
| |
28 | |
29 for (FeatureList::const_iterator it = features_.begin() + 1; | |
30 it != features_.end(); ++it) { | |
31 Availability availability = (*it)->IsAvailableToManifest( | |
32 extension_id, type, location, manifest_version, platform); | |
33 if (availability.is_available()) | |
34 return availability; | |
35 } | |
36 // If none of the SimpleFeatures are available, we return the availability | |
37 // info of the first SimpleFeature that was not available. | |
38 return first_availability; | |
39 } | |
40 | |
41 Feature::Availability ComplexFeature::IsAvailableToContext( | |
42 const Extension* extension, Context context, Platform platform) const { | |
43 Feature::Availability first_availability = | |
44 features_[0]->IsAvailableToContext(extension, context, platform); | |
45 if (first_availability.is_available()) { | |
46 return first_availability; | |
47 } | |
not at google - send to devlin
2012/12/14 19:10:42
ditto
justinlin
2012/12/14 21:07:52
Done.
| |
48 | |
49 for (FeatureList::const_iterator it = features_.begin() + 1; | |
50 it != features_.end(); ++it) { | |
51 Availability availability = | |
52 (*it)->IsAvailableToContext(extension, context, platform); | |
53 if (availability.is_available()) | |
54 return availability; | |
55 } | |
56 // If none of the SimpleFeatures are available, we return the availability | |
57 // info of the first SimpleFeature that was not available. | |
58 return first_availability; | |
59 } | |
60 | |
61 std::set<Feature::Context>* ComplexFeature::contexts() { | |
62 // TODO(justinlin): Current use cases for ComplexFeatures are simple (e.g. | |
63 // allow API to dev channel for every and stable channel for a whitelist), but | |
64 // if they get more complicated, we need to return some meaningful context | |
65 // set. Either that or remove this method from the Feature interface. | |
66 return features_[0]->contexts(); | |
67 } | |
68 | |
69 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, | |
70 Extension::Type type) const { | |
71 if (result == IS_AVAILABLE) | |
72 return ""; | |
73 | |
74 // TODO(justinlin): Form some kind of combined availabilities/messages from | |
75 // SimpleFeatures. | |
76 return features_[0]->GetAvailabilityMessage(result, type); | |
77 } | |
78 | |
79 } // namespace extensions | |
OLD | NEW |