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

Side by Side Diff: components/bookmarks/managed/managed_bookmarks_tracker.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 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 "components/bookmarks/managed/managed_bookmarks_tracker.h" 5 #include "components/bookmarks/managed/managed_bookmarks_tracker.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 model_->AddURL(folder, folder_index, title, url); 165 model_->AddURL(folder, folder_index, title, url);
166 } 166 }
167 } 167 }
168 168
169 // The |folder_index| index of |folder| has been updated, so advance it. 169 // The |folder_index| index of |folder| has been updated, so advance it.
170 ++folder_index; 170 ++folder_index;
171 } 171 }
172 172
173 // Remove any extra children of |folder| that haven't been reused. 173 // Remove any extra children of |folder| that haven't been reused.
174 while (folder->child_count() != folder_index) 174 while (folder->child_count() != folder_index)
175 model_->Remove(folder, folder_index); 175 model_->Remove(folder->GetChild(folder_index));
176 } 176 }
177 177
178 // static 178 // static
179 bool ManagedBookmarksTracker::LoadBookmark(const base::ListValue* list, 179 bool ManagedBookmarksTracker::LoadBookmark(const base::ListValue* list,
180 size_t index, 180 size_t index,
181 base::string16* title, 181 base::string16* title,
182 GURL* url, 182 GURL* url,
183 const base::ListValue** children) { 183 const base::ListValue** children) {
184 std::string spec; 184 std::string spec;
185 *url = GURL(); 185 *url = GURL();
186 *children = NULL; 186 *children = NULL;
187 const base::DictionaryValue* dict = NULL; 187 const base::DictionaryValue* dict = NULL;
188 if (!list->GetDictionary(index, &dict) || 188 if (!list->GetDictionary(index, &dict) ||
189 !dict->GetString(kName, title) || 189 !dict->GetString(kName, title) ||
190 (!dict->GetString(kUrl, &spec) && 190 (!dict->GetString(kUrl, &spec) &&
191 !dict->GetList(kChildren, children))) { 191 !dict->GetList(kChildren, children))) {
192 // Should never happen after policy validation. 192 // Should never happen after policy validation.
193 NOTREACHED(); 193 NOTREACHED();
194 return false; 194 return false;
195 } 195 }
196 if (!*children) { 196 if (!*children) {
197 *url = GURL(spec); 197 *url = GURL(spec);
198 DCHECK(url->is_valid()); 198 DCHECK(url->is_valid());
199 } 199 }
200 return true; 200 return true;
201 } 201 }
202 202
203 } // namespace policy 203 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698