Chromium Code Reviews| 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 GetContexts, IsInternal, & IsBlockedInServiceWorker are consistent | 15 // Verify IsInternal, & IsBlockedInServiceWorker are consistent across all |
|
Yoyo Zhou
2014/07/09 17:06:18
nit: comma seems extraneous
not at google - send to devlin
2014/07/09 17:12:00
Done.
| |
| 16 // across all features. | 16 // features. |
| 17 std::set<Feature::Context>* first_contexts = features_[0]->GetContexts(); | |
| 18 bool first_is_internal = features_[0]->IsInternal(); | 17 bool first_is_internal = features_[0]->IsInternal(); |
| 19 bool first_blocked_in_service_worker = | 18 bool first_blocked_in_service_worker = |
| 20 features_[0]->IsBlockedInServiceWorker(); | 19 features_[0]->IsBlockedInServiceWorker(); |
| 21 for (FeatureList::const_iterator it = features_.begin() + 1; | 20 for (FeatureList::const_iterator it = features_.begin() + 1; |
| 22 it != features_.end(); | 21 it != features_.end(); |
| 23 ++it) { | 22 ++it) { |
| 24 DCHECK(*first_contexts == *(*it)->GetContexts()) | |
| 25 << "Complex feature must have consistent values of " | |
| 26 "contexts across all sub features."; | |
| 27 DCHECK(first_is_internal == (*it)->IsInternal()) | 23 DCHECK(first_is_internal == (*it)->IsInternal()) |
| 28 << "Complex feature must have consistent values of " | 24 << "Complex feature must have consistent values of " |
| 29 "internal across all sub features."; | 25 "internal across all sub features."; |
| 30 DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker()) | 26 DCHECK(first_blocked_in_service_worker == (*it)->IsBlockedInServiceWorker()) |
| 31 << "Complex feature must have consistent values of " | 27 << "Complex feature must have consistent values of " |
| 32 "blocked_in_service_worker across all sub features."; | 28 "blocked_in_service_worker across all sub features."; |
| 33 DCHECK(no_parent_ == (*it)->no_parent()) | 29 DCHECK(no_parent_ == (*it)->no_parent()) |
| 34 << "Complex feature must have consistent values of " | 30 << "Complex feature must have consistent values of " |
| 35 "no_parent across all sub features."; | 31 "no_parent across all sub features."; |
| 36 } | 32 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 } | 101 } |
| 106 return false; | 102 return false; |
| 107 } | 103 } |
| 108 | 104 |
| 109 bool ComplexFeature::IsBlockedInServiceWorker() const { | 105 bool ComplexFeature::IsBlockedInServiceWorker() const { |
| 110 // Constructor verifies that composed features are consistent, thus we can | 106 // Constructor verifies that composed features are consistent, thus we can |
| 111 // return just the first feature's value. | 107 // return just the first feature's value. |
| 112 return features_[0]->IsBlockedInServiceWorker(); | 108 return features_[0]->IsBlockedInServiceWorker(); |
| 113 } | 109 } |
| 114 | 110 |
| 115 std::set<Feature::Context>* ComplexFeature::GetContexts() { | |
| 116 // TODO(justinlin): Current use cases for ComplexFeatures are simple (e.g. | |
| 117 // allow API in dev channel for everyone but stable channel for a whitelist), | |
| 118 // but if they get more complicated, we need to return some meaningful context | |
| 119 // set. Either that or remove this method from the Feature interface. | |
| 120 return features_[0]->GetContexts(); | |
| 121 } | |
| 122 | |
| 123 bool ComplexFeature::IsInternal() const { | 111 bool ComplexFeature::IsInternal() const { |
| 124 // TODO(justinlin): Same as the above TODO. | 112 // Constructor verifies that composed features are consistent, thus we can |
| 113 // return just the first feature's value. | |
| 125 return features_[0]->IsInternal(); | 114 return features_[0]->IsInternal(); |
| 126 } | 115 } |
| 127 | 116 |
| 128 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, | 117 std::string ComplexFeature::GetAvailabilityMessage(AvailabilityResult result, |
| 129 Manifest::Type type, | 118 Manifest::Type type, |
| 130 const GURL& url, | 119 const GURL& url, |
| 131 Context context) const { | 120 Context context) const { |
| 132 if (result == IS_AVAILABLE) | 121 if (result == IS_AVAILABLE) |
| 133 return std::string(); | 122 return std::string(); |
| 134 | 123 |
| 135 // TODO(justinlin): Form some kind of combined availabilities/messages from | 124 // TODO(justinlin): Form some kind of combined availabilities/messages from |
| 136 // SimpleFeatures. | 125 // SimpleFeatures. |
| 137 return features_[0]->GetAvailabilityMessage(result, type, url, context); | 126 return features_[0]->GetAvailabilityMessage(result, type, url, context); |
| 138 } | 127 } |
| 139 | 128 |
| 140 } // namespace extensions | 129 } // namespace extensions |
| OLD | NEW |