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

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: 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
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 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 scoped_ptr<DictionaryValue> dictionary_value(new DictionaryValue());
53 if (!value) {
not at google - send to devlin 2013/02/15 16:33:34 link to bug
justinlin 2013/02/21 09:18:23 Done.
54 LOG(ERROR) << "Could not load features: " << debug_string << " "
53 << error_message; 55 << error_message;
not at google - send to devlin 2013/02/15 16:33:34 If we're going to clean up this stuff, something l
justinlin 2013/02/21 09:18:23 Done, except I can't seem to use PassAs<Dictionary
not at google - send to devlin 2013/02/21 16:20:09 Bummer, sorry about that.
54 CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string; 56 } else {
55 scoped_ptr<DictionaryValue> dictionary_value( 57 CHECK(value->IsType(Value::TYPE_DICTIONARY)) << debug_string;
56 static_cast<DictionaryValue*>(value)); 58 dictionary_value.reset(static_cast<DictionaryValue*>(value));
not at google - send to devlin 2013/02/15 16:33:34 (This means that the DictionaryValue created on li
justinlin 2013/02/21 09:18:23 True. It was mostly for safety in case another "if
59 }
57 return scoped_ptr<BaseFeatureProvider>( 60 return scoped_ptr<BaseFeatureProvider>(
58 new BaseFeatureProvider(*dictionary_value, factory)); 61 new BaseFeatureProvider(*dictionary_value, factory));
59 } 62 }
60 }; 63 };
61 64
62 bool ParseFeature(const DictionaryValue* value, 65 bool ParseFeature(const DictionaryValue* value,
63 const std::string& name, 66 const std::string& name,
64 SimpleFeature* feature) { 67 SimpleFeature* feature) {
65 feature->set_name(name); 68 feature->set_name(name);
66 feature->Parse(value); 69 feature->Parse(value);
67 70
68 if (feature->extension_types()->empty()) { 71 if (feature->extension_types()->empty()) {
69 LOG(ERROR) << name << ": Simple features must specify at least one " 72 LOG(ERROR) << name << ": Simple features must specify at least one "
70 << "value for extension_types."; 73 << "value for extension_types.";
71 return false; 74 return false;
72 } 75 }
73 76
74 if (!feature->GetContexts()->empty()) { 77 if (!feature->GetContexts()->empty()) {
75 LOG(ERROR) << name << ": Simple features do not support contexts."; 78 LOG(ERROR) << name << ": Simple features do not support contexts.";
76 return false; 79 return false;
77 } 80 }
78 81
79 return true; 82 return true;
80 } 83 }
81 84
82 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER; 85 base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
83 86
84 } // namespace 87 } // namespace
85 88
86 BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root, 89 BaseFeatureProvider::BaseFeatureProvider(const DictionaryValue& root,
87 FeatureFactory factory) 90 FeatureFactory factory)
88 : factory_(factory ? factory : 91 : factory_(factory ? factory :
89 static_cast<FeatureFactory>(&CreateFeature<SimpleFeature>)) { 92 static_cast<FeatureFactory>(&CreateFeature<SimpleFeature>)) {
90 for (DictionaryValue::Iterator iter(root); iter.HasNext(); iter.Advance()) { 93 for (DictionaryValue::Iterator iter(root); iter.HasNext(); iter.Advance()) {
91 if (iter.value().GetType() == Value::TYPE_DICTIONARY) { 94 if (iter.value().GetType() == Value::TYPE_DICTIONARY) {
92 linked_ptr<SimpleFeature> feature((*factory_)()); 95 linked_ptr<SimpleFeature> feature((*factory_)());
93 96
94 if (!ParseFeature(static_cast<const DictionaryValue*>(&iter.value()), 97 if (!ParseFeature(static_cast<const DictionaryValue*>(&iter.value()),
95 iter.key(), 98 iter.key(),
96 feature.get())) 99 feature.get()))
97 continue; 100 continue;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 160
158 Feature* BaseFeatureProvider::GetFeature(const std::string& name) { 161 Feature* BaseFeatureProvider::GetFeature(const std::string& name) {
159 FeatureMap::iterator iter = features_.find(name); 162 FeatureMap::iterator iter = features_.find(name);
160 if (iter != features_.end()) 163 if (iter != features_.end())
161 return iter->second.get(); 164 return iter->second.get();
162 else 165 else
163 return NULL; 166 return NULL;
164 } 167 }
165 168
166 } // namespace 169 } // namespace
OLDNEW
« chrome/common/extensions/extension.cc ('K') | « chrome/common/extensions/extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698