[email protected] | c47f86fa | 2014-04-30 02:20:18 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 5 | #include "components/bookmarks/browser/bookmark_model.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 4e425be4 | 2011-01-15 06:56:09 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <functional> |
Gyuyoung Kim | 6afb508 | 2018-01-19 13:35:57 | [diff] [blame] | 9 | #include <memory> |
Mikel Astiz | 55b3fe20 | 2017-11-08 20:54:50 | [diff] [blame] | 10 | #include <string> |
dcheng | 5160635 | 2015-12-26 21:16:23 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 4e425be4 | 2011-01-15 06:56:09 | [diff] [blame] | 12 | |
[email protected] | bbdd298 | 2011-10-08 18:14:24 | [diff] [blame] | 13 | #include "base/bind.h" |
| 14 | #include "base/bind_helpers.h" |
Hans Wennborg | df87046c | 2020-04-28 11:06:24 | [diff] [blame] | 15 | #include "base/check_op.h" |
Pauline Leitao | 44f5a81 | 2019-07-30 10:49:51 | [diff] [blame] | 16 | #include "base/guid.h" |
[email protected] | 9a08fe8 | 2013-04-23 05:06:05 | [diff] [blame] | 17 | #include "base/i18n/string_compare.h" |
[email protected] | 996dbe8 | 2014-05-12 12:32:18 | [diff] [blame] | 18 | #include "base/macros.h" |
pkotwicz | ca240dd | 2015-07-09 16:15:32 | [diff] [blame] | 19 | #include "base/metrics/histogram_macros.h" |
Hans Wennborg | df87046c | 2020-04-28 11:06:24 | [diff] [blame] | 20 | #include "base/notreached.h" |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 21 | #include "base/strings/string_util.h" |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 22 | #include "components/bookmarks/browser/bookmark_expanded_state_tracker.h" |
Mikel Astiz | 1cc07d6df | 2020-07-27 08:59:50 | [diff] [blame^] | 23 | #include "components/bookmarks/browser/bookmark_load_details.h" |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 24 | #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 25 | #include "components/bookmarks/browser/bookmark_node_data.h" |
| 26 | #include "components/bookmarks/browser/bookmark_storage.h" |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 27 | #include "components/bookmarks/browser/bookmark_undo_delegate.h" |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 28 | #include "components/bookmarks/browser/bookmark_utils.h" |
Scott Violet | a772b27d | 2018-05-31 23:23:21 | [diff] [blame] | 29 | #include "components/bookmarks/browser/model_loader.h" |
mattreynolds | 25e9a31 | 2016-12-14 21:52:13 | [diff] [blame] | 30 | #include "components/bookmarks/browser/titled_url_index.h" |
| 31 | #include "components/bookmarks/browser/titled_url_match.h" |
mattreynolds | 191b8872 | 2016-12-13 19:25:32 | [diff] [blame] | 32 | #include "components/bookmarks/browser/typed_count_sorter.h" |
Scott Violet | 8aa6d5760 | 2018-04-25 15:46:21 | [diff] [blame] | 33 | #include "components/bookmarks/browser/url_and_title.h" |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 34 | #include "components/bookmarks/browser/url_index.h" |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 35 | #include "components/bookmarks/common/bookmark_constants.h" |
[email protected] | 7627e0b4 | 2014-04-17 17:20:53 | [diff] [blame] | 36 | #include "components/favicon_base/favicon_types.h" |
thakis | fe8fa0a | 2017-02-23 19:46:36 | [diff] [blame] | 37 | #include "components/strings/grit/components_strings.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 38 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 65baa22 | 2012-08-30 15:43:51 | [diff] [blame] | 39 | #include "ui/gfx/favicon_size.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 41 | using base::Time; |
tfarina | a0ec34e | 2015-01-12 18:46:48 | [diff] [blame] | 42 | |
| 43 | namespace bookmarks { |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 44 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 45 | namespace { |
| 46 | |
| 47 | // Helper to get a mutable bookmark node. |
[email protected] | 7b084b0 | 2011-07-08 16:06:48 | [diff] [blame] | 48 | BookmarkNode* AsMutable(const BookmarkNode* node) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 49 | return const_cast<BookmarkNode*>(node); |
| 50 | } |
| 51 | |
[email protected] | 996dbe8 | 2014-05-12 12:32:18 | [diff] [blame] | 52 | // Comparator used when sorting permanent nodes. Nodes that are initially |
| 53 | // visible are sorted before nodes that are initially hidden. |
vmpstr | 3abe330 | 2016-03-09 19:38:19 | [diff] [blame] | 54 | class VisibilityComparator { |
[email protected] | 996dbe8 | 2014-05-12 12:32:18 | [diff] [blame] | 55 | public: |
| 56 | explicit VisibilityComparator(BookmarkClient* client) : client_(client) {} |
| 57 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 58 | // Returns true if |n1| precedes |n2|. |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 59 | bool operator()(const std::unique_ptr<BookmarkNode>& n1, |
| 60 | const std::unique_ptr<BookmarkNode>& n2) { |
| 61 | DCHECK(n1->is_permanent_node()); |
| 62 | DCHECK(n2->is_permanent_node()); |
Mikel Astiz | af1a45f | 2020-03-10 21:15:30 | [diff] [blame] | 63 | bool n1_visible = client_->IsPermanentNodeVisibleWhenEmpty(n1->type()); |
| 64 | bool n2_visible = client_->IsPermanentNodeVisibleWhenEmpty(n2->type()); |
[email protected] | 996dbe8 | 2014-05-12 12:32:18 | [diff] [blame] | 65 | return n1_visible != n2_visible && n1_visible; |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | BookmarkClient* client_; |
| 70 | }; |
| 71 | |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 72 | // Comparator used when sorting bookmarks. Folders are sorted first, then |
[email protected] | 2c685cc2 | 2009-08-28 00:17:44 | [diff] [blame] | 73 | // bookmarks. |
vmpstr | 3abe330 | 2016-03-09 19:38:19 | [diff] [blame] | 74 | class SortComparator { |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 75 | public: |
[email protected] | a48f87d | 2012-10-09 18:06:33 | [diff] [blame] | 76 | explicit SortComparator(icu::Collator* collator) : collator_(collator) {} |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 77 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 78 | // Returns true if |n1| precedes |n2|. |
| 79 | bool operator()(const std::unique_ptr<BookmarkNode>& n1, |
| 80 | const std::unique_ptr<BookmarkNode>& n2) { |
[email protected] | 037db00 | 2009-10-19 20:06:08 | [diff] [blame] | 81 | if (n1->type() == n2->type()) { |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 82 | // Types are the same, compare the names. |
| 83 | if (!collator_) |
[email protected] | 440b37b2 | 2010-08-30 05:31:40 | [diff] [blame] | 84 | return n1->GetTitle() < n2->GetTitle(); |
[email protected] | 9a08fe8 | 2013-04-23 05:06:05 | [diff] [blame] | 85 | return base::i18n::CompareString16WithCollator( |
estade | 1274f88 | 2015-04-11 05:13:35 | [diff] [blame] | 86 | *collator_, n1->GetTitle(), n2->GetTitle()) == UCOL_LESS; |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 87 | } |
| 88 | // Types differ, sort such that folders come first. |
| 89 | return n1->is_folder(); |
| 90 | } |
| 91 | |
| 92 | private: |
[email protected] | b5b2385a | 2009-08-18 05:12:29 | [diff] [blame] | 93 | icu::Collator* collator_; |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 94 | }; |
| 95 | |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 96 | // Delegate that does nothing. |
| 97 | class EmptyUndoDelegate : public BookmarkUndoDelegate { |
| 98 | public: |
| 99 | EmptyUndoDelegate() {} |
| 100 | ~EmptyUndoDelegate() override {} |
| 101 | |
| 102 | private: |
| 103 | // BookmarkUndoDelegate: |
| 104 | void SetUndoProvider(BookmarkUndoProvider* provider) override {} |
| 105 | void OnBookmarkNodeRemoved(BookmarkModel* model, |
| 106 | const BookmarkNode* parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 107 | size_t index, |
dcheng | acd3f52 | 2016-04-21 22:30:41 | [diff] [blame] | 108 | std::unique_ptr<BookmarkNode> node) override {} |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 109 | |
| 110 | DISALLOW_COPY_AND_ASSIGN(EmptyUndoDelegate); |
| 111 | }; |
| 112 | |
Mikel Astiz | e163439 | 2020-02-25 17:12:40 | [diff] [blame] | 113 | #if DCHECK_IS_ON() |
| 114 | void AddGuidsToIndexRecursive(const BookmarkNode* node, |
| 115 | std::set<std::string>* guid_index) { |
| 116 | bool success = guid_index->insert(node->guid()).second; |
| 117 | DCHECK(success); |
| 118 | |
| 119 | // Recurse through children. |
| 120 | for (size_t i = node->children().size(); i > 0; --i) |
| 121 | AddGuidsToIndexRecursive(node->children()[i - 1].get(), guid_index); |
| 122 | } |
| 123 | #endif // DCHECK_IS_ON() |
| 124 | |
[email protected] | bc770a03 | 2011-12-12 17:35:30 | [diff] [blame] | 125 | } // namespace |
[email protected] | 97fdd16 | 2011-12-03 20:50:12 | [diff] [blame] | 126 | |
[email protected] | 97fdd16 | 2011-12-03 20:50:12 | [diff] [blame] | 127 | // BookmarkModel -------------------------------------------------------------- |
| 128 | |
dcheng | acd3f52 | 2016-04-21 22:30:41 | [diff] [blame] | 129 | BookmarkModel::BookmarkModel(std::unique_ptr<BookmarkClient> client) |
sdefresne | 070a510 | 2016-02-01 13:42:14 | [diff] [blame] | 130 | : client_(std::move(client)), |
Pauline Leitao | 44f5a81 | 2019-07-30 10:49:51 | [diff] [blame] | 131 | owned_root_(std::make_unique<BookmarkNode>(/*id=*/0, |
Mikel Astiz | 0bf1b2d1 | 2020-07-02 14:18:51 | [diff] [blame] | 132 | BookmarkNode::kRootNodeGuid, |
Pauline Leitao | 44f5a81 | 2019-07-30 10:49:51 | [diff] [blame] | 133 | GURL())), |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 134 | root_(owned_root_.get()), |
François Degros | d6e2d7dd | 2017-11-22 05:37:02 | [diff] [blame] | 135 | observers_(base::ObserverListPolicy::EXISTING_ONLY), |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 136 | empty_undo_delegate_(std::make_unique<EmptyUndoDelegate>()) { |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 137 | DCHECK(client_); |
sdefresne | 070a510 | 2016-02-01 13:42:14 | [diff] [blame] | 138 | client_->Init(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 141 | BookmarkModel::~BookmarkModel() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 142 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 143 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 144 | for (BookmarkModelObserver& observer : observers_) |
| 145 | observer.BookmarkModelBeingDeleted(this); |
[email protected] | 3de6fd34 | 2008-09-05 02:44:51 | [diff] [blame] | 146 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 147 | if (store_) { |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 148 | // The store maintains a reference back to us. We need to tell it we're gone |
| 149 | // so that it doesn't try and invoke a method back on us again. |
| 150 | store_->BookmarkModelDeleted(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
[email protected] | afecfb7 | 2013-04-18 17:17:33 | [diff] [blame] | 154 | void BookmarkModel::Load( |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 155 | PrefService* pref_service, |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 156 | const base::FilePath& profile_path, |
| 157 | const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, |
| 158 | const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 159 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 160 | // If the store is non-null, it means Load was already invoked. Load should |
| 161 | // only be invoked once. |
| 162 | DCHECK(!store_); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 163 | |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 164 | expanded_state_tracker_ = |
| 165 | std::make_unique<BookmarkExpandedStateTracker>(this, pref_service); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 166 | |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 167 | store_ = std::make_unique<BookmarkStorage>(this, profile_path, |
| 168 | io_task_runner.get()); |
Scott Violet | a772b27d | 2018-05-31 23:23:21 | [diff] [blame] | 169 | // Creating ModelLoader schedules the load on |io_task_runner|. |
tzik | 1d5d38a7 | 2018-07-27 04:40:10 | [diff] [blame] | 170 | model_loader_ = ModelLoader::Create( |
Scott Violet | a772b27d | 2018-05-31 23:23:21 | [diff] [blame] | 171 | profile_path.Append(kBookmarksFileName), io_task_runner.get(), |
| 172 | std::make_unique<BookmarkLoadDetails>(client_.get()), |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 173 | base::BindOnce(&BookmarkModel::DoneLoading, AsWeakPtr())); |
| 174 | } |
| 175 | |
| 176 | scoped_refptr<ModelLoader> BookmarkModel::model_loader() { |
| 177 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 178 | return model_loader_; |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | 125b23418 | 2011-07-08 19:54:41 | [diff] [blame] | 181 | void BookmarkModel::AddObserver(BookmarkModelObserver* observer) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 182 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 125b23418 | 2011-07-08 19:54:41 | [diff] [blame] | 183 | observers_.AddObserver(observer); |
| 184 | } |
| 185 | |
| 186 | void BookmarkModel::RemoveObserver(BookmarkModelObserver* observer) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 187 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 125b23418 | 2011-07-08 19:54:41 | [diff] [blame] | 188 | observers_.RemoveObserver(observer); |
| 189 | } |
| 190 | |
[email protected] | b68a817 | 2012-02-17 00:25:18 | [diff] [blame] | 191 | void BookmarkModel::BeginExtensiveChanges() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 192 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | b68a817 | 2012-02-17 00:25:18 | [diff] [blame] | 193 | if (++extensive_changes_ == 1) { |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 194 | for (BookmarkModelObserver& observer : observers_) |
| 195 | observer.ExtensiveBookmarkChangesBeginning(this); |
[email protected] | b68a817 | 2012-02-17 00:25:18 | [diff] [blame] | 196 | } |
[email protected] | 125b23418 | 2011-07-08 19:54:41 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | b68a817 | 2012-02-17 00:25:18 | [diff] [blame] | 199 | void BookmarkModel::EndExtensiveChanges() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 200 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | b68a817 | 2012-02-17 00:25:18 | [diff] [blame] | 201 | --extensive_changes_; |
| 202 | DCHECK_GE(extensive_changes_, 0); |
| 203 | if (extensive_changes_ == 0) { |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 204 | for (BookmarkModelObserver& observer : observers_) |
| 205 | observer.ExtensiveBookmarkChangesEnded(this); |
[email protected] | b68a817 | 2012-02-17 00:25:18 | [diff] [blame] | 206 | } |
[email protected] | 125b23418 | 2011-07-08 19:54:41 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | 346453a | 2014-03-12 10:14:37 | [diff] [blame] | 209 | void BookmarkModel::BeginGroupedChanges() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 210 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 211 | for (BookmarkModelObserver& observer : observers_) |
| 212 | observer.GroupedBookmarkChangesBeginning(this); |
[email protected] | 346453a | 2014-03-12 10:14:37 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void BookmarkModel::EndGroupedChanges() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 216 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 217 | for (BookmarkModelObserver& observer : observers_) |
| 218 | observer.GroupedBookmarkChangesEnded(this); |
[email protected] | 346453a | 2014-03-12 10:14:37 | [diff] [blame] | 219 | } |
| 220 | |
deepak.m1 | 3931267 | 2015-05-04 16:29:43 | [diff] [blame] | 221 | void BookmarkModel::Remove(const BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 222 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
tfarina | 16f92ed4 | 2015-06-12 13:54:36 | [diff] [blame] | 223 | DCHECK(loaded_); |
deepak.m1 | 3931267 | 2015-05-04 16:29:43 | [diff] [blame] | 224 | DCHECK(node); |
tfarina | 16f92ed4 | 2015-06-12 13:54:36 | [diff] [blame] | 225 | DCHECK(!is_root_node(node)); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 226 | const BookmarkNode* parent = node->parent(); |
| 227 | DCHECK(parent); |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 228 | size_t index = size_t{parent->GetIndexOf(node)}; |
| 229 | DCHECK_NE(size_t{-1}, index); |
Mikel Astiz | 32dcf91d | 2019-11-12 19:20:36 | [diff] [blame] | 230 | |
| 231 | // Removing a permanent node is problematic and can cause crashes elsewhere |
| 232 | // that are difficult to trace back. |
| 233 | CHECK(!is_permanent_node(node)) << "for type " << node->type(); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 234 | |
| 235 | for (BookmarkModelObserver& observer : observers_) |
| 236 | observer.OnWillRemoveBookmarks(this, parent, index, node); |
| 237 | |
| 238 | std::set<GURL> removed_urls; |
| 239 | std::unique_ptr<BookmarkNode> owned_node = |
| 240 | url_index_->Remove(AsMutable(node), &removed_urls); |
Mikel Astiz | b810f7ac | 2019-11-06 16:57:00 | [diff] [blame] | 241 | RemoveNodeFromIndexRecursive(owned_node.get()); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 242 | |
| 243 | if (store_) |
| 244 | store_->ScheduleSave(); |
| 245 | |
| 246 | for (BookmarkModelObserver& observer : observers_) |
| 247 | observer.BookmarkNodeRemoved(this, parent, index, node, removed_urls); |
| 248 | |
| 249 | undo_delegate()->OnBookmarkNodeRemoved(this, parent, index, |
| 250 | std::move(owned_node)); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 5cd942208a | 2014-06-11 06:16:46 | [diff] [blame] | 253 | void BookmarkModel::RemoveAllUserBookmarks() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 254 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 9109f8a1 | 2013-06-12 18:07:48 | [diff] [blame] | 255 | std::set<GURL> removed_urls; |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 256 | struct RemoveNodeData { |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 257 | const BookmarkNode* parent; |
| 258 | int index; |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 259 | std::unique_ptr<BookmarkNode> node; |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 260 | }; |
| 261 | std::vector<RemoveNodeData> removed_node_data_list; |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 262 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 263 | for (BookmarkModelObserver& observer : observers_) |
| 264 | observer.OnWillRemoveAllUserBookmarks(this); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 265 | |
[email protected] | 323dbf7 | 2013-03-30 17:08:33 | [diff] [blame] | 266 | BeginExtensiveChanges(); |
| 267 | // Skip deleting permanent nodes. Permanent bookmark nodes are the root and |
| 268 | // its immediate children. For removing all non permanent nodes just remove |
| 269 | // all children of non-root permanent nodes. |
| 270 | { |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 271 | for (const auto& permanent_node : root_->children()) { |
| 272 | if (!client_->CanBeEditedByUser(permanent_node.get())) |
[email protected] | 043a76d | 2014-06-05 16:36:24 | [diff] [blame] | 273 | continue; |
| 274 | |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 275 | for (size_t j = permanent_node->children().size(); j > 0; --j) { |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 276 | std::unique_ptr<BookmarkNode> node = url_index_->Remove( |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 277 | permanent_node->children()[j - 1].get(), &removed_urls); |
Mikel Astiz | b810f7ac | 2019-11-06 16:57:00 | [diff] [blame] | 278 | RemoveNodeFromIndexRecursive(node.get()); |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 279 | removed_node_data_list.push_back( |
| 280 | {permanent_node.get(), j - 1, std::move(node)}); |
[email protected] | 323dbf7 | 2013-03-30 17:08:33 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | EndExtensiveChanges(); |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 285 | if (store_) |
[email protected] | 323dbf7 | 2013-03-30 17:08:33 | [diff] [blame] | 286 | store_->ScheduleSave(); |
| 287 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 288 | for (BookmarkModelObserver& observer : observers_) |
| 289 | observer.BookmarkAllUserNodesRemoved(this, removed_urls); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 290 | |
| 291 | BeginGroupedChanges(); |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 292 | for (auto& removed_node_data : removed_node_data_list) { |
| 293 | undo_delegate()->OnBookmarkNodeRemoved(this, removed_node_data.parent, |
| 294 | removed_node_data.index, |
| 295 | std::move(removed_node_data.node)); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 296 | } |
| 297 | EndGroupedChanges(); |
[email protected] | 5cd942208a | 2014-06-11 06:16:46 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 300 | void BookmarkModel::Move(const BookmarkNode* node, |
| 301 | const BookmarkNode* new_parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 302 | size_t index) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 303 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Peter Kasting | a71b6c8 | 2019-05-31 18:41:33 | [diff] [blame] | 304 | DCHECK(loaded_); |
| 305 | DCHECK(node); |
| 306 | DCHECK(IsValidIndex(new_parent, index, true)); |
| 307 | DCHECK(!is_root_node(new_parent)); |
| 308 | DCHECK(!is_permanent_node(node)); |
| 309 | DCHECK(!new_parent->HasAncestor(node)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 310 | |
[email protected] | 2d48ee84 | 2011-03-08 23:27:29 | [diff] [blame] | 311 | const BookmarkNode* old_parent = node->parent(); |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 312 | size_t old_index = old_parent->GetIndexOf(node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 313 | |
| 314 | if (old_parent == new_parent && |
| 315 | (index == old_index || index == old_index + 1)) { |
| 316 | // Node is already in this position, nothing to do. |
| 317 | return; |
| 318 | } |
| 319 | |
[email protected] | 9e58364 | 2012-12-05 02:48:32 | [diff] [blame] | 320 | SetDateFolderModified(new_parent, Time::Now()); |
| 321 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 322 | if (old_parent == new_parent && index > old_index) |
| 323 | index--; |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 324 | |
| 325 | BookmarkNode* mutable_old_parent = AsMutable(old_parent); |
| 326 | std::unique_ptr<BookmarkNode> owned_node = |
Peter Kasting | 04fd7242 | 2019-06-03 19:21:03 | [diff] [blame] | 327 | mutable_old_parent->Remove(old_index); |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 328 | BookmarkNode* mutable_new_parent = AsMutable(new_parent); |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 329 | mutable_new_parent->Add(std::move(owned_node), index); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 330 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 331 | if (store_) |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 332 | store_->ScheduleSave(); |
| 333 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 334 | for (BookmarkModelObserver& observer : observers_) |
| 335 | observer.BookmarkNodeMoved(this, old_parent, old_index, new_parent, index); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 336 | } |
| 337 | |
[email protected] | 4e187ef65 | 2010-03-11 05:21:35 | [diff] [blame] | 338 | void BookmarkModel::Copy(const BookmarkNode* node, |
| 339 | const BookmarkNode* new_parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 340 | size_t index) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 341 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Peter Kasting | a71b6c8 | 2019-05-31 18:41:33 | [diff] [blame] | 342 | DCHECK(loaded_); |
| 343 | DCHECK(node); |
| 344 | DCHECK(IsValidIndex(new_parent, index, true)); |
| 345 | DCHECK(!is_root_node(new_parent)); |
| 346 | DCHECK(!is_permanent_node(node)); |
| 347 | DCHECK(!new_parent->HasAncestor(node)); |
[email protected] | 4e187ef65 | 2010-03-11 05:21:35 | [diff] [blame] | 348 | |
[email protected] | c6a7a3d | 2011-03-12 01:04:30 | [diff] [blame] | 349 | SetDateFolderModified(new_parent, Time::Now()); |
[email protected] | 67a8ae4 | 2013-05-20 09:42:39 | [diff] [blame] | 350 | BookmarkNodeData drag_data(node); |
[email protected] | b186450 | 2010-11-13 00:55:51 | [diff] [blame] | 351 | // CloneBookmarkNode will use BookmarkModel methods to do the job, so we |
[email protected] | 1a566fae | 2010-04-16 01:05:06 | [diff] [blame] | 352 | // don't need to send notifications here. |
tfarina | 8f3c40cc | 2015-01-20 21:22:50 | [diff] [blame] | 353 | CloneBookmarkNode(this, drag_data.elements, new_parent, index, true); |
[email protected] | 4e187ef65 | 2010-03-11 05:21:35 | [diff] [blame] | 354 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 355 | if (store_) |
[email protected] | 4e187ef65 | 2010-03-11 05:21:35 | [diff] [blame] | 356 | store_->ScheduleSave(); |
[email protected] | 4e187ef65 | 2010-03-11 05:21:35 | [diff] [blame] | 357 | } |
| 358 | |
[email protected] | 6a4e5a0 | 2012-06-26 19:47:48 | [diff] [blame] | 359 | const gfx::Image& BookmarkModel::GetFavicon(const BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 360 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | ea2e5aa5 | 2009-05-20 18:01:28 | [diff] [blame] | 361 | DCHECK(node); |
[email protected] | bcc3861 | 2012-10-23 01:10:27 | [diff] [blame] | 362 | if (node->favicon_state() == BookmarkNode::INVALID_FAVICON) { |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 363 | BookmarkNode* mutable_node = AsMutable(node); |
Mikel Astiz | a5ea255 | 2017-11-06 22:50:15 | [diff] [blame] | 364 | LoadFavicon(mutable_node, client_->PreferTouchIcon() |
| 365 | ? favicon_base::IconType::kTouchIcon |
| 366 | : favicon_base::IconType::kFavicon); |
[email protected] | ea2e5aa5 | 2009-05-20 18:01:28 | [diff] [blame] | 367 | } |
| 368 | return node->favicon(); |
| 369 | } |
| 370 | |
[email protected] | 504fca8 | 2014-05-07 22:48:08 | [diff] [blame] | 371 | favicon_base::IconType BookmarkModel::GetFaviconType(const BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 372 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 504fca8 | 2014-05-07 22:48:08 | [diff] [blame] | 373 | DCHECK(node); |
| 374 | return node->favicon_type(); |
| 375 | } |
| 376 | |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 377 | void BookmarkModel::SetTitle(const BookmarkNode* node, |
| 378 | const base::string16& title) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 379 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
tfarina | 5ebd536 | 2015-05-12 21:50:10 | [diff] [blame] | 380 | DCHECK(node); |
| 381 | |
[email protected] | 0491ff7 | 2011-12-30 00:45:59 | [diff] [blame] | 382 | if (node->GetTitle() == title) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 383 | return; |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 384 | |
[email protected] | 043a76d | 2014-06-05 16:36:24 | [diff] [blame] | 385 | if (is_permanent_node(node) && !client_->CanSetPermanentNodeTitle(node)) { |
[email protected] | baf4f92 | 2009-10-19 16:44:07 | [diff] [blame] | 386 | NOTREACHED(); |
| 387 | return; |
| 388 | } |
| 389 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 390 | for (BookmarkModelObserver& observer : observers_) |
| 391 | observer.OnWillChangeBookmarkNode(this, node); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 392 | |
[email protected] | 85d911c | 2009-05-19 03:59:42 | [diff] [blame] | 393 | // The title index doesn't support changing the title, instead we remove then |
Matt Reynolds | e33ab14 | 2017-11-09 03:06:48 | [diff] [blame] | 394 | // add it back. Only do this for URL nodes. A directory node can have its |
| 395 | // title changed but should be excluded from the index. |
| 396 | if (node->is_url()) |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 397 | titled_url_index_->Remove(node); |
Mikel Astiz | b9980c0 | 2020-01-31 17:11:31 | [diff] [blame] | 398 | url_index_->SetTitle(AsMutable(node), title); |
Matt Reynolds | e33ab14 | 2017-11-09 03:06:48 | [diff] [blame] | 399 | if (node->is_url()) |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 400 | titled_url_index_->Add(node); |
[email protected] | 85d911c | 2009-05-19 03:59:42 | [diff] [blame] | 401 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 402 | if (store_) |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 403 | store_->ScheduleSave(); |
| 404 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 405 | for (BookmarkModelObserver& observer : observers_) |
| 406 | observer.BookmarkNodeChanged(this, node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 409 | void BookmarkModel::SetURL(const BookmarkNode* node, const GURL& url) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 410 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 411 | DCHECK(node); |
| 412 | DCHECK(!node->is_folder()); |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 413 | |
[email protected] | 5d407754 | 2011-07-21 20:24:07 | [diff] [blame] | 414 | if (node->url() == url) |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 415 | return; |
| 416 | |
[email protected] | 5b5c9b7f3 | 2011-07-21 01:07:18 | [diff] [blame] | 417 | BookmarkNode* mutable_node = AsMutable(node); |
| 418 | mutable_node->InvalidateFavicon(); |
| 419 | CancelPendingFaviconLoadRequests(mutable_node); |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 420 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 421 | for (BookmarkModelObserver& observer : observers_) |
| 422 | observer.OnWillChangeBookmarkNode(this, node); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 423 | |
Mikel Astiz | e163439 | 2020-02-25 17:12:40 | [diff] [blame] | 424 | // The title index doesn't support changing the URL, instead we remove then |
| 425 | // add it back. |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 426 | titled_url_index_->Remove(mutable_node); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 427 | url_index_->SetUrl(mutable_node, url); |
Mikel Astiz | e163439 | 2020-02-25 17:12:40 | [diff] [blame] | 428 | titled_url_index_->Add(mutable_node); |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 429 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 430 | if (store_) |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 431 | store_->ScheduleSave(); |
| 432 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 433 | for (BookmarkModelObserver& observer : observers_) |
| 434 | observer.BookmarkNodeChanged(this, node); |
[email protected] | e548660 | 2010-02-09 21:27:55 | [diff] [blame] | 435 | } |
| 436 | |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 437 | void BookmarkModel::SetNodeMetaInfo(const BookmarkNode* node, |
| 438 | const std::string& key, |
| 439 | const std::string& value) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 440 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 441 | |
[email protected] | 39e11345 | 2013-11-26 00:43:06 | [diff] [blame] | 442 | std::string old_value; |
| 443 | if (node->GetMetaInfo(key, &old_value) && old_value == value) |
| 444 | return; |
| 445 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 446 | for (BookmarkModelObserver& observer : observers_) |
| 447 | observer.OnWillChangeBookmarkMetaInfo(this, node); |
[email protected] | cd869ede | 2013-10-17 12:29:40 | [diff] [blame] | 448 | |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 449 | if (AsMutable(node)->SetMetaInfo(key, value) && store_.get()) |
| 450 | store_->ScheduleSave(); |
[email protected] | cd869ede | 2013-10-17 12:29:40 | [diff] [blame] | 451 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 452 | for (BookmarkModelObserver& observer : observers_) |
| 453 | observer.BookmarkMetaInfoChanged(this, node); |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | e38a87d | 2013-12-05 01:35:18 | [diff] [blame] | 456 | void BookmarkModel::SetNodeMetaInfoMap( |
| 457 | const BookmarkNode* node, |
| 458 | const BookmarkNode::MetaInfoMap& meta_info_map) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 459 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 460 | |
[email protected] | e38a87d | 2013-12-05 01:35:18 | [diff] [blame] | 461 | const BookmarkNode::MetaInfoMap* old_meta_info_map = node->GetMetaInfoMap(); |
| 462 | if ((!old_meta_info_map && meta_info_map.empty()) || |
| 463 | (old_meta_info_map && meta_info_map == *old_meta_info_map)) |
| 464 | return; |
| 465 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 466 | for (BookmarkModelObserver& observer : observers_) |
| 467 | observer.OnWillChangeBookmarkMetaInfo(this, node); |
[email protected] | e38a87d | 2013-12-05 01:35:18 | [diff] [blame] | 468 | |
| 469 | AsMutable(node)->SetMetaInfoMap(meta_info_map); |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 470 | if (store_) |
[email protected] | e38a87d | 2013-12-05 01:35:18 | [diff] [blame] | 471 | store_->ScheduleSave(); |
| 472 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 473 | for (BookmarkModelObserver& observer : observers_) |
| 474 | observer.BookmarkMetaInfoChanged(this, node); |
[email protected] | e38a87d | 2013-12-05 01:35:18 | [diff] [blame] | 475 | } |
| 476 | |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 477 | void BookmarkModel::DeleteNodeMetaInfo(const BookmarkNode* node, |
| 478 | const std::string& key) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 479 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 480 | |
[email protected] | 39e11345 | 2013-11-26 00:43:06 | [diff] [blame] | 481 | const BookmarkNode::MetaInfoMap* meta_info_map = node->GetMetaInfoMap(); |
| 482 | if (!meta_info_map || meta_info_map->find(key) == meta_info_map->end()) |
| 483 | return; |
| 484 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 485 | for (BookmarkModelObserver& observer : observers_) |
| 486 | observer.OnWillChangeBookmarkMetaInfo(this, node); |
[email protected] | cd869ede | 2013-10-17 12:29:40 | [diff] [blame] | 487 | |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 488 | if (AsMutable(node)->DeleteMetaInfo(key) && store_.get()) |
| 489 | store_->ScheduleSave(); |
[email protected] | cd869ede | 2013-10-17 12:29:40 | [diff] [blame] | 490 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 491 | for (BookmarkModelObserver& observer : observers_) |
| 492 | observer.BookmarkMetaInfoChanged(this, node); |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 493 | } |
| 494 | |
rfevang | d75d3221 | 2014-12-06 01:27:22 | [diff] [blame] | 495 | void BookmarkModel::AddNonClonedKey(const std::string& key) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 496 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
rfevang | d75d3221 | 2014-12-06 01:27:22 | [diff] [blame] | 497 | non_cloned_keys_.insert(key); |
| 498 | } |
| 499 | |
pkotwicz | ca240dd | 2015-07-09 16:15:32 | [diff] [blame] | 500 | void BookmarkModel::OnFaviconsChanged(const std::set<GURL>& page_urls, |
| 501 | const GURL& icon_url) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 502 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 503 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 504 | if (!loaded_) |
| 505 | return; |
| 506 | |
pkotwicz | ca240dd | 2015-07-09 16:15:32 | [diff] [blame] | 507 | std::set<const BookmarkNode*> to_update; |
| 508 | for (const GURL& page_url : page_urls) { |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 509 | std::vector<const BookmarkNode*> nodes; |
pkotwicz | ca240dd | 2015-07-09 16:15:32 | [diff] [blame] | 510 | GetNodesByURL(page_url, &nodes); |
| 511 | to_update.insert(nodes.begin(), nodes.end()); |
| 512 | } |
| 513 | |
| 514 | if (!icon_url.is_empty()) { |
| 515 | // Log Histogram to determine how often |icon_url| is non empty in |
| 516 | // practice. |
| 517 | // TODO(pkotwicz): Do something more efficient if |icon_url| is non-empty |
| 518 | // many times a day for each user. |
| 519 | UMA_HISTOGRAM_BOOLEAN("Bookmarks.OnFaviconsChangedIconURL", true); |
| 520 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 521 | url_index_->GetNodesWithIconUrl(icon_url, &to_update); |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 522 | } |
pkotwicz | ca240dd | 2015-07-09 16:15:32 | [diff] [blame] | 523 | |
| 524 | for (const BookmarkNode* node : to_update) { |
| 525 | // Rerequest the favicon. |
| 526 | BookmarkNode* mutable_node = AsMutable(node); |
| 527 | mutable_node->InvalidateFavicon(); |
| 528 | CancelPendingFaviconLoadRequests(mutable_node); |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 529 | for (BookmarkModelObserver& observer : observers_) |
| 530 | observer.BookmarkNodeFaviconChanged(this, node); |
pkotwicz | ca240dd | 2015-07-09 16:15:32 | [diff] [blame] | 531 | } |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 532 | } |
| 533 | |
tfarina | 5ebd536 | 2015-05-12 21:50:10 | [diff] [blame] | 534 | void BookmarkModel::SetDateAdded(const BookmarkNode* node, Time date_added) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 535 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 536 | DCHECK(node); |
| 537 | DCHECK(!is_permanent_node(node)); |
[email protected] | b61445c | 2012-10-27 00:11:42 | [diff] [blame] | 538 | |
| 539 | if (node->date_added() == date_added) |
| 540 | return; |
| 541 | |
[email protected] | b61445c | 2012-10-27 00:11:42 | [diff] [blame] | 542 | AsMutable(node)->set_date_added(date_added); |
| 543 | |
| 544 | // Syncing might result in dates newer than the folder's last modified date. |
| 545 | if (date_added > node->parent()->date_folder_modified()) { |
| 546 | // Will trigger store_->ScheduleSave(). |
| 547 | SetDateFolderModified(node->parent(), date_added); |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 548 | } else if (store_) { |
[email protected] | b61445c | 2012-10-27 00:11:42 | [diff] [blame] | 549 | store_->ScheduleSave(); |
| 550 | } |
| 551 | } |
| 552 | |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 553 | void BookmarkModel::GetNodesByURL(const GURL& url, |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 554 | std::vector<const BookmarkNode*>* nodes) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 555 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 556 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 557 | if (url_index_) |
| 558 | url_index_->GetNodesByUrl(url, nodes); |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 559 | } |
| 560 | |
[email protected] | 23e3969 | 2014-06-06 21:10:13 | [diff] [blame] | 561 | const BookmarkNode* BookmarkModel::GetMostRecentlyAddedUserNodeForURL( |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 562 | const GURL& url) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 563 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 564 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 565 | std::vector<const BookmarkNode*> nodes; |
[email protected] | 848cd05e | 2008-09-19 18:33:48 | [diff] [blame] | 566 | GetNodesByURL(url, &nodes); |
tfarina | a0ec34e | 2015-01-12 18:46:48 | [diff] [blame] | 567 | std::sort(nodes.begin(), nodes.end(), &MoreRecentlyAdded); |
[email protected] | 23e3969 | 2014-06-06 21:10:13 | [diff] [blame] | 568 | |
| 569 | // Look for the first node that the user can edit. |
| 570 | for (size_t i = 0; i < nodes.size(); ++i) { |
| 571 | if (client_->CanBeEditedByUser(nodes[i])) |
| 572 | return nodes[i]; |
| 573 | } |
| 574 | |
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame] | 575 | return nullptr; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 576 | } |
| 577 | |
[email protected] | cf8e817 | 2011-07-23 00:46:24 | [diff] [blame] | 578 | bool BookmarkModel::HasBookmarks() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 579 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 580 | return url_index_ && url_index_->HasBookmarks(); |
[email protected] | cf8e817 | 2011-07-23 00:46:24 | [diff] [blame] | 581 | } |
| 582 | |
Marti Wong | c67da22 | 2017-09-01 02:30:01 | [diff] [blame] | 583 | bool BookmarkModel::HasNoUserCreatedBookmarksOrFolders() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 584 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Peter Kasting | fc86fec6 | 2019-05-21 20:43:47 | [diff] [blame] | 585 | return bookmark_bar_node_->children().empty() && |
| 586 | other_node_->children().empty() && mobile_node_->children().empty(); |
Marti Wong | c67da22 | 2017-09-01 02:30:01 | [diff] [blame] | 587 | } |
| 588 | |
[email protected] | cf8e817 | 2011-07-23 00:46:24 | [diff] [blame] | 589 | bool BookmarkModel::IsBookmarked(const GURL& url) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 590 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 591 | return url_index_ && url_index_->IsBookmarked(url); |
[email protected] | cf8e817 | 2011-07-23 00:46:24 | [diff] [blame] | 592 | } |
| 593 | |
Scott Violet | 8aa6d5760 | 2018-04-25 15:46:21 | [diff] [blame] | 594 | void BookmarkModel::GetBookmarks(std::vector<UrlAndTitle>* bookmarks) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 595 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 596 | if (url_index_) |
| 597 | url_index_->GetBookmarks(bookmarks); |
[email protected] | 90ef1313 | 2008-08-27 03:27:46 | [diff] [blame] | 598 | } |
| 599 | |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 600 | const BookmarkNode* BookmarkModel::AddFolder( |
[email protected] | eb59ad1 | 2014-04-24 00:05:08 | [diff] [blame] | 601 | const BookmarkNode* parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 602 | size_t index, |
[email protected] | eb59ad1 | 2014-04-24 00:05:08 | [diff] [blame] | 603 | const base::string16& title, |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 604 | const BookmarkNode::MetaInfoMap* meta_info, |
| 605 | base::Optional<std::string> guid) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 606 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Peter Kasting | a71b6c8 | 2019-05-31 18:41:33 | [diff] [blame] | 607 | DCHECK(loaded_); |
Mikel Astiz | 9f8d40e | 2020-02-13 17:47:13 | [diff] [blame] | 608 | DCHECK(parent); |
| 609 | DCHECK(parent->is_folder()); |
Peter Kasting | a71b6c8 | 2019-05-31 18:41:33 | [diff] [blame] | 610 | DCHECK(!is_root_node(parent)); |
| 611 | DCHECK(IsValidIndex(parent, index, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 612 | |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 613 | if (guid) |
Mikel Astiz | 0afae3ca | 2020-02-18 21:07:36 | [diff] [blame] | 614 | DCHECK(base::IsValidGUIDOutputString(*guid)); |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 615 | else |
| 616 | guid = base::GenerateGUID(); |
| 617 | |
| 618 | auto new_node = |
| 619 | std::make_unique<BookmarkNode>(generate_next_node_id(), *guid, GURL()); |
[email protected] | edb63cc | 2011-03-11 02:00:41 | [diff] [blame] | 620 | new_node->set_date_folder_modified(Time::Now()); |
[email protected] | aee23654 | 2011-12-01 04:34:03 | [diff] [blame] | 621 | // Folders shouldn't have line breaks in their titles. |
[email protected] | 0491ff7 | 2011-12-30 00:45:59 | [diff] [blame] | 622 | new_node->SetTitle(title); |
[email protected] | eb59ad1 | 2014-04-24 00:05:08 | [diff] [blame] | 623 | if (meta_info) |
| 624 | new_node->SetMetaInfoMap(*meta_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 625 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 626 | return AddNode(AsMutable(parent), index, std::move(new_node)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 627 | } |
| 628 | |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 629 | const BookmarkNode* BookmarkModel::AddURL( |
[email protected] | e64e901 | 2010-01-11 23:10:55 | [diff] [blame] | 630 | const BookmarkNode* parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 631 | size_t index, |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 632 | const base::string16& title, |
[email protected] | e64e901 | 2010-01-11 23:10:55 | [diff] [blame] | 633 | const GURL& url, |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 634 | const BookmarkNode::MetaInfoMap* meta_info, |
| 635 | base::Optional<base::Time> creation_time, |
| 636 | base::Optional<std::string> guid) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 637 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Peter Kasting | a71b6c8 | 2019-05-31 18:41:33 | [diff] [blame] | 638 | DCHECK(loaded_); |
| 639 | DCHECK(url.is_valid()); |
Mikel Astiz | 9f8d40e | 2020-02-13 17:47:13 | [diff] [blame] | 640 | DCHECK(parent); |
| 641 | DCHECK(parent->is_folder()); |
Peter Kasting | a71b6c8 | 2019-05-31 18:41:33 | [diff] [blame] | 642 | DCHECK(!is_root_node(parent)); |
| 643 | DCHECK(IsValidIndex(parent, index, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 644 | |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 645 | if (guid) |
Mikel Astiz | 0afae3ca | 2020-02-18 21:07:36 | [diff] [blame] | 646 | DCHECK(base::IsValidGUIDOutputString(*guid)); |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 647 | else |
| 648 | guid = base::GenerateGUID(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 649 | |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 650 | if (!creation_time) |
| 651 | creation_time = Time::Now(); |
| 652 | |
| 653 | // Syncing may result in dates newer than the last modified date. |
| 654 | if (*creation_time > parent->date_folder_modified()) |
| 655 | SetDateFolderModified(parent, *creation_time); |
| 656 | |
| 657 | auto new_node = |
| 658 | std::make_unique<BookmarkNode>(generate_next_node_id(), *guid, url); |
[email protected] | 0491ff7 | 2011-12-30 00:45:59 | [diff] [blame] | 659 | new_node->SetTitle(title); |
Pauline Leitao | 6a34195 | 2019-09-13 15:00:43 | [diff] [blame] | 660 | new_node->set_date_added(*creation_time); |
[email protected] | eb59ad1 | 2014-04-24 00:05:08 | [diff] [blame] | 661 | if (meta_info) |
| 662 | new_node->SetMetaInfoMap(*meta_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 663 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 664 | return AddNode(AsMutable(parent), index, std::move(new_node)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 665 | } |
| 666 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 667 | void BookmarkModel::SortChildren(const BookmarkNode* parent) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 668 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 23e3969 | 2014-06-06 21:10:13 | [diff] [blame] | 669 | DCHECK(client_->CanBeEditedByUser(parent)); |
[email protected] | 043a76d | 2014-06-05 16:36:24 | [diff] [blame] | 670 | |
[email protected] | 6b4d64c | 2011-07-29 21:33:24 | [diff] [blame] | 671 | if (!parent || !parent->is_folder() || is_root_node(parent) || |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 672 | parent->children().size() <= 1) { |
[email protected] | e2f86d9 | 2009-02-25 00:22:01 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 676 | for (BookmarkModelObserver& observer : observers_) |
| 677 | observer.OnWillReorderBookmarkNode(this, parent); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 678 | |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 679 | UErrorCode error = U_ZERO_ERROR; |
dcheng | acd3f52 | 2016-04-21 22:30:41 | [diff] [blame] | 680 | std::unique_ptr<icu::Collator> collator(icu::Collator::createInstance(error)); |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 681 | if (U_FAILURE(error)) |
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame] | 682 | collator.reset(nullptr); |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 683 | BookmarkNode* mutable_parent = AsMutable(parent); |
Peter Kasting | fc86fec6 | 2019-05-21 20:43:47 | [diff] [blame] | 684 | std::sort(mutable_parent->children_.begin(), mutable_parent->children_.end(), |
[email protected] | ef76264 | 2009-03-05 16:30:25 | [diff] [blame] | 685 | SortComparator(collator.get())); |
[email protected] | e2f86d9 | 2009-02-25 00:22:01 | [diff] [blame] | 686 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 687 | if (store_) |
[email protected] | 997a036 | 2009-03-12 03:10:51 | [diff] [blame] | 688 | store_->ScheduleSave(); |
| 689 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 690 | for (BookmarkModelObserver& observer : observers_) |
| 691 | observer.BookmarkNodeChildrenReordered(this, parent); |
[email protected] | e2f86d9 | 2009-02-25 00:22:01 | [diff] [blame] | 692 | } |
| 693 | |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 694 | void BookmarkModel::ReorderChildren( |
| 695 | const BookmarkNode* parent, |
[email protected] | 257d508 | 2013-08-06 07:46:43 | [diff] [blame] | 696 | const std::vector<const BookmarkNode*>& ordered_nodes) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 697 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 23e3969 | 2014-06-06 21:10:13 | [diff] [blame] | 698 | DCHECK(client_->CanBeEditedByUser(parent)); |
[email protected] | 043a76d | 2014-06-05 16:36:24 | [diff] [blame] | 699 | |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 700 | // Ensure that all children in |parent| are in |ordered_nodes|. |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 701 | DCHECK_EQ(parent->children().size(), ordered_nodes.size()); |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 702 | for (const BookmarkNode* node : ordered_nodes) |
| 703 | DCHECK_EQ(parent, node->parent()); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 704 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 705 | for (BookmarkModelObserver& observer : observers_) |
| 706 | observer.OnWillReorderBookmarkNode(this, parent); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 707 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 708 | if (ordered_nodes.size() > 1) { |
| 709 | std::map<const BookmarkNode*, int> order; |
| 710 | for (size_t i = 0; i < ordered_nodes.size(); ++i) |
| 711 | order[ordered_nodes[i]] = i; |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 712 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 713 | std::vector<std::unique_ptr<BookmarkNode>> new_children( |
| 714 | ordered_nodes.size()); |
| 715 | BookmarkNode* mutable_parent = AsMutable(parent); |
Peter Kasting | fc86fec6 | 2019-05-21 20:43:47 | [diff] [blame] | 716 | for (auto& child : mutable_parent->children_) { |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 717 | size_t new_location = order[child.get()]; |
| 718 | new_children[new_location] = std::move(child); |
| 719 | } |
Peter Kasting | fc86fec6 | 2019-05-21 20:43:47 | [diff] [blame] | 720 | mutable_parent->children_.swap(new_children); |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 721 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 722 | if (store_) |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 723 | store_->ScheduleSave(); |
| 724 | } |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 725 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 726 | for (BookmarkModelObserver& observer : observers_) |
| 727 | observer.BookmarkNodeChildrenReordered(this, parent); |
[email protected] | 472f95e | 2013-06-10 16:49:18 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | c6a7a3d | 2011-03-12 01:04:30 | [diff] [blame] | 730 | void BookmarkModel::SetDateFolderModified(const BookmarkNode* parent, |
| 731 | const Time time) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 732 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | eea8fd553 | 2009-12-16 00:08:10 | [diff] [blame] | 733 | DCHECK(parent); |
[email protected] | edb63cc | 2011-03-11 02:00:41 | [diff] [blame] | 734 | AsMutable(parent)->set_date_folder_modified(time); |
[email protected] | eea8fd553 | 2009-12-16 00:08:10 | [diff] [blame] | 735 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 736 | if (store_) |
[email protected] | eea8fd553 | 2009-12-16 00:08:10 | [diff] [blame] | 737 | store_->ScheduleSave(); |
| 738 | } |
| 739 | |
[email protected] | c6a7a3d | 2011-03-12 01:04:30 | [diff] [blame] | 740 | void BookmarkModel::ResetDateFolderModified(const BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 741 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | c6a7a3d | 2011-03-12 01:04:30 | [diff] [blame] | 742 | SetDateFolderModified(node, Time()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 743 | } |
| 744 | |
kkimlabs | f1a7a373 | 2014-11-04 10:30:46 | [diff] [blame] | 745 | void BookmarkModel::GetBookmarksMatching(const base::string16& text, |
| 746 | size_t max_count, |
mattreynolds | 25e9a31 | 2016-12-14 21:52:13 | [diff] [blame] | 747 | std::vector<TitledUrlMatch>* matches) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 748 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
kkimlabs | f1a7a373 | 2014-11-04 10:30:46 | [diff] [blame] | 749 | GetBookmarksMatching(text, max_count, |
| 750 | query_parser::MatchingAlgorithm::DEFAULT, matches); |
| 751 | } |
| 752 | |
[email protected] | b3a8489 | 2014-04-23 04:28:07 | [diff] [blame] | 753 | void BookmarkModel::GetBookmarksMatching( |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 754 | const base::string16& text, |
[email protected] | e64e901 | 2010-01-11 23:10:55 | [diff] [blame] | 755 | size_t max_count, |
kkimlabs | f1a7a373 | 2014-11-04 10:30:46 | [diff] [blame] | 756 | query_parser::MatchingAlgorithm matching_algorithm, |
mattreynolds | 25e9a31 | 2016-12-14 21:52:13 | [diff] [blame] | 757 | std::vector<TitledUrlMatch>* matches) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 758 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 759 | |
[email protected] | 01eec88 | 2009-05-22 18:13:28 | [diff] [blame] | 760 | if (!loaded_) |
| 761 | return; |
| 762 | |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 763 | titled_url_index_->GetResultsMatching(text, max_count, matching_algorithm, |
| 764 | matches); |
[email protected] | 85d911c | 2009-05-19 03:59:42 | [diff] [blame] | 765 | } |
| 766 | |
[email protected] | 9876bb1c | 2008-12-16 20:42:25 | [diff] [blame] | 767 | void BookmarkModel::ClearStore() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 768 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 265e88e | 2014-07-07 20:45:19 | [diff] [blame] | 769 | store_.reset(); |
[email protected] | 9876bb1c | 2008-12-16 20:42:25 | [diff] [blame] | 770 | } |
| 771 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 772 | void BookmarkModel::RestoreRemovedNode(const BookmarkNode* parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 773 | size_t index, |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 774 | std::unique_ptr<BookmarkNode> node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 775 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 776 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 777 | BookmarkNode* node_ptr = node.get(); |
| 778 | AddNode(AsMutable(parent), index, std::move(node)); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 779 | |
| 780 | // We might be restoring a folder node that have already contained a set of |
| 781 | // child nodes. We need to notify all of them. |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 782 | NotifyNodeAddedForAllDescendents(node_ptr); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | void BookmarkModel::NotifyNodeAddedForAllDescendents(const BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 786 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 787 | |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 788 | for (size_t i = 0; i < node->children().size(); ++i) { |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 789 | for (BookmarkModelObserver& observer : observers_) |
| 790 | observer.BookmarkNodeAdded(this, node, i); |
Peter Kasting | 5174590 | 2019-06-28 21:54:55 | [diff] [blame] | 791 | NotifyNodeAddedForAllDescendents(node->children()[i].get()); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
Mikel Astiz | b810f7ac | 2019-11-06 16:57:00 | [diff] [blame] | 795 | void BookmarkModel::RemoveNodeFromIndexRecursive(BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 796 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 797 | DCHECK(loaded_); |
| 798 | DCHECK(!is_permanent_node(node)); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 799 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 800 | if (node->is_url()) |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 801 | titled_url_index_->Remove(node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 802 | |
Mikel Astiz | e163439 | 2020-02-25 17:12:40 | [diff] [blame] | 803 | // Note that |guid_index_| is used for DCHECK-enabled builds only. |
| 804 | #if DCHECK_IS_ON() |
| 805 | DCHECK(guid_index_.erase(node->guid())) |
| 806 | << "Bookmark GUID missing in index: " << node->guid(); |
| 807 | #endif // DCHECK_IS_ON() |
| 808 | |
[email protected] | abc2f26 | 2011-03-15 21:15:44 | [diff] [blame] | 809 | CancelPendingFaviconLoadRequests(node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 810 | |
| 811 | // Recurse through children. |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 812 | for (size_t i = node->children().size(); i > 0; --i) |
Mikel Astiz | b810f7ac | 2019-11-06 16:57:00 | [diff] [blame] | 813 | RemoveNodeFromIndexRecursive(node->children()[i - 1].get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 814 | } |
| 815 | |
dcheng | acd3f52 | 2016-04-21 22:30:41 | [diff] [blame] | 816 | void BookmarkModel::DoneLoading(std::unique_ptr<BookmarkLoadDetails> details) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 817 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 818 | DCHECK(details); |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 819 | DCHECK(!loaded_); |
[email protected] | 01eec88 | 2009-05-22 18:13:28 | [diff] [blame] | 820 | |
[email protected] | 01eec88 | 2009-05-22 18:13:28 | [diff] [blame] | 821 | next_node_id_ = details->max_id(); |
[email protected] | 367d707 | 2009-07-13 23:27:13 | [diff] [blame] | 822 | if (details->computed_checksum() != details->stored_checksum() || |
Pauline Leitao | 44f5a81 | 2019-07-30 10:49:51 | [diff] [blame] | 823 | details->ids_reassigned() || details->guids_reassigned()) { |
[email protected] | 367d707 | 2009-07-13 23:27:13 | [diff] [blame] | 824 | // If bookmarks file changed externally, the IDs may have changed |
| 825 | // externally. In that case, the decoder may have reassigned IDs to make |
| 826 | // them unique. So when the file has changed externally, we should save the |
Pauline Leitao | 44f5a81 | 2019-07-30 10:49:51 | [diff] [blame] | 827 | // bookmarks file to persist such changes. The same applies if new GUIDs |
| 828 | // have been assigned to bookmarks. |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 829 | if (store_) |
[email protected] | 367d707 | 2009-07-13 23:27:13 | [diff] [blame] | 830 | store_->ScheduleSave(); |
| 831 | } |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 832 | |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 833 | titled_url_index_ = details->owned_index(); |
Scott Violet | a772b27d | 2018-05-31 23:23:21 | [diff] [blame] | 834 | url_index_ = details->url_index(); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 835 | root_ = details->root_node(); |
| 836 | // See declaration for details on why |owned_root_| is reset. |
| 837 | owned_root_.reset(); |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 838 | bookmark_bar_node_ = details->bb_node(); |
| 839 | other_node_ = details->other_folder_node(); |
| 840 | mobile_node_ = details->mobile_folder_node(); |
| 841 | |
Mikel Astiz | e163439 | 2020-02-25 17:12:40 | [diff] [blame] | 842 | #if DCHECK_IS_ON() |
| 843 | AddGuidsToIndexRecursive(root_, &guid_index_); |
| 844 | #endif // DCHECK_IS_ON() |
| 845 | |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 846 | titled_url_index_->SetNodeSorter( |
| 847 | std::make_unique<TypedCountSorter>(client_.get())); |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 848 | // Sorting the permanent nodes has to happen on the main thread, so we do it |
| 849 | // here, after loading completes. |
Peter Kasting | fc86fec6 | 2019-05-21 20:43:47 | [diff] [blame] | 850 | std::stable_sort(root_->children_.begin(), root_->children_.end(), |
sdefresne | 070a510 | 2016-02-01 13:42:14 | [diff] [blame] | 851 | VisibilityComparator(client_.get())); |
[email protected] | 6c116404 | 2009-05-08 14:41:08 | [diff] [blame] | 852 | |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 853 | root_->SetMetaInfoMap(details->model_meta_info_map()); |
[email protected] | 1858410f | 2012-10-26 05:06:45 | [diff] [blame] | 854 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 855 | loaded_ = true; |
Mohamed Amir Yosef | d1950618 | 2018-06-19 13:02:14 | [diff] [blame] | 856 | client_->DecodeBookmarkSyncMetadata( |
| 857 | details->sync_metadata_str(), |
| 858 | store_ ? base::BindRepeating(&BookmarkStorage::ScheduleSave, |
| 859 | base::Unretained(store_.get())) |
| 860 | : base::DoNothing()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 861 | |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 862 | // Notify our direct observers. |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 863 | for (BookmarkModelObserver& observer : observers_) |
| 864 | observer.BookmarkModelLoaded(this, details->ids_reassigned()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 865 | } |
| 866 | |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 867 | BookmarkNode* BookmarkModel::AddNode(BookmarkNode* parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 868 | size_t index, |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 869 | std::unique_ptr<BookmarkNode> node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 870 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 871 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 872 | BookmarkNode* node_ptr = node.get(); |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 873 | url_index_->Add(parent, index, std::move(node)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 874 | |
Zinovy Nis | aa5aee39 | 2018-05-08 16:18:41 | [diff] [blame] | 875 | if (store_) |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 876 | store_->ScheduleSave(); |
| 877 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 878 | AddNodeToIndexRecursive(node_ptr); |
danduong | f4fde32 | 2014-11-04 18:56:56 | [diff] [blame] | 879 | |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 880 | for (BookmarkModelObserver& observer : observers_) |
| 881 | observer.BookmarkNodeAdded(this, parent, index); |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 882 | |
avi | cee78e4e | 2016-09-30 17:08:14 | [diff] [blame] | 883 | return node_ptr; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 884 | } |
| 885 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 886 | void BookmarkModel::AddNodeToIndexRecursive(BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 887 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 888 | |
Scott Violet | 82ef0fa | 2018-05-23 18:23:39 | [diff] [blame] | 889 | if (node->is_url()) |
Mikel Astiz | c69bf85 | 2020-01-30 21:48:53 | [diff] [blame] | 890 | titled_url_index_->Add(node); |
Mikel Astiz | e163439 | 2020-02-25 17:12:40 | [diff] [blame] | 891 | |
| 892 | // The node's GUID must be unique. Note that |guid_index_| is used for |
| 893 | // DCHECK-enabled builds only. |
| 894 | #if DCHECK_IS_ON() |
| 895 | DCHECK(guid_index_.insert(node->guid()).second) |
| 896 | << "Duplicate bookmark GUID: " << node->guid(); |
| 897 | #endif // DCHECK_IS_ON() |
| 898 | |
Peter Kasting | b0d21f2 | 2019-06-25 00:26:16 | [diff] [blame] | 899 | for (const auto& child : node->children()) |
| 900 | AddNodeToIndexRecursive(child.get()); |
danduong | f4fde32 | 2014-11-04 18:56:56 | [diff] [blame] | 901 | } |
| 902 | |
[email protected] | b3c33d46 | 2009-06-26 22:29:20 | [diff] [blame] | 903 | bool BookmarkModel::IsValidIndex(const BookmarkNode* parent, |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 904 | size_t index, |
[email protected] | d8e41ed | 2008-09-11 15:22:32 | [diff] [blame] | 905 | bool allow_end) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 906 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Peter Kasting | 8cf4c23e | 2019-06-06 00:38:30 | [diff] [blame] | 907 | return parent && parent->is_folder() && |
| 908 | (index < parent->children().size() || |
| 909 | (allow_end && index == parent->children().size())); |
[email protected] | bd1b9670 | 2009-07-08 21:54:14 | [diff] [blame] | 910 | } |
[email protected] | f25387b | 2008-08-21 15:20:33 | [diff] [blame] | 911 | |
[email protected] | abc2f26 | 2011-03-15 21:15:44 | [diff] [blame] | 912 | void BookmarkModel::OnFaviconDataAvailable( |
[email protected] | 0ea3db5 | 2012-12-07 01:32:01 | [diff] [blame] | 913 | BookmarkNode* node, |
[email protected] | 504fca8 | 2014-05-07 22:48:08 | [diff] [blame] | 914 | favicon_base::IconType icon_type, |
[email protected] | 7627e0b4 | 2014-04-17 17:20:53 | [diff] [blame] | 915 | const favicon_base::FaviconImageResult& image_result) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 916 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | 4167c3a | 2008-08-21 18:12:20 | [diff] [blame] | 917 | DCHECK(node); |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 918 | |
[email protected] | e95b717f | 2014-02-06 13:47:13 | [diff] [blame] | 919 | node->set_favicon_load_task_id(base::CancelableTaskTracker::kBadTaskId); |
[email protected] | bcc3861 | 2012-10-23 01:10:27 | [diff] [blame] | 920 | node->set_favicon_state(BookmarkNode::LOADED_FAVICON); |
[email protected] | 65baa22 | 2012-08-30 15:43:51 | [diff] [blame] | 921 | if (!image_result.image.IsEmpty()) { |
[email protected] | 504fca8 | 2014-05-07 22:48:08 | [diff] [blame] | 922 | node->set_favicon_type(icon_type); |
[email protected] | 65baa22 | 2012-08-30 15:43:51 | [diff] [blame] | 923 | node->set_favicon(image_result.image); |
[email protected] | 2ad0e87 | 2012-11-30 01:24:46 | [diff] [blame] | 924 | node->set_icon_url(image_result.icon_url); |
[email protected] | 65baa22 | 2012-08-30 15:43:51 | [diff] [blame] | 925 | FaviconLoaded(node); |
Mikel Astiz | a5ea255 | 2017-11-06 22:50:15 | [diff] [blame] | 926 | } else if (icon_type == favicon_base::IconType::kTouchIcon) { |
[email protected] | 504fca8 | 2014-05-07 22:48:08 | [diff] [blame] | 927 | // Couldn't load the touch icon, fallback to the regular favicon. |
| 928 | DCHECK(client_->PreferTouchIcon()); |
Mikel Astiz | a5ea255 | 2017-11-06 22:50:15 | [diff] [blame] | 929 | LoadFavicon(node, favicon_base::IconType::kFavicon); |
Mikel Astiz | 55b3fe20 | 2017-11-08 20:54:50 | [diff] [blame] | 930 | } else { |
| 931 | // No favicon available, but we still notify observers. |
| 932 | FaviconLoaded(node); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
tfarina | c0baf0b | 2014-12-08 18:01:21 | [diff] [blame] | 936 | void BookmarkModel::LoadFavicon(BookmarkNode* node, |
| 937 | favicon_base::IconType icon_type) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 938 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 939 | |
[email protected] | 0890e60e | 2011-06-27 14:55:21 | [diff] [blame] | 940 | if (node->is_folder()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 941 | return; |
| 942 | |
[email protected] | 5d407754 | 2011-07-21 20:24:07 | [diff] [blame] | 943 | DCHECK(node->url().is_valid()); |
[email protected] | 504fca8 | 2014-05-07 22:48:08 | [diff] [blame] | 944 | node->set_favicon_state(BookmarkNode::LOADING_FAVICON); |
[email protected] | 25244a93 | 2014-07-12 23:00:24 | [diff] [blame] | 945 | base::CancelableTaskTracker::TaskId taskId = |
| 946 | client_->GetFaviconImageForPageURL( |
danakj | e8f4a202 | 2019-12-13 20:37:39 | [diff] [blame] | 947 | node->url(), icon_type, |
| 948 | base::BindOnce(&BookmarkModel::OnFaviconDataAvailable, |
| 949 | base::Unretained(this), node, icon_type), |
[email protected] | 25244a93 | 2014-07-12 23:00:24 | [diff] [blame] | 950 | &cancelable_task_tracker_); |
[email protected] | 6a848b5 | 2014-04-26 22:06:54 | [diff] [blame] | 951 | if (taskId != base::CancelableTaskTracker::kBadTaskId) |
| 952 | node->set_favicon_load_task_id(taskId); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 953 | } |
| 954 | |
[email protected] | 5b5c9b7f3 | 2011-07-21 01:07:18 | [diff] [blame] | 955 | void BookmarkModel::FaviconLoaded(const BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 956 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
tfarina | 2fa1d2fb | 2016-10-19 01:44:31 | [diff] [blame] | 957 | for (BookmarkModelObserver& observer : observers_) |
| 958 | observer.BookmarkNodeFaviconChanged(this, node); |
[email protected] | 5b5c9b7f3 | 2011-07-21 01:07:18 | [diff] [blame] | 959 | } |
| 960 | |
[email protected] | abc2f26 | 2011-03-15 21:15:44 | [diff] [blame] | 961 | void BookmarkModel::CancelPendingFaviconLoadRequests(BookmarkNode* node) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 962 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
[email protected] | e95b717f | 2014-02-06 13:47:13 | [diff] [blame] | 963 | if (node->favicon_load_task_id() != base::CancelableTaskTracker::kBadTaskId) { |
[email protected] | 0ea3db5 | 2012-12-07 01:32:01 | [diff] [blame] | 964 | cancelable_task_tracker_.TryCancel(node->favicon_load_task_id()); |
[email protected] | e95b717f | 2014-02-06 13:47:13 | [diff] [blame] | 965 | node->set_favicon_load_task_id(base::CancelableTaskTracker::kBadTaskId); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 969 | int64_t BookmarkModel::generate_next_node_id() { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 970 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
Scott Violet | e349e96 | 2018-05-03 20:45:23 | [diff] [blame] | 971 | DCHECK(loaded_); |
[email protected] | 4d89f38 | 2009-05-12 06:56:49 | [diff] [blame] | 972 | return next_node_id_++; |
| 973 | } |
[email protected] | 01eec88 | 2009-05-22 18:13:28 | [diff] [blame] | 974 | |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 975 | void BookmarkModel::SetUndoDelegate(BookmarkUndoDelegate* undo_delegate) { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 976 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 977 | undo_delegate_ = undo_delegate; |
| 978 | if (undo_delegate_) |
| 979 | undo_delegate_->SetUndoProvider(this); |
| 980 | } |
| 981 | |
| 982 | BookmarkUndoDelegate* BookmarkModel::undo_delegate() const { |
Mikel Astiz | ecaeb70 | 2019-12-03 07:11:12 | [diff] [blame] | 983 | DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
jianli | 14436d5 | 2015-10-09 22:47:35 | [diff] [blame] | 984 | return undo_delegate_ ? undo_delegate_ : empty_undo_delegate_.get(); |
| 985 | } |
| 986 | |
tfarina | a0ec34e | 2015-01-12 18:46:48 | [diff] [blame] | 987 | } // namespace bookmarks |