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

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

Issue 850603003: Add a 'nocompile' option to Extension feature files, and annotate all Devtools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 5 years, 11 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
« no previous file with comments | « chrome/test/data/extensions/api_test/bindings/nocompile/page.js ('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 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/base_feature_provider.h" 5 #include "extensions/common/features/base_feature_provider.h"
6 6
7 #include <stack> 7 #include <stack>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "extensions/common/extensions_client.h" 12 #include "extensions/common/extensions_client.h"
13 #include "extensions/common/features/complex_feature.h" 13 #include "extensions/common/features/complex_feature.h"
14 #include "extensions/common/features/simple_feature.h" 14 #include "extensions/common/features/simple_feature.h"
15 15
16 namespace extensions { 16 namespace extensions {
17 17
18 namespace { 18 namespace {
19 19
20 bool IsNocompile(const base::Value& value) {
21 bool nocompile = false;
22 const base::DictionaryValue* as_dict = NULL;
Marijn Kruisselbrink 2015/01/13 01:06:10 nullptr is recommended over NULL for new code
not at google - send to devlin 2015/01/13 01:14:52 Done. It irritated me having one instance of nullp
23 if (value.GetAsDictionary(&as_dict)) {
24 as_dict->GetBoolean("nocompile", &nocompile);
Marijn Kruisselbrink 2015/01/13 01:06:10 Would it make sense to DCHECK for the situation wh
not at google - send to devlin 2015/01/13 01:14:52 Eh... it adds 2 lines of code, and we don't check
Marijn Kruisselbrink 2015/01/13 01:19:59 Okay, makes sense. Yeah, it seems a bit arbitrary
25 } else {
26 NOTREACHED() << "nocompile only supported for simple features";
27 }
28 return nocompile;
29 }
30
20 bool ParseFeature(const base::DictionaryValue* value, 31 bool ParseFeature(const base::DictionaryValue* value,
21 const std::string& name, 32 const std::string& name,
22 SimpleFeature* feature) { 33 SimpleFeature* feature) {
23 feature->set_name(name); 34 feature->set_name(name);
24 std::string error = feature->Parse(value); 35 std::string error = feature->Parse(value);
25 if (!error.empty()) 36 if (!error.empty())
26 LOG(ERROR) << error; 37 LOG(ERROR) << error;
27 return error.empty(); 38 return error.empty();
28 } 39 }
29 40
30 } // namespace 41 } // namespace
31 42
32 BaseFeatureProvider::BaseFeatureProvider(const base::DictionaryValue& root, 43 BaseFeatureProvider::BaseFeatureProvider(const base::DictionaryValue& root,
33 FeatureFactory factory) 44 FeatureFactory factory)
34 : factory_(factory) { 45 : factory_(factory) {
35 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd(); 46 for (base::DictionaryValue::Iterator iter(root); !iter.IsAtEnd();
36 iter.Advance()) { 47 iter.Advance()) {
48 if (IsNocompile(iter.value())) {
49 continue;
50 }
51
37 if (iter.value().GetType() == base::Value::TYPE_DICTIONARY) { 52 if (iter.value().GetType() == base::Value::TYPE_DICTIONARY) {
38 linked_ptr<SimpleFeature> feature((*factory_)()); 53 linked_ptr<SimpleFeature> feature((*factory_)());
39 54
40 std::vector<std::string> split; 55 std::vector<std::string> split;
41 base::SplitString(iter.key(), '.', &split); 56 base::SplitString(iter.key(), '.', &split);
42 57
43 // Push parent features on the stack, starting with the current feature. 58 // Push parent features on the stack, starting with the current feature.
44 // If one of the features has "noparent" set, stop pushing features on 59 // If one of the features has "noparent" set, stop pushing features on
45 // the stack. The features will then be parsed in order, starting with 60 // the stack. The features will then be parsed in order, starting with
46 // the farthest parent that is either top level or has "noparent" set. 61 // the farthest parent that is either top level or has "noparent" set.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 std::vector<Feature*> result; 181 std::vector<Feature*> result;
167 result.reserve(std::distance(first_child, after_children)); 182 result.reserve(std::distance(first_child, after_children));
168 for (FeatureMap::const_iterator it = first_child; it != after_children; 183 for (FeatureMap::const_iterator it = first_child; it != after_children;
169 ++it) { 184 ++it) {
170 result.push_back(it->second.get()); 185 result.push_back(it->second.get());
171 } 186 }
172 return result; 187 return result;
173 } 188 }
174 189
175 } // namespace extensions 190 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/bindings/nocompile/page.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698