Remove PopularSites' dependencies on //chrome/....
1. Fetch popular sites directly from PopularSites.
2. Move chrome paths dependency out of PopularSites.
Also, add better error-handling for if PathService::Get() fails. In that
case, immediately bail in PopularSites with failure.
3. Sanitize JSON before writing it to file.
Rather than downloading directly to a temporary file, download to a
string and sanitize it before writing to the file. When reading from a
cached file, don't bother sanitizing it.
BUG=603026
Review-Url: https://codereview.chromium.org/1957313003
Cr-Commit-Position: refs/heads/master@{#393278}
diff --git a/chrome/browser/android/ntp/most_visited_sites.cc b/chrome/browser/android/ntp/most_visited_sites.cc
index 31de1d8..ceac2e2 100644
--- a/chrome/browser/android/ntp/most_visited_sites.cc
+++ b/chrome/browser/android/ntp/most_visited_sites.cc
@@ -176,18 +176,27 @@
const TemplateURLService* template_url_service,
variations::VariationsService* variations_service,
net::URLRequestContextGetter* download_context,
+ const base::FilePath& popular_sites_directory,
scoped_refptr<history::TopSites> top_sites,
SuggestionsService* suggestions,
bool is_child_profile,
Profile* profile)
- : profile_(profile), prefs_(prefs),
+ : profile_(profile),
+ prefs_(prefs),
template_url_service_(template_url_service),
variations_service_(variations_service),
- download_context_(download_context), top_sites_(top_sites),
- suggestions_service_(suggestions), is_child_profile_(is_child_profile),
- observer_(nullptr), num_sites_(0), received_most_visited_sites_(false),
- received_popular_sites_(false), recorded_uma_(false),
- scoped_observer_(this), mv_source_(SUGGESTIONS_SERVICE),
+ download_context_(download_context),
+ popular_sites_directory_(popular_sites_directory),
+ top_sites_(top_sites),
+ suggestions_service_(suggestions),
+ is_child_profile_(is_child_profile),
+ observer_(nullptr),
+ num_sites_(0),
+ received_most_visited_sites_(false),
+ received_popular_sites_(false),
+ recorded_uma_(false),
+ scoped_observer_(this),
+ mv_source_(SUGGESTIONS_SERVICE),
weak_ptr_factory_(this) {
SupervisedUserService* supervised_user_service =
SupervisedUserServiceFactory::GetForProfile(profile_);
@@ -209,13 +218,9 @@
if (ShouldShowPopularSites() &&
NeedPopularSites(prefs_, num_sites_)) {
popular_sites_.reset(new PopularSites(
- prefs_,
- template_url_service_,
- variations_service_,
- download_context_,
- GetPopularSitesCountry(),
- GetPopularSitesVersion(),
- false,
+ prefs_, template_url_service_, variations_service_, download_context_,
+ popular_sites_directory_, GetPopularSitesCountry(),
+ GetPopularSitesVersion(), false,
base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
base::Unretained(this))));
} else {