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

Unified Diff: components/ntp_tiles/popular_sites_impl.cc

Issue 2841643005: [Popular Sites] Add Variations parameter to override URL path (Closed)
Patch Set: Update ntp-tiles-internals. Created 3 years, 8 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
« no previous file with comments | « components/ntp_tiles/popular_sites_impl.h ('k') | components/ntp_tiles/popular_sites_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f083770a26ebd13a3f58813acfd2d20841e5f690..eb52b3925c0aa182a4ec0f3f06881460b7cdd1a0 100644
--- a/components/ntp_tiles/popular_sites_impl.cc
+++ b/components/ntp_tiles/popular_sites_impl.cc
@@ -52,7 +52,8 @@ namespace ntp_tiles {
namespace {
const char kPopularSitesURLFormat[] =
- "https://www.gstatic.com/chrome/ntp/suggested_sites_%s_%s.json";
+ "https://www.gstatic.com/%ssuggested_sites_%s_%s.json";
+const char kPopularSitesDefaultDirectory[] = "chrome/ntp/";
const char kPopularSitesDefaultCountryCode[] = "DEFAULT";
const char kPopularSitesDefaultVersion[] = "5";
const int kPopularSitesRedownloadIntervalHours = 24;
@@ -65,10 +66,11 @@ const char kPopularSitesJsonPref[] = "suggested_sites_json";
// versions of Chrome, no longer used. Remove after M61.
const char kPopularSitesLocalFilenameToCleanup[] = "suggested_sites.json";
-GURL GetPopularSitesURL(const std::string& country,
+GURL GetPopularSitesURL(const std::string& directory,
+ const std::string& country,
const std::string& version) {
- return GURL(base::StringPrintf(kPopularSitesURLFormat, country.c_str(),
- version.c_str()));
+ return GURL(base::StringPrintf(kPopularSitesURLFormat, directory.c_str(),
+ country.c_str(), version.c_str()));
}
// Extract the country from the default search engine if the default search
@@ -259,13 +261,25 @@ GURL PopularSitesImpl::GetLastURLFetched() const {
}
GURL PopularSitesImpl::GetURLToFetch() {
+ const std::string directory = GetDirectoryToFetch();
const std::string country = GetCountryToFetch();
const std::string version = GetVersionToFetch();
const GURL override_url =
GURL(prefs_->GetString(ntp_tiles::prefs::kPopularSitesOverrideURL));
- return override_url.is_valid() ? override_url
- : GetPopularSitesURL(country, version);
+ return override_url.is_valid()
+ ? override_url
+ : GetPopularSitesURL(directory, country, version);
+}
+
+std::string PopularSitesImpl::GetDirectoryToFetch() {
+ std::string directory =
+ prefs_->GetString(ntp_tiles::prefs::kPopularSitesOverrideDirectory);
+
+ if (directory.empty())
+ directory = kPopularSitesDefaultDirectory;
+
+ return directory;
}
// Determine the country code to use. In order of precedence:
@@ -325,6 +339,8 @@ void PopularSitesImpl::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* user_prefs) {
user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideURL,
std::string());
+ user_prefs->RegisterStringPref(
+ ntp_tiles::prefs::kPopularSitesOverrideDirectory, std::string());
user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideCountry,
std::string());
user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideVersion,
@@ -413,7 +429,8 @@ void PopularSitesImpl::OnDownloadFailed() {
if (!is_fallback_) {
DLOG(WARNING) << "Download country site list failed";
is_fallback_ = true;
- pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode,
+ pending_url_ = GetPopularSitesURL(kPopularSitesDefaultDirectory,
+ kPopularSitesDefaultCountryCode,
kPopularSitesDefaultVersion);
FetchPopularSites();
} else {
« no previous file with comments | « components/ntp_tiles/popular_sites_impl.h ('k') | components/ntp_tiles/popular_sites_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698