| 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/json_feature_provider.h" | 5 #include "extensions/common/features/json_feature_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <stack> | 9 #include <stack> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (parse_error) | 109 if (parse_error) |
| 110 continue; | 110 continue; |
| 111 | 111 |
| 112 AddFeature(iter.key(), std::move(feature)); | 112 AddFeature(iter.key(), std::move(feature)); |
| 113 } else if (iter.value().GetType() == base::Value::TYPE_LIST) { | 113 } else if (iter.value().GetType() == base::Value::TYPE_LIST) { |
| 114 // This is a complex feature. | 114 // This is a complex feature. |
| 115 const base::ListValue* list = | 115 const base::ListValue* list = |
| 116 static_cast<const base::ListValue*>(&iter.value()); | 116 static_cast<const base::ListValue*>(&iter.value()); |
| 117 CHECK_GT(list->GetSize(), 0UL); | 117 CHECK_GT(list->GetSize(), 0UL); |
| 118 | 118 |
| 119 std::vector<Feature*> features; | 119 std::unique_ptr<ComplexFeature::FeatureList> features( |
| 120 new ComplexFeature::FeatureList()); |
| 120 | 121 |
| 121 // Parse and add all SimpleFeatures from the list. | 122 // Parse and add all SimpleFeatures from the list. |
| 122 for (const auto& entry : *list) { | 123 for (const auto& entry : *list) { |
| 123 base::DictionaryValue* dict; | 124 base::DictionaryValue* dict; |
| 124 if (!entry->GetAsDictionary(&dict)) { | 125 if (!entry->GetAsDictionary(&dict)) { |
| 125 LOG(ERROR) << iter.key() << ": Feature rules must be dictionaries."; | 126 LOG(ERROR) << iter.key() << ": Feature rules must be dictionaries."; |
| 126 continue; | 127 continue; |
| 127 } | 128 } |
| 128 | 129 |
| 129 std::unique_ptr<SimpleFeature> feature((*factory_)()); | 130 std::unique_ptr<SimpleFeature> feature((*factory_)()); |
| 130 if (!ParseFeature(dict, iter.key(), feature.get())) | 131 if (!ParseFeature(dict, iter.key(), feature.get())) |
| 131 continue; | 132 continue; |
| 132 | 133 |
| 133 features.push_back(feature.release()); | 134 features->push_back(std::move(feature)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 std::unique_ptr<ComplexFeature> feature(new ComplexFeature(&features)); | 137 std::unique_ptr<ComplexFeature> feature( |
| 138 new ComplexFeature(std::move(features))); |
| 137 feature->set_name(iter.key()); | 139 feature->set_name(iter.key()); |
| 138 | 140 |
| 139 AddFeature(iter.key(), feature.release()); | 141 AddFeature(iter.key(), std::move(feature)); |
| 140 } else { | 142 } else { |
| 141 LOG(ERROR) << iter.key() << ": Feature description must be dictionary or" | 143 LOG(ERROR) << iter.key() << ": Feature description must be dictionary or" |
| 142 << " list of dictionaries."; | 144 << " list of dictionaries."; |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 | 148 |
| 147 JSONFeatureProvider::~JSONFeatureProvider() {} | 149 JSONFeatureProvider::~JSONFeatureProvider() {} |
| 148 | 150 |
| 149 } // namespace extensions | 151 } // namespace extensions |
| OLD | NEW |