| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/gfx/png_decoder.h" | 8 #include "base/gfx/png_decoder.h" |
| 9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } // anonymous namespace | 29 } // anonymous namespace |
| 30 | 30 |
| 31 // BookmarkNode --------------------------------------------------------------- | 31 // BookmarkNode --------------------------------------------------------------- |
| 32 | 32 |
| 33 BookmarkNode::BookmarkNode(const GURL& url) | 33 BookmarkNode::BookmarkNode(const GURL& url) |
| 34 : url_(url) { | 34 : url_(url) { |
| 35 Initialize(0); | 35 Initialize(0); |
| 36 } | 36 } |
| 37 | 37 |
| 38 BookmarkNode::BookmarkNode(int64 id, const GURL& url) | 38 BookmarkNode::BookmarkNode(int64 id, const GURL& url) |
| 39 : url_(url){ | 39 : url_(url) { |
| 40 Initialize(id); | 40 Initialize(id); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void BookmarkNode::Initialize(int64 id) { | 43 void BookmarkNode::Initialize(int64 id) { |
| 44 id_ = id; | 44 id_ = id; |
| 45 loaded_favicon_ = false; | 45 loaded_favicon_ = false; |
| 46 favicon_load_handle_ = 0; | 46 favicon_load_handle_ = 0; |
| 47 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR; | 47 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR; |
| 48 date_added_ = Time::Now(); | 48 date_added_ = Time::Now(); |
| 49 } | 49 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 71 date_added_ = entry.date_added; | 71 date_added_ = entry.date_added; |
| 72 date_group_modified_ = entry.date_group_modified; | 72 date_group_modified_ = entry.date_group_modified; |
| 73 SetTitle(entry.title); | 73 SetTitle(entry.title); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // BookmarkModel -------------------------------------------------------------- | 76 // BookmarkModel -------------------------------------------------------------- |
| 77 | 77 |
| 78 namespace { | 78 namespace { |
| 79 | 79 |
| 80 // Comparator used when sorting bookmarks. Folders are sorted first, then | 80 // Comparator used when sorting bookmarks. Folders are sorted first, then |
| 81 // bookmarks. | 81 // bookmarks. |
| 82 class SortComparator : public std::binary_function<const BookmarkNode*, | 82 class SortComparator : public std::binary_function<const BookmarkNode*, |
| 83 const BookmarkNode*, | 83 const BookmarkNode*, |
| 84 bool> { | 84 bool> { |
| 85 public: | 85 public: |
| 86 explicit SortComparator(icu::Collator* collator) : collator_(collator) { } | 86 explicit SortComparator(icu::Collator* collator) : collator_(collator) { } |
| 87 | 87 |
| 88 // Returns true if lhs preceeds rhs. | 88 // Returns true if lhs preceeds rhs. |
| 89 bool operator() (const BookmarkNode* n1, const BookmarkNode* n2) { | 89 bool operator() (const BookmarkNode* n1, const BookmarkNode* n2) { |
| 90 if (n1->GetType() == n2->GetType()) { | 90 if (n1->GetType() == n2->GetType()) { |
| 91 // Types are the same, compare the names. | 91 // Types are the same, compare the names. |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 int index = parent->IndexOfChild(node.get()); | 503 int index = parent->IndexOfChild(node.get()); |
| 504 parent->Remove(index); | 504 parent->Remove(index); |
| 505 history::URLsStarredDetails details(false); | 505 history::URLsStarredDetails details(false); |
| 506 { | 506 { |
| 507 AutoLock url_lock(url_lock_); | 507 AutoLock url_lock(url_lock_); |
| 508 RemoveNode(node.get(), &details.changed_urls); | 508 RemoveNode(node.get(), &details.changed_urls); |
| 509 | 509 |
| 510 // RemoveNode adds an entry to changed_urls for each node of type URL. As we | 510 // RemoveNode adds an entry to changed_urls for each node of type URL. As we |
| 511 // allow duplicates we need to remove any entries that are still bookmarked. | 511 // allow duplicates we need to remove any entries that are still bookmarked. |
| 512 for (std::set<GURL>::iterator i = details.changed_urls.begin(); | 512 for (std::set<GURL>::iterator i = details.changed_urls.begin(); |
| 513 i != details.changed_urls.end(); ){ | 513 i != details.changed_urls.end(); ) { |
| 514 if (IsBookmarkedNoLock(*i)) { | 514 if (IsBookmarkedNoLock(*i)) { |
| 515 // When we erase the iterator pointing at the erasee is | 515 // When we erase the iterator pointing at the erasee is |
| 516 // invalidated, so using i++ here within the "erase" call is | 516 // invalidated, so using i++ here within the "erase" call is |
| 517 // important as it advances the iterator before passing the | 517 // important as it advances the iterator before passing the |
| 518 // old value through to erase. | 518 // old value through to erase. |
| 519 details.changed_urls.erase(i++); | 519 details.changed_urls.erase(i++); |
| 520 } else { | 520 } else { |
| 521 ++i; | 521 ++i; |
| 522 } | 522 } |
| 523 } | 523 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 720 } |
| 721 | 721 |
| 722 void BookmarkModel::SetFileChanged() { | 722 void BookmarkModel::SetFileChanged() { |
| 723 file_changed_ = true; | 723 file_changed_ = true; |
| 724 } | 724 } |
| 725 | 725 |
| 726 BookmarkStorage::LoadDetails* BookmarkModel::CreateLoadDetails() { | 726 BookmarkStorage::LoadDetails* BookmarkModel::CreateLoadDetails() { |
| 727 BookmarkNode* bb_node = CreateBookmarkNode(); | 727 BookmarkNode* bb_node = CreateBookmarkNode(); |
| 728 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); | 728 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); |
| 729 return new BookmarkStorage::LoadDetails( | 729 return new BookmarkStorage::LoadDetails( |
| 730 bb_node, other_folder_node, new BookmarkIndex(), next_node_id_); | 730 bb_node, other_folder_node, new BookmarkIndex(profile()), next_node_id_); |
| 731 } | 731 } |
| OLD | NEW |