| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 BookmarkModel::BookmarkModel(Profile* profile) | 113 BookmarkModel::BookmarkModel(Profile* profile) |
| 114 : profile_(profile), | 114 : profile_(profile), |
| 115 loaded_(false), | 115 loaded_(false), |
| 116 file_changed_(false), | 116 file_changed_(false), |
| 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 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 BookmarkModel::~BookmarkModel() { | 130 BookmarkModel::~BookmarkModel() { |
| 131 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 131 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 132 BookmarkModelBeingDeleted(this)); | 132 BookmarkModelBeingDeleted(this)); |
| 133 | 133 |
| 134 if (store_) { | 134 if (store_) { |
| 135 // The store maintains a reference back to us. We need to tell it we're gone | 135 // 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. | 136 // so that it doesn't try and invoke a method back on us again. |
| 137 store_->BookmarkModelDeleted(); | 137 store_->BookmarkModelDeleted(); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 // static | 141 // static |
| 142 void BookmarkModel::RegisterUserPrefs(PrefService* prefs) { | 142 void BookmarkModel::RegisterUserPrefs(PrefService* prefs) { |
| 143 prefs->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, new ListValue, | 143 prefs->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, new ListValue, |
| 144 PrefService::SYNCABLE_PREF); | 144 PrefService::SYNCABLE_PREF); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void BookmarkModel::Cleanup() { |
| 148 if (loaded_) |
| 149 return; |
| 150 |
| 151 // See comment in Profile shutdown code where this is invoked for details. |
| 152 loaded_signal_.Signal(); |
| 153 } |
| 154 |
| 147 void BookmarkModel::Load() { | 155 void BookmarkModel::Load() { |
| 148 if (store_.get()) { | 156 if (store_.get()) { |
| 149 // If the store is non-null, it means Load was already invoked. Load should | 157 // If the store is non-null, it means Load was already invoked. Load should |
| 150 // only be invoked once. | 158 // only be invoked once. |
| 151 NOTREACHED(); | 159 NOTREACHED(); |
| 152 return; | 160 return; |
| 153 } | 161 } |
| 154 | 162 |
| 155 expanded_state_tracker_.reset(new BookmarkExpandedStateTracker( | 163 expanded_state_tracker_.reset(new BookmarkExpandedStateTracker( |
| 156 profile_, prefs::kBookmarkEditorExpandedNodes)); | 164 profile_, prefs::kBookmarkEditorExpandedNodes)); |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 file_changed_ = true; | 811 file_changed_ = true; |
| 804 } | 812 } |
| 805 | 813 |
| 806 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 814 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
| 807 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 815 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 808 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); | 816 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 809 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); | 817 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); |
| 810 return new BookmarkLoadDetails(bb_node, other_node, synced_node, | 818 return new BookmarkLoadDetails(bb_node, other_node, synced_node, |
| 811 new BookmarkIndex(profile_), next_node_id_); | 819 new BookmarkIndex(profile_), next_node_id_); |
| 812 } | 820 } |
| OLD | NEW |