Skip to content

Commit

Permalink
[iOS][Bkmrk] GetDefaultBookmarkFolder() should only return a folder
Browse files Browse the repository at this point in the history
This patch adds a DCHECK() when setting the default folder, to be sure
the BookmarkNode is a folder.
And this patch adds a test when getting the default folder from
the pref, to not return a BookmarkNode that is not a folder.
We should not trust pref values.

This patch needs to be cherry-picked in M115 and M114 if possible.

(cherry picked from commit 4c37398)

Fixed: 1450146
Change-Id: I847a30c7d57d0685843e090e56b8911065bdbdf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4577200
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Auto-Submit: Jérôme Lebel <jlebel@chromium.org>
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1151686}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4593716
Reviewed-by: Menghan Yang <myuu@google.com>
Commit-Queue: Menghan Yang <myuu@google.com>
Cr-Commit-Position: refs/branch-heads/5790@{#402}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Jérôme Lebel authored and Chromium LUCI CQ committed Jun 6, 2023
1 parent fabf0cd commit fc40717
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ios/chrome/browser/bookmarks/bookmarks_utils.cc
Expand Up @@ -86,6 +86,8 @@ void SetLastUsedBookmarkFolder(PrefService* prefs,
const bookmarks::BookmarkNode* folder,
bookmarks::StorageType type) {
DCHECK(folder);
DCHECK(folder->is_folder()) << "node type: " << folder->type()
<< ", storage type: " << static_cast<int>(type);
prefs->SetInt64(prefs::kIosBookmarkLastUsedFolderReceivingBookmarks,
folder->id());
prefs->SetInteger(prefs::kIosBookmarkLastUsedStorageReceivingBookmarks,
Expand All @@ -108,7 +110,7 @@ const bookmarks::BookmarkNode* GetDefaultBookmarkFolder(
type, profile_bookmark_model, account_bookmark_model);
const BookmarkNode* result =
bookmarks::GetBookmarkNodeByID(bookmark_model, node_id);
if (result) {
if (result && result->is_folder()) {
return result;
}
}
Expand Down

0 comments on commit fc40717

Please sign in to comment.