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

Side by Side Diff: chrome/browser/bookmarks/bookmark_model.cc

Issue 7530024: bookmarks: Simplify is_permanent_node() implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use is_root_node Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bookmarks/bookmark_model.h" 5 #include "chrome/browser/bookmarks/bookmark_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 187 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
188 BookmarkImportBeginning(this)); 188 BookmarkImportBeginning(this));
189 } 189 }
190 190
191 void BookmarkModel::EndImportMode() { 191 void BookmarkModel::EndImportMode() {
192 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 192 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
193 BookmarkImportEnding(this)); 193 BookmarkImportEnding(this));
194 } 194 }
195 195
196 void BookmarkModel::Remove(const BookmarkNode* parent, int index) { 196 void BookmarkModel::Remove(const BookmarkNode* parent, int index) {
197 if (!loaded_ || !IsValidIndex(parent, index, false) || is_root(parent)) { 197 if (!loaded_ || !IsValidIndex(parent, index, false) || is_root_node(parent)) {
198 NOTREACHED(); 198 NOTREACHED();
199 return; 199 return;
200 } 200 }
201 RemoveAndDeleteNode(AsMutable(parent->GetChild(index))); 201 RemoveAndDeleteNode(AsMutable(parent->GetChild(index)));
202 } 202 }
203 203
204 void BookmarkModel::Move(const BookmarkNode* node, 204 void BookmarkModel::Move(const BookmarkNode* node,
205 const BookmarkNode* new_parent, 205 const BookmarkNode* new_parent,
206 int index) { 206 int index) {
207 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) || 207 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) ||
208 is_root(new_parent) || is_permanent_node(node)) { 208 is_root_node(new_parent) || is_permanent_node(node)) {
209 NOTREACHED(); 209 NOTREACHED();
210 return; 210 return;
211 } 211 }
212 212
213 if (new_parent->HasAncestor(node)) { 213 if (new_parent->HasAncestor(node)) {
214 // Can't make an ancestor of the node be a child of the node. 214 // Can't make an ancestor of the node be a child of the node.
215 NOTREACHED(); 215 NOTREACHED();
216 return; 216 return;
217 } 217 }
218 218
(...skipping 18 matching lines...) Expand all
237 237
238 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 238 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
239 BookmarkNodeMoved(this, old_parent, old_index, 239 BookmarkNodeMoved(this, old_parent, old_index,
240 new_parent, index)); 240 new_parent, index));
241 } 241 }
242 242
243 void BookmarkModel::Copy(const BookmarkNode* node, 243 void BookmarkModel::Copy(const BookmarkNode* node,
244 const BookmarkNode* new_parent, 244 const BookmarkNode* new_parent,
245 int index) { 245 int index) {
246 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) || 246 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) ||
247 is_root(new_parent) || is_permanent_node(node)) { 247 is_root_node(new_parent) || is_permanent_node(node)) {
248 NOTREACHED(); 248 NOTREACHED();
249 return; 249 return;
250 } 250 }
251 251
252 if (new_parent->HasAncestor(node)) { 252 if (new_parent->HasAncestor(node)) {
253 // Can't make an ancestor of the node be a child of the node. 253 // Can't make an ancestor of the node be a child of the node.
254 NOTREACHED(); 254 NOTREACHED();
255 return; 255 return;
256 } 256 }
257 257
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 393 }
394 394
395 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) { 395 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) {
396 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. 396 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
397 return GetNodeByID(&root_, id); 397 return GetNodeByID(&root_, id);
398 } 398 }
399 399
400 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent, 400 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent,
401 int index, 401 int index,
402 const string16& title) { 402 const string16& title) {
403 if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) { 403 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) {
404 // Can't add to the root. 404 // Can't add to the root.
405 NOTREACHED(); 405 NOTREACHED();
406 return NULL; 406 return NULL;
407 } 407 }
408 408
409 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); 409 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL());
410 new_node->set_date_folder_modified(Time::Now()); 410 new_node->set_date_folder_modified(Time::Now());
411 new_node->set_title(title); 411 new_node->set_title(title);
412 new_node->set_type(BookmarkNode::FOLDER); 412 new_node->set_type(BookmarkNode::FOLDER);
413 413
414 return AddNode(AsMutable(parent), index, new_node, false); 414 return AddNode(AsMutable(parent), index, new_node, false);
415 } 415 }
416 416
417 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, 417 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent,
418 int index, 418 int index,
419 const string16& title, 419 const string16& title,
420 const GURL& url) { 420 const GURL& url) {
421 return AddURLWithCreationTime(parent, index, title, url, Time::Now()); 421 return AddURLWithCreationTime(parent, index, title, url, Time::Now());
422 } 422 }
423 423
424 const BookmarkNode* BookmarkModel::AddURLWithCreationTime( 424 const BookmarkNode* BookmarkModel::AddURLWithCreationTime(
425 const BookmarkNode* parent, 425 const BookmarkNode* parent,
426 int index, 426 int index,
427 const string16& title, 427 const string16& title,
428 const GURL& url, 428 const GURL& url,
429 const Time& creation_time) { 429 const Time& creation_time) {
430 if (!loaded_ || !url.is_valid() || is_root(parent) || 430 if (!loaded_ || !url.is_valid() || is_root_node(parent) ||
431 !IsValidIndex(parent, index, true)) { 431 !IsValidIndex(parent, index, true)) {
432 NOTREACHED(); 432 NOTREACHED();
433 return NULL; 433 return NULL;
434 } 434 }
435 435
436 bool was_bookmarked = IsBookmarked(url); 436 bool was_bookmarked = IsBookmarked(url);
437 437
438 SetDateFolderModified(parent, creation_time); 438 SetDateFolderModified(parent, creation_time);
439 439
440 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url); 440 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url);
441 new_node->set_title(title); 441 new_node->set_title(title);
442 new_node->set_date_added(creation_time); 442 new_node->set_date_added(creation_time);
443 new_node->set_type(BookmarkNode::URL); 443 new_node->set_type(BookmarkNode::URL);
444 444
445 { 445 {
446 // Only hold the lock for the duration of the insert. 446 // Only hold the lock for the duration of the insert.
447 base::AutoLock url_lock(url_lock_); 447 base::AutoLock url_lock(url_lock_);
448 nodes_ordered_by_url_set_.insert(new_node); 448 nodes_ordered_by_url_set_.insert(new_node);
449 } 449 }
450 450
451 return AddNode(AsMutable(parent), index, new_node, was_bookmarked); 451 return AddNode(AsMutable(parent), index, new_node, was_bookmarked);
452 } 452 }
453 453
454 void BookmarkModel::SortChildren(const BookmarkNode* parent) { 454 void BookmarkModel::SortChildren(const BookmarkNode* parent) {
455 if (!parent || !parent->is_folder() || is_root(parent) || 455 if (!parent || !parent->is_folder() || is_root_node(parent) ||
456 parent->child_count() <= 1) { 456 parent->child_count() <= 1) {
457 return; 457 return;
458 } 458 }
459 459
460 UErrorCode error = U_ZERO_ERROR; 460 UErrorCode error = U_ZERO_ERROR;
461 scoped_ptr<icu::Collator> collator( 461 scoped_ptr<icu::Collator> collator(
462 icu::Collator::createInstance( 462 icu::Collator::createInstance(
463 icu::Locale(g_browser_process->GetApplicationLocale().c_str()), 463 icu::Locale(g_browser_process->GetApplicationLocale().c_str()),
464 error)); 464 error));
465 if (U_FAILURE(error)) 465 if (U_FAILURE(error))
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 825
826 void BookmarkModel::SetFileChanged() { 826 void BookmarkModel::SetFileChanged() {
827 file_changed_ = true; 827 file_changed_ = true;
828 } 828 }
829 829
830 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 830 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
831 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 831 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
832 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); 832 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE);
833 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); 833 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED);
834 return new BookmarkLoadDetails(bb_node, other_node, synced_node, 834 return new BookmarkLoadDetails(bb_node, other_node, synced_node,
835 new BookmarkIndex(profile()), next_node_id_); 835 new BookmarkIndex(profile_), next_node_id_);
836 } 836 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698