| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/common/features/complex_feature.h" | 5 #include "extensions/common/features/complex_feature.h" |
| 6 | 6 |
| 7 namespace extensions { | 7 namespace extensions { |
| 8 | 8 |
| 9 ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) { | 9 ComplexFeature::ComplexFeature(scoped_ptr<FeatureList> features) { |
| 10 DCHECK_GT(features->size(), 0UL); | 10 DCHECK_GT(features->size(), 0UL); |
| 11 features_.swap(*features); | 11 features_.swap(*features); |
| 12 no_parent_ = features_[0]->no_parent(); | 12 no_parent_ = features_[0]->no_parent(); |
| 13 | 13 |
| 14 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | 14 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
| 15 // Verify IsInternal and IsBlockedInServiceWorker are consistent across all | 15 // Verify IsInternal and no_parent is consistent across all features. |
| 16 // features. | |
| 17 bool first_is_internal = features_[0]->IsInternal(); | 16 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; | 17 for (FeatureList::const_iterator it = features_.begin() + 1; |
| 21 it != features_.end(); | 18 it != features_.end(); |
| 22 ++it) { | 19 ++it) { |
| 23 DCHECK(first_is_internal == (*it)->IsInternal()) | 20 DCHECK(first_is_internal == (*it)->IsInternal()) |
| 24 << "Complex feature must have consistent values of " | 21 << "Complex feature must have consistent values of " |
| 25 "internal across all sub features."; | 22 "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()) | 23 DCHECK(no_parent_ == (*it)->no_parent()) |
| 30 << "Complex feature must have consistent values of " | 24 << "Complex feature must have consistent values of " |
| 31 "no_parent across all sub features."; | 25 "no_parent across all sub features."; |
| 32 } | 26 } |
| 33 #endif | 27 #endif |
| 34 } | 28 } |
| 35 | 29 |
| 36 ComplexFeature::~ComplexFeature() { | 30 ComplexFeature::~ComplexFeature() { |
| 37 } | 31 } |
| 38 | 32 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const { | 89 bool ComplexFeature::IsIdInWhitelist(const std::string& extension_id) const { |
| 96 for (FeatureList::const_iterator it = features_.begin(); | 90 for (FeatureList::const_iterator it = features_.begin(); |
| 97 it != features_.end(); | 91 it != features_.end(); |
| 98 ++it) { | 92 ++it) { |
| 99 if ((*it)->IsIdInWhitelist(extension_id)) | 93 if ((*it)->IsIdInWhitelist(extension_id)) |
| 100 return true; | 94 return true; |
| 101 } | 95 } |
| 102 return false; | 96 return false; |
| 103 } | 97 } |
| 104 | 98 |
| 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(); | |
| 109 } | |
| 110 | |
| 111 bool ComplexFeature::IsInternal() const { | 99 bool ComplexFeature::IsInternal() const { |
| 112 // Constructor verifies that composed features are consistent, thus we can | 100 // Constructor verifies that composed features are consistent, thus we can |
| 113 // return just the first feature's value. | 101 // return just the first feature's value. |
| 114 return features_[0]->IsInternal(); | 102 return features_[0]->IsInternal(); |
| 115 } | 103 } |
| 116 | 104 |
| 117 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, | 105 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, |
| 118 Manifest::Type type, | 106 Manifest::Type type, |
| 119 const GURL& url, | 107 const GURL& url, |
| 120 Context context) const { | 108 Context context) const { |
| 121 if (result == IS_AVAILABLE) | 109 if (result == IS_AVAILABLE) |
| 122 return std::string(); | 110 return std::string(); |
| 123 | 111 |
| 124 // TODO(justinlin): Form some kind of combined availabilities/messages from | 112 // TODO(justinlin): Form some kind of combined availabilities/messages from |
| 125 // SimpleFeatures. | 113 // SimpleFeatures. |
| 126 return features_[0]->GetAvailabilityMessage(result, type, url, context); | 114 return features_[0]->GetAvailabilityMessage(result, type, url, context); |
| 127 } | 115 } |
| 128 | 116 |
| 129 } // namespace extensions | 117 } // namespace extensions |
| OLD | NEW |