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