Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1075)

Side by Side Diff: chrome/common/extensions/features/base_feature_provider.cc

Issue 12255041: Extension BaseFeatureProvider minor cleanups. Don't crash in release mode if we failed to parse a p… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kalman@ comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/features/base_feature_provider.h" 5 #include "chrome/common/extensions/features/base_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/features/complex_feature.h" 9 #include "chrome/common/extensions/features/complex_feature.h"
10 #include "chrome/common/extensions/features/manifest_feature.h" 10 #include "chrome/common/extensions/features/manifest_feature.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 scoped_ptr<BaseFeatureProvider> manifest_features; 36 scoped_ptr<BaseFeatureProvider> manifest_features;
37 scoped_ptr<BaseFeatureProvider> permission_features; 37 scoped_ptr<BaseFeatureProvider> permission_features;
38 38
39 private: 39 private:
40 scoped_ptr<BaseFeatureProvider> LoadProvider( 40 scoped_ptr<BaseFeatureProvider> LoadProvider(
41 const std::string& debug_string, 41 const std::string& debug_string,
42 BaseFeatureProvider::FeatureFactory factory, 42 BaseFeatureProvider::FeatureFactory factory,
43 int resource_id) { 43 int resource_id) {
44 std::string manifest_features = 44 const std::string& features_file =
45 ResourceBundle::GetSharedInstance().GetRawDataResource( 45 ResourceBundle::GetSharedInstance().GetRawDataResource(
46 resource_id).as_string(); 46 resource_id).as_string();
47 int error_code = 0; 47 int error_code = 0;
48 std::string error_message; 48 std::string error_message;
49 Value* value = base::JSONReader::ReadAndReturnError( 49 scoped_ptr<Value> value(base::JSONReader::ReadAndReturnError(
50 manifest_features, base::JSON_PARSE_RFC, 50 features_file, base::JSON_PARSE_RFC,
51 &error_code, &error_message); 51 &error_code, &error_message));
52 CHECK(value) << "Could not load features: " << debug_string << " " 52 DCHECK(value) << "Could not load features: " << debug_string << " "
53 << error_message; 53 << error_message;
54 CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string; 54 scoped_ptr<DictionaryValue> value_as_dict;
55 scoped_ptr<DictionaryValue> dictionary_value( 55 if (value) {
56 static_cast<DictionaryValue*>(value)); 56 CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string;
57 return scoped_ptr<BaseFeatureProvider>( 57 value_as_dict.reset(static_cast<DictionaryValue*>(value.release()));
58 new BaseFeatureProvider(*dictionary_value, factory)); 58 } else {
59 // http://crbug.com/176381
60 value_as_dict.reset(new DictionaryValue());
61 }
62 return make_scoped_ptr(new BaseFeatureProvider(*value_as_dict, factory));
59 } 63 }
60 }; 64 };
61 65
62 bool ParseFeature(const DictionaryValue* value, 66 bool ParseFeature(const DictionaryValue* value,
63 const std::string& name, 67 const std::string& name,
64 SimpleFeature* feature) { 68 SimpleFeature* feature) {
65 feature->set_name(name); 69 feature->set_name(name);
66 feature->Parse(value); 70 feature->Parse(value);
67 71
68 if (feature->extension_types()->empty()) { 72 if (feature->extension_types()->empty()) {
69 LOG(ERROR) << name << ": Simple features must specify at least one " 73 LOG(ERROR) << name << ": Simple features must specify at least one "
70 << "value for extension_types."; 74 << "value for extension_types.";
71 return false; 75 return false;
72 } 76 }
73 77
74 if (!feature->GetContexts()->empty()) { 78 if (!feature->GetContexts()->empty()) {
75 LOG(ERROR) << name << ": Simple features do not support contexts."; 79 LOG(ERROR) << name << ": Simple features do not support contexts.";
76 return false; 80 return false;
77 } 81 }
78 82
79 return true; 83 return true;
80 } 84 }
81 85
82 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; 86 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
83 87
84 } // namespace 88 } // namespace
85 89
86 BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root, 90 BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
87 FeatureFactory factory) 91 FeatureFactory factory)
88 : factory_(factory ? factory : 92 : factory_(factory ? factory :
89 static_cast<FeatureFactory>(&CreateFeature<SimpleFeature>)) { 93 static_cast<FeatureFactory>(&CreateFeature<SimpleFeature>)) {
90 for (DictionaryValue::Iterator iter(root); iter.HasNext(); iter.Advance()) { 94 for (DictionaryValue::Iterator iter(root); iter.HasNext(); iter.Advance()) {
91 if (iter.value().GetType() == Value::TYPE_DICTIONARY) { 95 if (iter.value().GetType() == Value::TYPE_DICTIONARY) {
92 linked_ptr<SimpleFeature> feature((*factory_)()); 96 linked_ptr<SimpleFeature> feature((*factory_)());
93 97
94 if (!ParseFeature(static_cast<const DictionaryValue*>(&iter.value()), 98 if (!ParseFeature(static_cast<const DictionaryValue*>(&iter.value()),
95 iter.key(), 99 iter.key(),
96 feature.get())) 100 feature.get()))
97 continue; 101 continue;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 161
158 Feature* BaseFeatureProvider::GetFeature(const std::string& name) { 162 Feature* BaseFeatureProvider::GetFeature(const std::string& name) {
159 FeatureMap::iterator iter = features_.find(name); 163 FeatureMap::iterator iter = features_.find(name);
160 if (iter != features_.end()) 164 if (iter != features_.end())
161 return iter->second.get(); 165 return iter->second.get();
162 else 166 else
163 return NULL; 167 return NULL;
164 } 168 }
165 169
166 } // namespace 170 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698