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

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: new 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 namespace extensions {
8
9 ComplexFeature::ComplexFeature() {}
10
11 ComplexFeature::~ComplexFeature() {}
12
13 void ComplexFeature::AddSimpleFeature(const PermissionFeature* feature) {
14 simple_features_.push_back(*feature);
15 }
16
17 Feature::Availability ComplexFeature::IsAvailableToManifest(
18 const std::string& extension_id, Extension::Type type, Location location,
19 int manifest_version, Platform platform) const {
20 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.
21 Feature::Availability first_availability =
22 simple_features_[0].IsAvailableToManifest(extension_id,
23 type,
24 location,
25 manifest_version,
26 platform);
27 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.
28 for (SimpleFeatureList::const_iterator it = simple_features_.begin() + 1;
29 it != simple_features_.end(); ++it) {
30 Availability availability =
31 it->IsAvailableToManifest(extension_id,
32 type,
33 location,
34 manifest_version,
35 platform);
36 if (availability.is_available())
37 return availability;
38 }
39 }
40 // If none of the SimpleFeatures are available, we return the availability
41 // info of the first SimpleFeature (which, of course is not available).
42 return first_availability;
43 }
44
45 Feature::Availability ComplexFeature::IsAvailableToContext(
46 const Extension* extension, Context context, Platform platform) const {
47 DCHECK_GT(simple_features_.size(), 0UL);
48 Feature::Availability first_availability =
49 simple_features_[0].IsAvailableToContext(extension,
50 context,
51 platform);
52 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.
53 for (SimpleFeatureList::const_iterator it = simple_features_.begin() + 1;
54 it != simple_features_.end(); ++it) {
55 Availability availability =
56 it->IsAvailableToContext(extension, context, platform);
57 if (availability.is_available())
58 return availability;
59 }
60 }
61 // If none of the SimpleFeatures are available, we return the availability
62 // info of the first SimpleFeature (which, of course is not available).
63 return first_availability;
64 }
65
66 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result,
67 Extension::Type type) const {
68 DCHECK_GT(simple_features_.size(), 0UL);
69 if (result == IS_AVAILABLE)
70 return "";
71
72 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
73 }
74
75 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698