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

Unified Diff: chrome/browser/android/ntp/most_visited_sites.cc

Issue 1930353002: Invoke factories once in MostVisitedSites(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « chrome/browser/android/ntp/most_visited_sites.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/ntp/most_visited_sites.cc
diff --git a/chrome/browser/android/ntp/most_visited_sites.cc b/chrome/browser/android/ntp/most_visited_sites.cc
index 7b1de89be00a118b452baa49d13e27ffceee53a4..e43cfa71265bc77afe70a5976a26fb27937829bf 100644
--- a/chrome/browser/android/ntp/most_visited_sites.cc
+++ b/chrome/browser/android/ntp/most_visited_sites.cc
@@ -39,7 +39,6 @@ using content::BrowserThread;
using history::TopSites;
using suggestions::ChromeSuggestion;
using suggestions::SuggestionsProfile;
-using suggestions::SuggestionsService;
using suggestions::SuggestionsServiceFactory;
namespace {
@@ -178,7 +177,9 @@ MostVisitedSites::Suggestion&
MostVisitedSites::Suggestion::operator=(Suggestion&&) = default;
MostVisitedSites::MostVisitedSites(Profile* profile)
- : profile_(profile), observer_(nullptr), num_sites_(0),
+ : profile_(profile), top_sites_(TopSitesFactory::GetForProfile(profile)),
+ suggestions_service_(SuggestionsServiceFactory::GetForProfile(profile_)),
+ observer_(nullptr), num_sites_(0),
received_most_visited_sites_(false), received_popular_sites_(false),
recorded_uma_(false), scoped_observer_(this), weak_ptr_factory_(this) {
// Register the thumbnails debugging page.
@@ -213,40 +214,36 @@ void MostVisitedSites::SetMostVisitedURLsObserver(
received_popular_sites_ = true;
}
- scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
- if (top_sites) {
+ if (top_sites_) {
// TopSites updates itself after a delay. To ensure up-to-date results,
// force an update now.
- top_sites->SyncWithHistory();
+ top_sites_->SyncWithHistory();
// Register as TopSitesObserver so that we can update ourselves when the
// TopSites changes.
- scoped_observer_.Add(top_sites.get());
+ scoped_observer_.Add(top_sites_.get());
}
- SuggestionsService* suggestions_service =
- SuggestionsServiceFactory::GetForProfile(profile_);
- suggestions_subscription_ = suggestions_service->AddCallback(
+ suggestions_subscription_ = suggestions_service_->AddCallback(
base::Bind(&MostVisitedSites::OnSuggestionsProfileAvailable,
base::Unretained(this)));
// Immediately get the current suggestions from the cache. If the cache is
// empty, this will fall back to TopSites.
OnSuggestionsProfileAvailable(
- suggestions_service->GetSuggestionsDataFromCache());
+ suggestions_service_->GetSuggestionsDataFromCache());
// Also start a request for fresh suggestions.
- suggestions_service->FetchSuggestionsData();
+ suggestions_service_->FetchSuggestionsData();
}
void MostVisitedSites::GetURLThumbnail(
const GURL& url,
const ThumbnailCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::DB, FROM_HERE,
- base::Bind(&MaybeFetchLocalThumbnail, url, top_sites),
+ base::Bind(&MaybeFetchLocalThumbnail, url, top_sites_),
base::Bind(&MostVisitedSites::OnLocalThumbnailFetched,
weak_ptr_factory_.GetWeakPtr(), url, callback));
}
@@ -259,27 +256,24 @@ void MostVisitedSites::OnLocalThumbnailFetched(
if (!bitmap.get()) {
// A thumbnail is not locally available for |url|. Make sure it is put in
// the list to be fetched at the next visit to this site.
- scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
- if (top_sites)
- top_sites->AddForcedURL(url, base::Time::Now());
+ if (top_sites_)
+ top_sites_->AddForcedURL(url, base::Time::Now());
// Also fetch a remote thumbnail if possible. PopularSites or the
// SuggestionsService can supply a thumbnail download URL.
- SuggestionsService* suggestions_service =
- SuggestionsServiceFactory::GetForProfile(profile_);
if (popular_sites_) {
const std::vector<PopularSites::Site>& sites = popular_sites_->sites();
auto it = std::find_if(
sites.begin(), sites.end(),
[&url](const PopularSites::Site& site) { return site.url == url; });
if (it != sites.end() && it->thumbnail_url.is_valid()) {
- return suggestions_service->GetPageThumbnailWithURL(
+ return suggestions_service_->GetPageThumbnailWithURL(
url, it->thumbnail_url,
base::Bind(&MostVisitedSites::OnObtainedThumbnail,
weak_ptr_factory_.GetWeakPtr(), false, callback));
}
}
if (mv_source_ == SUGGESTIONS_SERVICE) {
- return suggestions_service->GetPageThumbnail(
+ return suggestions_service_->GetPageThumbnail(
url, base::Bind(&MostVisitedSites::OnObtainedThumbnail,
weak_ptr_factory_.GetWeakPtr(), false, callback));
}
@@ -299,22 +293,19 @@ void MostVisitedSites::OnObtainedThumbnail(
void MostVisitedSites::AddOrRemoveBlacklistedUrl(
const GURL& url, bool add_url) {
// Always blacklist in the local TopSites.
- scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
- if (top_sites) {
+ if (top_sites_) {
if (add_url)
- top_sites->AddBlacklistedURL(url);
+ top_sites_->AddBlacklistedURL(url);
else
- top_sites->RemoveBlacklistedURL(url);
+ top_sites_->RemoveBlacklistedURL(url);
}
// Only blacklist in the server-side suggestions service if it's active.
if (mv_source_ == SUGGESTIONS_SERVICE) {
- SuggestionsService* suggestions_service =
- SuggestionsServiceFactory::GetForProfile(profile_);
if (add_url)
- suggestions_service->BlacklistURL(url);
+ suggestions_service_->BlacklistURL(url);
else
- suggestions_service->UndoBlacklistURL(url);
+ suggestions_service_->UndoBlacklistURL(url);
}
}
@@ -365,9 +356,7 @@ void MostVisitedSites::RegisterProfilePrefs(
}
void MostVisitedSites::QueryMostVisitedURLs() {
- SuggestionsService* suggestions_service =
- SuggestionsServiceFactory::GetForProfile(profile_);
- if (suggestions_service->FetchSuggestionsData()) {
+ if (suggestions_service_->FetchSuggestionsData()) {
// A suggestions network request is on its way. We'll be called back via
// OnSuggestionsProfileAvailable.
return;
@@ -376,15 +365,14 @@ void MostVisitedSites::QueryMostVisitedURLs() {
// cache. If that also returns nothing, OnSuggestionsProfileAvailable will
// call InitiateTopSitesQuery.
OnSuggestionsProfileAvailable(
- suggestions_service->GetSuggestionsDataFromCache());
+ suggestions_service_->GetSuggestionsDataFromCache());
}
void MostVisitedSites::InitiateTopSitesQuery() {
- scoped_refptr<TopSites> top_sites = TopSitesFactory::GetForProfile(profile_);
- if (!top_sites)
+ if (!top_sites_)
return;
- top_sites->GetMostVisitedURLs(
+ top_sites_->GetMostVisitedURLs(
base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable,
weak_ptr_factory_.GetWeakPtr()),
false);
@@ -493,11 +481,10 @@ MostVisitedSites::CreateWhitelistEntryPointSuggestions(
std::set<std::string> personal_hosts;
for (const auto& suggestion : personal_suggestions)
personal_hosts.insert(suggestion->url.host());
- scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
for (const auto& whitelist : supervised_user_service->whitelists()) {
// Skip blacklisted sites.
- if (top_sites && top_sites->IsBlacklisted(whitelist->entry_point()))
+ if (top_sites_ && top_sites_->IsBlacklisted(whitelist->entry_point()))
continue;
// Skip suggestions already present.
@@ -548,10 +535,9 @@ MostVisitedSites::CreatePopularSitesSuggestions(
hosts.insert(suggestion->url.host());
for (const auto& suggestion : whitelist_suggestions)
hosts.insert(suggestion->url.host());
- scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_));
for (const PopularSites::Site& popular_site : popular_sites_->sites()) {
// Skip blacklisted sites.
- if (top_sites && top_sites->IsBlacklisted(popular_site.url))
+ if (top_sites_ && top_sites_->IsBlacklisted(popular_site.url))
continue;
std::string host = popular_site.url.host();
// Skip suggestions already present in personal or whitelists.
« no previous file with comments | « chrome/browser/android/ntp/most_visited_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698