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

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: rebased 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) ||
198 parent == root_node()) {
198 NOTREACHED(); 199 NOTREACHED();
199 return; 200 return;
200 } 201 }
201 RemoveAndDeleteNode(AsMutable(parent->GetChild(index))); 202 RemoveAndDeleteNode(AsMutable(parent->GetChild(index)));
202 } 203 }
203 204
204 void BookmarkModel::Move(const BookmarkNode* node, 205 void BookmarkModel::Move(const BookmarkNode* node,
205 const BookmarkNode* new_parent, 206 const BookmarkNode* new_parent,
206 int index) { 207 int index) {
207 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) || 208 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) ||
208 is_root(new_parent) || is_permanent_node(node)) { 209 new_parent == root_node() || is_permanent_node(node)) {
209 NOTREACHED(); 210 NOTREACHED();
210 return; 211 return;
211 } 212 }
212 213
213 if (new_parent->HasAncestor(node)) { 214 if (new_parent->HasAncestor(node)) {
214 // Can't make an ancestor of the node be a child of the node. 215 // Can't make an ancestor of the node be a child of the node.
215 NOTREACHED(); 216 NOTREACHED();
216 return; 217 return;
217 } 218 }
218 219
(...skipping 18 matching lines...) Expand all
237 238
238 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 239 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
239 BookmarkNodeMoved(this, old_parent, old_index, 240 BookmarkNodeMoved(this, old_parent, old_index,
240 new_parent, index)); 241 new_parent, index));
241 } 242 }
242 243
243 void BookmarkModel::Copy(const BookmarkNode* node, 244 void BookmarkModel::Copy(const BookmarkNode* node,
244 const BookmarkNode* new_parent, 245 const BookmarkNode* new_parent,
245 int index) { 246 int index) {
246 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) || 247 if (!loaded_ || !node || !IsValidIndex(new_parent, index, true) ||
247 is_root(new_parent) || is_permanent_node(node)) { 248 new_parent == root_node() || is_permanent_node(node)) {
248 NOTREACHED(); 249 NOTREACHED();
249 return; 250 return;
250 } 251 }
251 252
252 if (new_parent->HasAncestor(node)) { 253 if (new_parent->HasAncestor(node)) {
253 // Can't make an ancestor of the node be a child of the node. 254 // Can't make an ancestor of the node be a child of the node.
254 NOTREACHED(); 255 NOTREACHED();
255 return; 256 return;
256 } 257 }
257 258
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 394 }
394 395
395 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) { 396 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) {
396 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. 397 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate.
397 return GetNodeByID(&root_, id); 398 return GetNodeByID(&root_, id);
398 } 399 }
399 400
400 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent, 401 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent,
401 int index, 402 int index,
402 const string16& title) { 403 const string16& title) {
403 if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) { 404 if (!loaded_ || parent == root_node() || !IsValidIndex(parent, index, true)) {
404 // Can't add to the root. 405 // Can't add to the root.
405 NOTREACHED(); 406 NOTREACHED();
406 return NULL; 407 return NULL;
407 } 408 }
408 409
409 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); 410 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL());
410 new_node->set_date_folder_modified(Time::Now()); 411 new_node->set_date_folder_modified(Time::Now());
411 new_node->set_title(title); 412 new_node->set_title(title);
412 new_node->set_type(BookmarkNode::FOLDER); 413 new_node->set_type(BookmarkNode::FOLDER);
413 414
414 return AddNode(AsMutable(parent), index, new_node, false); 415 return AddNode(AsMutable(parent), index, new_node, false);
415 } 416 }
416 417
417 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, 418 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent,
418 int index, 419 int index,
419 const string16& title, 420 const string16& title,
420 const GURL& url) { 421 const GURL& url) {
421 return AddURLWithCreationTime(parent, index, title, url, Time::Now()); 422 return AddURLWithCreationTime(parent, index, title, url, Time::Now());
422 } 423 }
423 424
424 const BookmarkNode* BookmarkModel::AddURLWithCreationTime( 425 const BookmarkNode* BookmarkModel::AddURLWithCreationTime(
425 const BookmarkNode* parent, 426 const BookmarkNode* parent,
426 int index, 427 int index,
427 const string16& title, 428 const string16& title,
428 const GURL& url, 429 const GURL& url,
429 const Time& creation_time) { 430 const Time& creation_time) {
430 if (!loaded_ || !url.is_valid() || is_root(parent) || 431 if (!loaded_ || !url.is_valid() || parent == root_node() ||
431 !IsValidIndex(parent, index, true)) { 432 !IsValidIndex(parent, index, true)) {
432 NOTREACHED(); 433 NOTREACHED();
433 return NULL; 434 return NULL;
434 } 435 }
435 436
436 bool was_bookmarked = IsBookmarked(url); 437 bool was_bookmarked = IsBookmarked(url);
437 438
438 SetDateFolderModified(parent, creation_time); 439 SetDateFolderModified(parent, creation_time);
439 440
440 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url); 441 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url);
441 new_node->set_title(title); 442 new_node->set_title(title);
442 new_node->set_date_added(creation_time); 443 new_node->set_date_added(creation_time);
443 new_node->set_type(BookmarkNode::URL); 444 new_node->set_type(BookmarkNode::URL);
444 445
445 { 446 {
446 // Only hold the lock for the duration of the insert. 447 // Only hold the lock for the duration of the insert.
447 base::AutoLock url_lock(url_lock_); 448 base::AutoLock url_lock(url_lock_);
448 nodes_ordered_by_url_set_.insert(new_node); 449 nodes_ordered_by_url_set_.insert(new_node);
449 } 450 }
450 451
451 return AddNode(AsMutable(parent), index, new_node, was_bookmarked); 452 return AddNode(AsMutable(parent), index, new_node, was_bookmarked);
452 } 453 }
453 454
454 void BookmarkModel::SortChildren(const BookmarkNode* parent) { 455 void BookmarkModel::SortChildren(const BookmarkNode* parent) {
455 if (!parent || !parent->is_folder() || is_root(parent) || 456 if (!parent || !parent->is_folder() || parent == root_node() ||
456 parent->child_count() <= 1) { 457 parent->child_count() <= 1) {
457 return; 458 return;
458 } 459 }
459 460
460 UErrorCode error = U_ZERO_ERROR; 461 UErrorCode error = U_ZERO_ERROR;
461 scoped_ptr<icu::Collator> collator( 462 scoped_ptr<icu::Collator> collator(
462 icu::Collator::createInstance( 463 icu::Collator::createInstance(
463 icu::Locale(g_browser_process->GetApplicationLocale().c_str()), 464 icu::Locale(g_browser_process->GetApplicationLocale().c_str()),
464 error)); 465 error));
465 if (U_FAILURE(error)) 466 if (U_FAILURE(error))
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 826
826 void BookmarkModel::SetFileChanged() { 827 void BookmarkModel::SetFileChanged() {
827 file_changed_ = true; 828 file_changed_ = true;
828 } 829 }
829 830
830 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 831 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
831 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 832 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
832 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); 833 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE);
833 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); 834 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED);
834 return new BookmarkLoadDetails(bb_node, other_node, synced_node, 835 return new BookmarkLoadDetails(bb_node, other_node, synced_node,
835 new BookmarkIndex(profile()), next_node_id_); 836 new BookmarkIndex(profile_), next_node_id_);
836 } 837 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698