Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/common/extensions/features/complex_feature.cc

Issue 11316164: Implement ComplexFeature to support permission features with multiple rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames and add TODO Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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);
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
28 for (FeatureList::const_iterator it = features_.begin() + 1;
29 it != features_.end(); ++it) {
30 Availability availability = (*it)->IsAvailableToManifest(
31 extension_id, type, location, manifest_version, platform);
32 if (availability.is_available())
33 return availability;
34 }
35 // If none of the SimpleFeatures are available, we return the availability
36 // info of the first SimpleFeature that was not available.
37 return first_availability;
38 }
39
40 Feature::Availability ComplexFeature::IsAvailableToContext(
41 const Extension* extension, Context context, Platform platform) const {
42 Feature::Availability first_availability =
43 features_[0]->IsAvailableToContext(extension, context, platform);
44 if (first_availability.is_available())
45 return first_availability;
46
47 for (FeatureList::const_iterator it = features_.begin() + 1;
48 it != features_.end(); ++it) {
49 Availability availability =
50 (*it)->IsAvailableToContext(extension, context, platform);
51 if (availability.is_available())
52 return availability;
53 }
54 // If none of the SimpleFeatures are available, we return the availability
55 // info of the first SimpleFeature that was not available.
56 return first_availability;
57 }
58
59 std::set<Feature::Context>* ComplexFeature::GetContexts() {
60 // TODO(justinlin): Current use cases for ComplexFeatures are simple (e.g.
61 // allow API in dev channel for everyone but stable channel for a whitelist),
62 // but if they get more complicated, we need to return some meaningful context
63 // set. Either that or remove this method from the Feature interface.
64 return features_[0]->GetContexts();
65 }
66
67 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result,
68 Extension::Type type) const {
69 if (result == IS_AVAILABLE)
70 return "";
71
72 // TODO(justinlin): Form some kind of combined availabilities/messages from
73 // SimpleFeatures.
74 return features_[0]->GetAvailabilityMessage(result, type);
75 }
76
77 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/features/complex_feature.h ('k') | chrome/common/extensions/features/complex_feature_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698