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

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

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Push parent features on the stack, starting with the current feature. 43 // Push parent features on the stack, starting with the current feature.
44 // If one of the features has "noparent" set, stop pushing features on 44 // 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 45 // 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. 46 // the farthest parent that is either top level or has "noparent" set.
47 std::stack<std::pair<std::string, const base::DictionaryValue*> > 47 std::stack<std::pair<std::string, const base::DictionaryValue*> >
48 parse_stack; 48 parse_stack;
49 while (!split.empty()) { 49 while (!split.empty()) {
50 std::string parent_name = JoinString(split, '.'); 50 std::string parent_name = JoinString(split, '.');
51 split.pop_back(); 51 split.pop_back();
52 if (root.HasKey(parent_name)) { 52 if (root.HasKey(parent_name)) {
53 const base::DictionaryValue* parent = NULL; 53 const base::DictionaryValue* parent = nullptr;
54 CHECK(root.GetDictionaryWithoutPathExpansion(parent_name, &parent)); 54 CHECK(root.GetDictionaryWithoutPathExpansion(parent_name, &parent));
55 parse_stack.push(std::make_pair(parent_name, parent)); 55 parse_stack.push(std::make_pair(parent_name, parent));
56 bool no_parent = false; 56 bool no_parent = false;
57 parent->GetBoolean("noparent", &no_parent); 57 parent->GetBoolean("noparent", &no_parent);
58 if (no_parent) 58 if (no_parent)
59 break; 59 break;
60 } 60 }
61 } 61 }
62 62
63 CHECK(!parse_stack.empty()); 63 CHECK(!parse_stack.empty());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // now. 128 // now.
129 } 129 }
130 return feature_names_; 130 return feature_names_;
131 } 131 }
132 132
133 Feature* BaseFeatureProvider::GetFeature(const std::string& name) const { 133 Feature* BaseFeatureProvider::GetFeature(const std::string& name) const {
134 FeatureMap::const_iterator iter = features_.find(name); 134 FeatureMap::const_iterator iter = features_.find(name);
135 if (iter != features_.end()) 135 if (iter != features_.end())
136 return iter->second.get(); 136 return iter->second.get();
137 else 137 else
138 return NULL; 138 return nullptr;
139 } 139 }
140 140
141 Feature* BaseFeatureProvider::GetParent(Feature* feature) const { 141 Feature* BaseFeatureProvider::GetParent(Feature* feature) const {
142 CHECK(feature); 142 CHECK(feature);
143 if (feature->no_parent()) 143 if (feature->no_parent())
144 return NULL; 144 return nullptr;
145 145
146 std::vector<std::string> split; 146 std::vector<std::string> split;
147 base::SplitString(feature->name(), '.', &split); 147 base::SplitString(feature->name(), '.', &split);
148 if (split.size() < 2) 148 if (split.size() < 2)
149 return NULL; 149 return nullptr;
150 split.pop_back(); 150 split.pop_back();
151 return GetFeature(JoinString(split, '.')); 151 return GetFeature(JoinString(split, '.'));
152 } 152 }
153 153
154 // Children of a given API are named starting with parent.name()+".", which 154 // Children of a given API are named starting with parent.name()+".", which
155 // means they'll be contiguous in the features_ std::map. 155 // means they'll be contiguous in the features_ std::map.
156 std::vector<Feature*> BaseFeatureProvider::GetChildren(const Feature& parent) 156 std::vector<Feature*> BaseFeatureProvider::GetChildren(const Feature& parent)
157 const { 157 const {
158 std::string prefix = parent.name() + "."; 158 std::string prefix = parent.name() + ".";
159 const FeatureMap::const_iterator first_child = features_.lower_bound(prefix); 159 const FeatureMap::const_iterator first_child = features_.lower_bound(prefix);
160 160
161 // All children have names before (parent.name() + ('.'+1)). 161 // All children have names before (parent.name() + ('.'+1)).
162 ++prefix[prefix.size() - 1]; 162 ++prefix[prefix.size() - 1];
163 const FeatureMap::const_iterator after_children = 163 const FeatureMap::const_iterator after_children =
164 features_.lower_bound(prefix); 164 features_.lower_bound(prefix);
165 165
166 std::vector<Feature*> result; 166 std::vector<Feature*> result;
167 result.reserve(std::distance(first_child, after_children)); 167 result.reserve(std::distance(first_child, after_children));
168 for (FeatureMap::const_iterator it = first_child; it != after_children; 168 for (FeatureMap::const_iterator it = first_child; it != after_children;
169 ++it) { 169 ++it) {
170 result.push_back(it->second.get()); 170 result.push_back(it->second.get());
171 } 171 }
172 return result; 172 return result;
173 } 173 }
174 174
175 } // namespace extensions 175 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698