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..f5cf7fb085d94ca7962916f819db044c36aded1c 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,27 @@ PopularSites::SitesVector ParseSiteList(const base::ListValue& list) { |
return sites; |
} |
+PopularSites::SitesVector GetDefaultFromPrefs(const PrefService& prefs) { |
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
+ if (command_line->HasSwitch(ntp_tiles::switches::kDisableNTPPopularSites)) { |
sfiera
2017/02/13 10:58:01
This check is not sufficient; use field_trial.h.
fhorschig
2017/02/13 14:57:00
Done.
sfiera
2017/02/13 15:05:54
If the test is going to instantiate the class, it
fhorschig
2017/02/13 18:13:44
Done.
|
+ return PopularSites::SitesVector(); |
+ } |
+ return ParseSiteList(*prefs.GetList(kPopularSitesJsonPref)); |
+} |
+ |
+// Creates the List of popular sites based on a snapshot available for mobile. |
+std::unique_ptr<base::ListValue> DefaultPopularSites() { |
+#if defined(OS_IOS) || defined(OS_ANDROID) |
sfiera
2017/02/13 10:58:01
Alphabetically, Android is before iOS. Just sayin'
fhorschig
2017/02/13 14:57:00
Done.
|
+ 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 +182,7 @@ PopularSitesImpl::PopularSitesImpl( |
download_context_(download_context), |
parse_json_(std::move(parse_json)), |
is_fallback_(false), |
+ sites_(GetDefaultFromPrefs(*prefs_)), |
weak_ptr_factory_(this) { |
// If valid path provided, remove local files created by older versions. |
if (!directory.empty() && blocking_runner_) { |
@@ -194,17 +219,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 +304,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() { |