| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/common/extensions/simple_feature_provider.h" | 5 #include "chrome/common/extensions/simple_feature_provider.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "chrome/common/extensions/manifest_feature.h" | 9 #include "chrome/common/extensions/manifest_feature.h" |
| 10 #include "chrome/common/extensions/permission_feature.h" | 10 #include "chrome/common/extensions/permission_feature.h" |
| 11 #include "grit/common_resources.h" | 11 #include "grit/common_resources.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const bool kAllowTrailingComma = false; | |
| 19 | |
| 20 template<class FeatureClass> | 18 template<class FeatureClass> |
| 21 Feature* CreateFeature() { | 19 Feature* CreateFeature() { |
| 22 return new FeatureClass(); | 20 return new FeatureClass(); |
| 23 } | 21 } |
| 24 | 22 |
| 25 struct Static { | 23 struct Static { |
| 26 Static() | 24 Static() |
| 27 : manifest_features( | 25 : manifest_features( |
| 28 LoadProvider("manifest", | 26 LoadProvider("manifest", |
| 29 &CreateFeature<ManifestFeature>, | 27 &CreateFeature<ManifestFeature>, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 scoped_ptr<SimpleFeatureProvider> LoadProvider( | 39 scoped_ptr<SimpleFeatureProvider> LoadProvider( |
| 42 const std::string& debug_string, | 40 const std::string& debug_string, |
| 43 SimpleFeatureProvider::FeatureFactory factory, | 41 SimpleFeatureProvider::FeatureFactory factory, |
| 44 int resource_id) { | 42 int resource_id) { |
| 45 std::string manifest_features = | 43 std::string manifest_features = |
| 46 ResourceBundle::GetSharedInstance().GetRawDataResource( | 44 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 47 resource_id).as_string(); | 45 resource_id).as_string(); |
| 48 int error_code = 0; | 46 int error_code = 0; |
| 49 std::string error_message; | 47 std::string error_message; |
| 50 Value* value = base::JSONReader::ReadAndReturnError( | 48 Value* value = base::JSONReader::ReadAndReturnError( |
| 51 manifest_features, kAllowTrailingComma, &error_code, &error_message); | 49 manifest_features, base::JSON_PARSE_RFC, |
| 50 &error_code, &error_message); |
| 52 CHECK(value) << "Could not load features: " << debug_string << " " | 51 CHECK(value) << "Could not load features: " << debug_string << " " |
| 53 << error_message; | 52 << error_message; |
| 54 CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string; | 53 CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string; |
| 55 scoped_ptr<DictionaryValue> dictionary_value( | 54 scoped_ptr<DictionaryValue> dictionary_value( |
| 56 static_cast<DictionaryValue*>(value)); | 55 static_cast<DictionaryValue*>(value)); |
| 57 return scoped_ptr<SimpleFeatureProvider>( | 56 return scoped_ptr<SimpleFeatureProvider>( |
| 58 new SimpleFeatureProvider(dictionary_value.get(), factory)); | 57 new SimpleFeatureProvider(dictionary_value.get(), factory)); |
| 59 } | 58 } |
| 60 }; | 59 }; |
| 61 | 60 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 115 |
| 117 Feature* SimpleFeatureProvider::GetFeature(const std::string& name) { | 116 Feature* SimpleFeatureProvider::GetFeature(const std::string& name) { |
| 118 FeatureMap::iterator iter = features_.find(name); | 117 FeatureMap::iterator iter = features_.find(name); |
| 119 if (iter != features_.end()) | 118 if (iter != features_.end()) |
| 120 return iter->second.get(); | 119 return iter->second.get(); |
| 121 else | 120 else |
| 122 return NULL; | 121 return NULL; |
| 123 } | 122 } |
| 124 | 123 |
| 125 } // namespace | 124 } // namespace |
| OLD | NEW |