Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1532)

Unified Diff: components/ntp_tiles/popular_sites_impl.cc

Issue 2668943002: provide static popular sites for first run (Closed)
Patch Set: most_visited_unittest registers prefs properly. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f39024bef903b27d15c40e2076ad817d35726aaa 100644
--- a/components/ntp_tiles/popular_sites_impl.cc
+++ b/components/ntp_tiles/popular_sites_impl.cc
@@ -19,6 +19,7 @@
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/google/core/browser/google_util.h"
#include "components/ntp_tiles/constants.h"
+#include "components/ntp_tiles/field_trial.h"
#include "components/ntp_tiles/pref_names.h"
#include "components/ntp_tiles/switches.h"
#include "components/pref_registry/pref_registry_syncable.h"
@@ -30,6 +31,12 @@
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
+#if defined(OS_ANDROID) || defined(OS_IOS)
+#include "base/json/json_reader.h"
+#include "components/grit/components_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#endif
+
#if defined(OS_IOS)
#include "components/ntp_tiles/country_code_ios.h"
#endif
@@ -125,6 +132,19 @@ PopularSites::SitesVector ParseSiteList(const base::ListValue& list) {
return sites;
}
+// Creates the List of popular sites based on a snapshot available for mobile.
sdefresne 2017/02/14 12:37:35 s/List/list/
fhorschig 2017/02/14 17:24:15 Done.
+std::unique_ptr<base::ListValue> DefaultPopularSites() {
+#if defined(OS_ANDROID) || defined(OS_IOS)
+ std::unique_ptr<base::ListValue> sites =
+ base::ListValue::From(base::JSONReader().ReadToValue(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DEFAULT_POPULAR_SITES_JSON)));
+ DCHECK(sites);
+ return sites;
+#endif
+ return base::MakeUnique<base::ListValue>();
+}
+
} // namespace
PopularSites::Site::Site(const base::string16& title,
@@ -158,6 +178,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 +215,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 +300,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() {

Powered by Google App Engine
This is Rietveld 408576698