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

Side by Side Diff: chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.cc

Issue 1105413002: Avoid conversion of index to BookmarkNode pointer unnacessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 7 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 (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/browser/extensions/api/bookmarks/bookmark_api_helpers.h" 5 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h"
6 6
7 #include <math.h> // For floor() 7 #include <math.h> // For floor()
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 if (bookmarks::IsDescendantOf(node, client->managed_node()) || 129 if (bookmarks::IsDescendantOf(node, client->managed_node()) ||
130 bookmarks::IsDescendantOf(node, client->supervised_node())) { 130 bookmarks::IsDescendantOf(node, client->supervised_node())) {
131 *error = keys::kModifyManagedError; 131 *error = keys::kModifyManagedError;
132 return false; 132 return false;
133 } 133 }
134 if (node->is_folder() && !node->empty() && !recursive) { 134 if (node->is_folder() && !node->empty() && !recursive) {
135 *error = keys::kFolderNotEmptyError; 135 *error = keys::kFolderNotEmptyError;
136 return false; 136 return false;
137 } 137 }
138 138
139 const BookmarkNode* parent = node->parent(); 139 model->Remove(node);
140 model->Remove(parent, parent->GetIndexOf(node));
141 return true; 140 return true;
142 } 141 }
143 142
144 void GetMetaInfo(const BookmarkNode& node, 143 void GetMetaInfo(const BookmarkNode& node,
145 base::DictionaryValue* id_to_meta_info_map) { 144 base::DictionaryValue* id_to_meta_info_map) {
146 if (!node.IsVisible()) 145 if (!node.IsVisible())
147 return; 146 return;
148 147
149 const BookmarkNode::MetaInfoMap* meta_info = node.GetMetaInfoMap(); 148 const BookmarkNode::MetaInfoMap* meta_info = node.GetMetaInfoMap();
150 base::DictionaryValue* value = new base::DictionaryValue(); 149 base::DictionaryValue* value = new base::DictionaryValue();
151 if (meta_info) { 150 if (meta_info) {
152 BookmarkNode::MetaInfoMap::const_iterator itr; 151 BookmarkNode::MetaInfoMap::const_iterator itr;
153 for (itr = meta_info->begin(); itr != meta_info->end(); ++itr) { 152 for (itr = meta_info->begin(); itr != meta_info->end(); ++itr) {
154 value->SetStringWithoutPathExpansion(itr->first, itr->second); 153 value->SetStringWithoutPathExpansion(itr->first, itr->second);
155 } 154 }
156 } 155 }
157 id_to_meta_info_map->Set(base::Int64ToString(node.id()), value); 156 id_to_meta_info_map->Set(base::Int64ToString(node.id()), value);
158 157
159 if (node.is_folder()) { 158 if (node.is_folder()) {
160 for (int i = 0; i < node.child_count(); ++i) { 159 for (int i = 0; i < node.child_count(); ++i) {
161 GetMetaInfo(*(node.GetChild(i)), id_to_meta_info_map); 160 GetMetaInfo(*(node.GetChild(i)), id_to_meta_info_map);
162 } 161 }
163 } 162 }
164 } 163 }
165 164
166 } // namespace bookmark_api_helpers 165 } // namespace bookmark_api_helpers
167 } // namespace extensions 166 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698