[BuildBreak] Linux: Fix g++ 4.8 compilation for error: multi-line comment [-Werror...
[chromium-blink-merge.git] / extensions / common / features / complex_feature.cc
blob94402859e7120f4a9ae593d5c934613e005fcfaa
1 // Copyright 2014 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.
5 #include "extensions/common/features/complex_feature.h"
7 namespace extensions {
9 ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) {
10 DCHECK_GT(features->size(), 0UL);
11 features_.swap(*features);
12 no_parent_ = features_[0]->no_parent();
14 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
15 // Verify IsInternal and IsBlockedInServiceWorker are consistent across all
16 // features.
17 bool first_is_internal = features_[0]->IsInternal();
18 bool first_blocked_in_service_worker =
19 features_[0]->IsBlockedInServiceWorker();
20 for (FeatureList::const_iterator it = features_.begin() + 1;
21 it != features_.end();
22 ++it) {
23 DCHECK(first_is_internal == (*it)->IsInternal())
24 << "Complex feature must have consistent values of "
25 "internal across all sub features.";
26 DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker())
27 << "Complex feature must have consistent values of "
28 "blocked_in_service_worker across all sub features.";
29 DCHECK(no_parent_ == (*it)->no_parent())
30 << "Complex feature must have consistent values of "
31 "no_parent across all sub features.";
33 #endif
36 ComplexFeature::~ComplexFeature() {
39 Feature::Availability ComplexFeature::IsAvailableToManifest(
40 const std::string& extension_id,
41 Manifest::Type type,
42 Manifest::Location location,
43 int manifest_version,
44 Platform platform) const {
45 Feature::Availability first_availability =
46 features_[0]->IsAvailableToManifest(
47 extension_id, type, location, manifest_version, platform);
48 if (first_availability.is_available())
49 return first_availability;
51 for (FeatureList::const_iterator it = features_.begin() + 1;
52 it != features_.end(); ++it) {
53 Availability availability = (*it)->IsAvailableToManifest(
54 extension_id, type, location, manifest_version, platform);
55 if (availability.is_available())
56 return availability;
58 // If none of the SimpleFeatures are available, we return the availability
59 // info of the first SimpleFeature that was not available.
60 return first_availability;
63 Feature::Availability ComplexFeature::IsAvailableToContext(
64 const Extension* extension,
65 Context context,
66 const GURL& url,
67 Platform platform) const {
68 Feature::Availability first_availability =
69 features_[0]->IsAvailableToContext(extension, context, url, platform);
70 if (first_availability.is_available())
71 return first_availability;
73 for (FeatureList::const_iterator it = features_.begin() + 1;
74 it != features_.end(); ++it) {
75 Availability availability =
76 (*it)->IsAvailableToContext(extension, context, url, platform);
77 if (availability.is_available())
78 return availability;
80 // If none of the SimpleFeatures are available, we return the availability
81 // info of the first SimpleFeature that was not available.
82 return first_availability;
85 bool ComplexFeature::IsIdInBlacklist(const std::string& extension_id) const {
86 for (FeatureList::const_iterator it = features_.begin();
87 it != features_.end();
88 ++it) {
89 if ((*it)->IsIdInBlacklist(extension_id))
90 return true;
92 return false;
95 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const {
96 for (FeatureList::const_iterator it = features_.begin();
97 it != features_.end();
98 ++it) {
99 if ((*it)->IsIdInWhitelist(extension_id))
100 return true;
102 return false;
105 bool ComplexFeature::IsBlockedInServiceWorker() const {
106 // Constructor verifies that composed features are consistent, thus we can
107 // return just the first feature's value.
108 return features_[0]->IsBlockedInServiceWorker();
111 bool ComplexFeature::IsInternal() const {
112 // Constructor verifies that composed features are consistent, thus we can
113 // return just the first feature's value.
114 return features_[0]->IsInternal();
117 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result,
118 Manifest::Type type,
119 const GURL& url,
120 Context context) const {
121 if (result == IS_AVAILABLE)
122 return std::string();
124 // TODO(justinlin): Form some kind of combined availabilities/messages from
125 // SimpleFeatures.
126 return features_[0]->GetAvailabilityMessage(result, type, url, context);
129 } // namespace extensions