Skip to content

Commit

Permalink
Make ManagedBookmarksPolicyHandler use Value::List and Value::Dict.
Browse files Browse the repository at this point in the history
It was using Value::ListStorage (which was deprecated), and deprecated
methods to access dictionary fields.

Bug: 1301890
Change-Id: If2e501067bd3e1f6046d2ed70a74256ee2fb1763
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3727193
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1018691}
  • Loading branch information
Matt Menke authored and Chromium LUCI CQ committed Jun 28, 2022
1 parent 4d522ad commit 07b95e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions components/bookmarks/managed/managed_bookmarks_policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void ManagedBookmarksPolicyHandler::ApplyPolicySettings(
return;

prefs->SetString(prefs::kManagedBookmarksFolderName, GetFolderName(*value));
base::Value filtered(FilterBookmarks(std::move(*value).TakeListDeprecated()));
prefs->SetValue(prefs::kManagedBookmarks, std::move(filtered));
base::Value::List filtered(FilterBookmarks(std::move(value->GetList())));
prefs->SetValue(prefs::kManagedBookmarks, base::Value(std::move(filtered)));
}

std::string ManagedBookmarksPolicyHandler::GetFolderName(
Expand All @@ -62,43 +62,43 @@ std::string ManagedBookmarksPolicyHandler::GetFolderName(
return std::string();
}

base::Value::ListStorage ManagedBookmarksPolicyHandler::FilterBookmarks(
base::Value::ListStorage list) {
base::Value::List ManagedBookmarksPolicyHandler::FilterBookmarks(
base::Value::List list) {
// Move over conforming values found.
base::Value::ListStorage out;
base::Value::List out;

for (base::Value& item : list) {
if (!item.is_dict())
continue;

const std::string* name =
item.FindStringKey(ManagedBookmarksTracker::kName);
const std::string* url = item.FindStringKey(ManagedBookmarksTracker::kUrl);
base::Value* children =
item.FindListKey(ManagedBookmarksTracker::kChildren);
base::Value::Dict& dict = item.GetDict();
const std::string* name = dict.FindString(ManagedBookmarksTracker::kName);
const std::string* url = dict.FindString(ManagedBookmarksTracker::kUrl);
base::Value::List* children =
dict.FindList(ManagedBookmarksTracker::kChildren);
// Every bookmark must have a name, and then either a URL of a list of
// child bookmarks.
if (!name || (!url && !children))
continue;

if (children) {
// Ignore the URL if this bookmark has child nodes.
item.RemoveKey(ManagedBookmarksTracker::kUrl);
*children = base::Value(
FilterBookmarks(std::move(*children).TakeListDeprecated()));
*children = FilterBookmarks(std::move(*children));
// Ignore the URL if this bookmark has child nodes. Note that this needs
// to be after `children` is overwritten, in case removing an entry from
// the dictionary invalidates its pointers.
dict.Remove(ManagedBookmarksTracker::kUrl);
} else {
// Make sure the URL is valid before passing a bookmark to the pref.
item.RemoveKey(ManagedBookmarksTracker::kChildren);
dict.Remove(ManagedBookmarksTracker::kChildren);
GURL gurl = url_formatter::FixupURL(*url, std::string());
if (!gurl.is_valid()) {
continue;
}
item.SetStringKey(ManagedBookmarksTracker::kUrl, gurl.spec());
dict.Set(ManagedBookmarksTracker::kUrl, gurl.spec());
}

out.push_back(std::move(item));
out.Append(std::move(item));
}
list.clear();
return out;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ManagedBookmarksPolicyHandler

private:
std::string GetFolderName(const base::Value& list);
base::Value::ListStorage FilterBookmarks(base::Value::ListStorage bookmarks);
base::Value::List FilterBookmarks(base::Value::List bookmarks);
};

} // namespace bookmarks
Expand Down

0 comments on commit 07b95e0

Please sign in to comment.