Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / common / features / json_feature_provider_source.cc
blob5b9ee168378f0ee4b719455f8337425c42e39591
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
3 // found in the LICENSE file.
5 #include "extensions/common/features/json_feature_provider_source.h"
7 #include "base/json/json_reader.h"
8 #include "base/logging.h"
9 #include "ui/base/resource/resource_bundle.h"
11 namespace extensions {
13 JSONFeatureProviderSource::JSONFeatureProviderSource(const std::string& name)
14 : name_(name) {
17 JSONFeatureProviderSource::~JSONFeatureProviderSource() {
20 void JSONFeatureProviderSource::LoadJSON(int resource_id) {
21 const std::string& features_file = ResourceBundle::GetSharedInstance()
22 .GetRawDataResource(resource_id)
23 .as_string();
24 int error_code = 0;
25 std::string error_message;
26 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError(
27 features_file, base::JSON_PARSE_RFC, &error_code, &error_message));
28 DCHECK(value) << "Could not load features: " << name_ << " " << error_message;
30 scoped_ptr<base::DictionaryValue> value_as_dict;
31 if (value) {
32 CHECK(value->IsType(base::Value::TYPE_DICTIONARY)) << name_;
33 value_as_dict.reset(static_cast<base::DictionaryValue*>(value.release()));
34 } else {
35 // There was some error loading the features file.
36 // http://crbug.com/176381
37 value_as_dict.reset(new base::DictionaryValue());
40 // Ensure there are no key collisions.
41 for (base::DictionaryValue::Iterator iter(*value_as_dict); !iter.IsAtEnd();
42 iter.Advance()) {
43 if (dictionary_.GetWithoutPathExpansion(iter.key(), NULL))
44 LOG(FATAL) << "Key " << iter.key() << " is defined in " << name_
45 << " JSON feature files more than once.";
48 // Merge.
49 dictionary_.MergeDictionary(value_as_dict.get());
52 } // namespace extensions