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

Unified Diff: components/ntp_tiles/popular_sites.cc

Issue 2570783003: [Popular Sites] Split PopularSites interface and PopularSitesImpl (Closed)
Patch Set: Split PopularSitesImpl. Created 4 years 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.cc
diff --git a/components/ntp_tiles/popular_sites.cc b/components/ntp_tiles/popular_sites.cc
index 02120f37ec3c647cc6b5b43cbf8940b5f6d0bceb..58fa44d531fb068af959d98be157fc43c16f2108 100644
--- a/components/ntp_tiles/popular_sites.cc
+++ b/components/ntp_tiles/popular_sites.cc
@@ -177,7 +177,7 @@ PopularSites::Site::Site(const Site& other) = default;
PopularSites::Site::~Site() {}
-PopularSites::PopularSites(
+PopularSitesImpl::PopularSitesImpl(
const scoped_refptr<base::SequencedWorkerPool>& blocking_pool,
PrefService* prefs,
const TemplateURLService* template_url_service,
@@ -198,10 +198,10 @@ PopularSites::PopularSites(
is_fallback_(false),
weak_ptr_factory_(this) {}
-PopularSites::~PopularSites() {}
+PopularSitesImpl::~PopularSitesImpl() {}
-void PopularSites::StartFetch(bool force_download,
- const FinishedCallback& callback) {
+void PopularSitesImpl::StartFetch(bool force_download,
+ const FinishedCallback& callback) {
DCHECK(!callback_);
callback_ = callback;
@@ -243,16 +243,21 @@ void PopularSites::StartFetch(bool force_download,
base::PostTaskAndReplyWithResult(
blocking_runner_.get(), FROM_HERE,
base::Bind(&base::ReadFileToString, local_path_, file_data_ptr),
- base::Bind(&PopularSites::OnReadFileDone, weak_ptr_factory_.GetWeakPtr(),
+ base::Bind(&PopularSitesImpl::OnReadFileDone,
+ weak_ptr_factory_.GetWeakPtr(),
base::Passed(std::move(file_data))));
}
-GURL PopularSites::LastURL() const {
+const PopularSites::SitesVector& PopularSitesImpl::sites() const {
+ return sites_;
+}
+
+GURL PopularSitesImpl::LastURL() const {
return GURL(prefs_->GetString(kPopularSitesURLPref));
}
// static
-void PopularSites::RegisterProfilePrefs(
+void PopularSitesImpl::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* user_prefs) {
user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideURL,
std::string());
@@ -265,8 +270,8 @@ void PopularSites::RegisterProfilePrefs(
user_prefs->RegisterStringPref(kPopularSitesURLPref, std::string());
}
-void PopularSites::OnReadFileDone(std::unique_ptr<std::string> data,
- bool success) {
+void PopularSitesImpl::OnReadFileDone(std::unique_ptr<std::string> data,
+ bool success) {
if (success) {
auto json = base::JSONReader::Read(*data, base::JSON_ALLOW_TRAILING_COMMAS);
if (json) {
@@ -280,7 +285,7 @@ void PopularSites::OnReadFileDone(std::unique_ptr<std::string> data,
}
}
-void PopularSites::FetchPopularSites() {
+void PopularSitesImpl::FetchPopularSites() {
fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this);
data_use_measurement::DataUseUserData::AttachToFetcher(
fetcher_.get(), data_use_measurement::DataUseUserData::NTP_TILES);
@@ -291,7 +296,7 @@ void PopularSites::FetchPopularSites() {
fetcher_->Start();
}
-void PopularSites::OnURLFetchComplete(const net::URLFetcher* source) {
+void PopularSitesImpl::OnURLFetchComplete(const net::URLFetcher* source) {
DCHECK_EQ(fetcher_.get(), source);
std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_);
@@ -303,29 +308,29 @@ void PopularSites::OnURLFetchComplete(const net::URLFetcher* source) {
return;
}
- parse_json_.Run(
- json_string,
- base::Bind(&PopularSites::OnJsonParsed, weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&PopularSites::OnJsonParseFailed,
- weak_ptr_factory_.GetWeakPtr()));
+ parse_json_.Run(json_string, base::Bind(&PopularSitesImpl::OnJsonParsed,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&PopularSitesImpl::OnJsonParseFailed,
+ weak_ptr_factory_.GetWeakPtr()));
}
-void PopularSites::OnJsonParsed(std::unique_ptr<base::Value> json) {
+void PopularSitesImpl::OnJsonParsed(std::unique_ptr<base::Value> json) {
const base::Value* json_ptr = json.get();
base::PostTaskAndReplyWithResult(
blocking_runner_.get(), FROM_HERE,
base::Bind(&WriteJsonToFile, local_path_, json_ptr),
- base::Bind(&PopularSites::OnFileWriteDone, weak_ptr_factory_.GetWeakPtr(),
+ base::Bind(&PopularSitesImpl::OnFileWriteDone,
+ weak_ptr_factory_.GetWeakPtr(),
base::Passed(std::move(json))));
}
-void PopularSites::OnJsonParseFailed(const std::string& error_message) {
+void PopularSitesImpl::OnJsonParseFailed(const std::string& error_message) {
DLOG(WARNING) << "JSON parsing failed: " << error_message;
OnDownloadFailed();
}
-void PopularSites::OnFileWriteDone(std::unique_ptr<base::Value> json,
- bool success) {
+void PopularSitesImpl::OnFileWriteDone(std::unique_ptr<base::Value> json,
+ bool success) {
if (success) {
prefs_->SetInt64(kPopularSitesLastDownloadPref,
base::Time::Now().ToInternalValue());
@@ -338,7 +343,7 @@ void PopularSites::OnFileWriteDone(std::unique_ptr<base::Value> json,
}
}
-void PopularSites::ParseSiteList(std::unique_ptr<base::Value> json) {
+void PopularSitesImpl::ParseSiteList(std::unique_ptr<base::Value> json) {
base::ListValue* list = nullptr;
if (!json || !json->GetAsList(&list)) {
DLOG(WARNING) << "JSON is not a list";
@@ -347,7 +352,7 @@ void PopularSites::ParseSiteList(std::unique_ptr<base::Value> json) {
return;
}
- std::vector<PopularSites::Site> sites;
+ SitesVector sites;
for (size_t i = 0; i < list->GetSize(); i++) {
base::DictionaryValue* item;
if (!list->GetDictionary(i, &item))
@@ -363,16 +368,16 @@ void PopularSites::ParseSiteList(std::unique_ptr<base::Value> json) {
std::string large_icon_url;
item->GetString("large_icon_url", &large_icon_url);
- sites.push_back(PopularSites::Site(title, GURL(url), GURL(favicon_url),
- GURL(large_icon_url),
- GURL(thumbnail_url)));
+ sites.push_back(PopularSitesImpl::Site(title, GURL(url), GURL(favicon_url),
+ GURL(large_icon_url),
+ GURL(thumbnail_url)));
}
sites_.swap(sites);
callback_.Run(true);
}
-void PopularSites::OnDownloadFailed() {
+void PopularSitesImpl::OnDownloadFailed() {
if (!is_fallback_) {
DLOG(WARNING) << "Download country site list failed";
is_fallback_ = true;

Powered by Google App Engine
This is Rietveld 408576698