Commit 5ac492eb authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Remove JSONReader::ReadDeprecated() usage in popular_sites_impl.cc.

Switch to base::JSONReader::Read() and also modernize base::Value usage
in the modified functions.

Bug: 925165
Change-Id: Ie0062059b2ab1a1c28e4bd658074d6ce9bd658ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894312
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711878}
parent fd5f761d
...@@ -196,14 +196,14 @@ std::map<SectionType, PopularSites::SitesVector> ParseSites( ...@@ -196,14 +196,14 @@ std::map<SectionType, PopularSites::SitesVector> ParseSites(
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && \ #if BUILDFLAG(GOOGLE_CHROME_BRANDING) && \
(defined(OS_ANDROID) || defined(OS_IOS)) (defined(OS_ANDROID) || defined(OS_IOS))
void SetDefaultResourceForSite(int index, void SetDefaultResourceForSite(size_t index,
int resource_id, int resource_id,
base::ListValue* sites) { base::Value* sites) {
base::DictionaryValue* site; base::Value::ListStorage& list = sites->GetList();
if (!sites->GetDictionary(index, &site)) if (index >= list.size() || !list[index].is_dict())
return; return;
site->SetInteger("default_icon_resource", resource_id); list[index].SetIntKey("default_icon_resource", resource_id);
} }
#endif #endif
...@@ -215,26 +215,23 @@ base::Value DefaultPopularSites() { ...@@ -215,26 +215,23 @@ base::Value DefaultPopularSites() {
if (!base::FeatureList::IsEnabled(kPopularSitesBakedInContentFeature)) if (!base::FeatureList::IsEnabled(kPopularSitesBakedInContentFeature))
return base::Value(base::Value::Type::LIST); return base::Value(base::Value::Type::LIST);
std::unique_ptr<base::ListValue> sites = base::Optional<base::Value> sites = base::JSONReader::Read(
base::ListValue::From(base::JSONReader::ReadDeprecated(
ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DEFAULT_POPULAR_SITES_JSON))); IDR_DEFAULT_POPULAR_SITES_JSON));
DCHECK(sites); for (base::Value& site : sites.value().GetList())
for (base::Value& site : *sites) { site.SetBoolKey("baked_in", true);
base::DictionaryValue& dict = static_cast<base::DictionaryValue&>(site);
dict.SetBoolean("baked_in", true);
}
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
int index = 0; size_t index = 0;
for (int icon_resource : for (int icon_resource :
{IDR_DEFAULT_POPULAR_SITES_ICON0, IDR_DEFAULT_POPULAR_SITES_ICON1, {IDR_DEFAULT_POPULAR_SITES_ICON0, IDR_DEFAULT_POPULAR_SITES_ICON1,
IDR_DEFAULT_POPULAR_SITES_ICON2, IDR_DEFAULT_POPULAR_SITES_ICON3, IDR_DEFAULT_POPULAR_SITES_ICON2, IDR_DEFAULT_POPULAR_SITES_ICON3,
IDR_DEFAULT_POPULAR_SITES_ICON4, IDR_DEFAULT_POPULAR_SITES_ICON5, IDR_DEFAULT_POPULAR_SITES_ICON4, IDR_DEFAULT_POPULAR_SITES_ICON5,
IDR_DEFAULT_POPULAR_SITES_ICON6, IDR_DEFAULT_POPULAR_SITES_ICON7}) { IDR_DEFAULT_POPULAR_SITES_ICON6, IDR_DEFAULT_POPULAR_SITES_ICON7}) {
SetDefaultResourceForSite(index++, icon_resource, sites.get()); SetDefaultResourceForSite(index++, icon_resource, &sites.value());
} }
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
return base::Value::FromUniquePtrValue(std::move(sites)); return std::move(sites.value());
#endif // OS_ANDROID || OS_IOS #endif // OS_ANDROID || OS_IOS
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment