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_source.h" | 5 #include "extensions/common/features/json_feature_provider_source.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const base::StringPiece features_file = | 24 const base::StringPiece features_file = |
25 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 25 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
26 int error_code = 0; | 26 int error_code = 0; |
27 std::string error_message; | 27 std::string error_message; |
28 std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( | 28 std::unique_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( |
29 features_file, base::JSON_PARSE_RFC, &error_code, &error_message)); | 29 features_file, base::JSON_PARSE_RFC, &error_code, &error_message)); |
30 DCHECK(value) << "Could not load features: " << name_ << " " << error_message; | 30 DCHECK(value) << "Could not load features: " << name_ << " " << error_message; |
31 | 31 |
32 std::unique_ptr<base::DictionaryValue> value_as_dict; | 32 std::unique_ptr<base::DictionaryValue> value_as_dict; |
33 if (value) { | 33 if (value) { |
34 CHECK(value->IsType(base::Value::TYPE_DICTIONARY)) << name_; | 34 CHECK(value->IsType(base::Value::Type::DICTIONARY)) << name_; |
35 value_as_dict = base::DictionaryValue::From(std::move(value)); | 35 value_as_dict = base::DictionaryValue::From(std::move(value)); |
36 } else { | 36 } else { |
37 // There was some error loading the features file. | 37 // There was some error loading the features file. |
38 // http://crbug.com/176381 | 38 // http://crbug.com/176381 |
39 value_as_dict.reset(new base::DictionaryValue()); | 39 value_as_dict.reset(new base::DictionaryValue()); |
40 } | 40 } |
41 | 41 |
42 // Ensure there are no key collisions. | 42 // Ensure there are no key collisions. |
43 for (base::DictionaryValue::Iterator iter(*value_as_dict); !iter.IsAtEnd(); | 43 for (base::DictionaryValue::Iterator iter(*value_as_dict); !iter.IsAtEnd(); |
44 iter.Advance()) { | 44 iter.Advance()) { |
45 if (dictionary_.GetWithoutPathExpansion(iter.key(), NULL)) | 45 if (dictionary_.GetWithoutPathExpansion(iter.key(), NULL)) |
46 LOG(FATAL) << "Key " << iter.key() << " is defined in " << name_ | 46 LOG(FATAL) << "Key " << iter.key() << " is defined in " << name_ |
47 << " JSON feature files more than once."; | 47 << " JSON feature files more than once."; |
48 } | 48 } |
49 | 49 |
50 // Merge. | 50 // Merge. |
51 dictionary_.MergeDictionary(value_as_dict.get()); | 51 dictionary_.MergeDictionary(value_as_dict.get()); |
52 } | 52 } |
53 | 53 |
54 } // namespace extensions | 54 } // namespace extensions |
OLD | NEW |