Index: components/ntp_tiles/popular_sites_impl.cc |
diff --git a/components/ntp_tiles/popular_sites_impl.cc b/components/ntp_tiles/popular_sites_impl.cc |
index ce69227f271e9376aba9c43dd4b9217778926d26..020893ac52e4872973f3d06f256751fb5a4bdfe9 100644 |
--- a/components/ntp_tiles/popular_sites_impl.cc |
+++ b/components/ntp_tiles/popular_sites_impl.cc |
@@ -11,6 +11,7 @@ |
#include "base/command_line.h" |
#include "base/files/file_path.h" |
#include "base/files/file_util.h" |
+#include "base/json/json_reader.h" |
#include "base/path_service.h" |
#include "base/strings/string_util.h" |
#include "base/strings/stringprintf.h" |
@@ -18,6 +19,7 @@ |
#include "base/values.h" |
#include "components/data_use_measurement/core/data_use_user_data.h" |
#include "components/google/core/browser/google_util.h" |
+#include "components/grit/components_resources.h" |
#include "components/ntp_tiles/constants.h" |
#include "components/ntp_tiles/pref_names.h" |
#include "components/ntp_tiles/switches.h" |
@@ -29,6 +31,7 @@ |
#include "components/variations/variations_associated_data.h" |
#include "net/base/load_flags.h" |
#include "net/http/http_status_code.h" |
+#include "ui/base/resource/resource_bundle.h" |
#if defined(OS_IOS) |
#include "components/ntp_tiles/country_code_ios.h" |
@@ -125,6 +128,15 @@ PopularSites::SitesVector ParseSiteList(const base::ListValue& list) { |
return sites; |
} |
+std::unique_ptr<base::ListValue> DefaultPopularSites() { |
+ std::unique_ptr<base::ListValue> sites = |
+ base::ListValue::From(base::JSONReader().ReadToValue( |
+ ResourceBundle::GetSharedInstance().GetRawDataResource( |
+ IDR_DEFAULT_POPULAR_SITES_JSON))); |
+ DCHECK(sites); |
+ return sites; |
+} |
+ |
} // namespace |
PopularSites::Site::Site(const base::string16& title, |
@@ -158,6 +170,7 @@ PopularSitesImpl::PopularSitesImpl( |
download_context_(download_context), |
parse_json_(std::move(parse_json)), |
is_fallback_(false), |
+ sites_(ParseSiteList(*prefs_->GetList(kPopularSitesJsonPref))), |
weak_ptr_factory_(this) { |
// If valid path provided, remove local files created by older versions. |
if (!directory.empty() && blocking_runner_) { |
@@ -194,17 +207,7 @@ bool PopularSitesImpl::MaybeStartFetch(bool force_download, |
FetchPopularSites(); |
return true; |
} |
- |
- const base::ListValue* json = prefs_->GetList(kPopularSitesJsonPref); |
- if (!json) { |
- // Cache didn't exist. |
- FetchPopularSites(); |
- return true; |
- } else { |
- // Note that we don't run the callback. |
- sites_ = ParseSiteList(*json); |
- return false; |
- } |
+ return false; |
} |
const PopularSites::SitesVector& PopularSitesImpl::sites() const { |
@@ -289,7 +292,8 @@ void PopularSitesImpl::RegisterProfilePrefs( |
user_prefs->RegisterInt64Pref(kPopularSitesLastDownloadPref, 0); |
user_prefs->RegisterStringPref(kPopularSitesURLPref, std::string()); |
- user_prefs->RegisterListPref(kPopularSitesJsonPref); |
+ user_prefs->RegisterListPref(kPopularSitesJsonPref, |
+ DefaultPopularSites().release()); |
} |
void PopularSitesImpl::FetchPopularSites() { |