| OLD | NEW |
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 root_(GURL()), | 117 root_(GURL()), |
| 118 bookmark_bar_node_(NULL), | 118 bookmark_bar_node_(NULL), |
| 119 other_node_(NULL), | 119 other_node_(NULL), |
| 120 synced_node_(NULL), | 120 synced_node_(NULL), |
| 121 next_node_id_(1), | 121 next_node_id_(1), |
| 122 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), | 122 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), |
| 123 loaded_signal_(true, false) { | 123 loaded_signal_(true, false) { |
| 124 if (!profile_) { | 124 if (!profile_) { |
| 125 // Profile is null during testing. | 125 // Profile is null during testing. |
| 126 DoneLoading(CreateLoadDetails()); | 126 DoneLoading(CreateLoadDetails()); |
| 127 } else { |
| 128 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 129 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 127 } | 130 } |
| 128 } | 131 } |
| 129 | 132 |
| 130 BookmarkModel::~BookmarkModel() { | 133 BookmarkModel::~BookmarkModel() { |
| 131 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 134 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 132 BookmarkModelBeingDeleted(this)); | 135 BookmarkModelBeingDeleted(this)); |
| 133 | 136 |
| 134 if (store_) { | 137 if (store_) { |
| 135 // The store maintains a reference back to us. We need to tell it we're gone | 138 // The store maintains a reference back to us. We need to tell it we're gone |
| 136 // so that it doesn't try and invoke a method back on us again. | 139 // so that it doesn't try and invoke a method back on us again. |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 BookmarkNode* node = AsMutable(nodes[i]); | 788 BookmarkNode* node = AsMutable(nodes[i]); |
| 786 node->InvalidateFavicon(); | 789 node->InvalidateFavicon(); |
| 787 CancelPendingFaviconLoadRequests(node); | 790 CancelPendingFaviconLoadRequests(node); |
| 788 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 791 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 789 BookmarkNodeFaviconChanged(this, node)); | 792 BookmarkNodeFaviconChanged(this, node)); |
| 790 } | 793 } |
| 791 } | 794 } |
| 792 break; | 795 break; |
| 793 } | 796 } |
| 794 | 797 |
| 798 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 799 std::string* pref = Details<std::string>(details).ptr(); |
| 800 if (*pref == prefs::kShowBookmarkBar) { |
| 801 Source<Profile> source(profile_); |
| 802 NotificationService::current()->Notify( |
| 803 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 804 source, |
| 805 NotificationService::NoDetails()); |
| 806 } else { |
| 807 NOTREACHED(); |
| 808 } |
| 809 break; |
| 810 } |
| 811 |
| 795 default: | 812 default: |
| 796 NOTREACHED(); | 813 NOTREACHED(); |
| 797 break; | 814 break; |
| 798 } | 815 } |
| 799 } | 816 } |
| 800 | 817 |
| 801 void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) { | 818 void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) { |
| 802 // NOTE: this is called with url_lock_ already held. As such, this doesn't | 819 // NOTE: this is called with url_lock_ already held. As such, this doesn't |
| 803 // explicitly grab the lock. | 820 // explicitly grab the lock. |
| 804 if (node->is_url()) | 821 if (node->is_url()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 815 file_changed_ = true; | 832 file_changed_ = true; |
| 816 } | 833 } |
| 817 | 834 |
| 818 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 835 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
| 819 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 836 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 820 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); | 837 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 821 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); | 838 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); |
| 822 return new BookmarkLoadDetails(bb_node, other_node, synced_node, | 839 return new BookmarkLoadDetails(bb_node, other_node, synced_node, |
| 823 new BookmarkIndex(profile_), next_node_id_); | 840 new BookmarkIndex(profile_), next_node_id_); |
| 824 } | 841 } |
| OLD | NEW |