Chromium Code Reviews| Index: components/history/core/browser/top_sites_impl.cc |
| diff --git a/components/history/core/browser/top_sites_impl.cc b/components/history/core/browser/top_sites_impl.cc |
| index 57e72498d659f69250d919a70a96d9e6c81722e8..b9ae71596b59ed7266fd9c563fbb936c0fce41db 100644 |
| --- a/components/history/core/browser/top_sites_impl.cc |
| +++ b/components/history/core/browser/top_sites_impl.cc |
| @@ -172,41 +172,6 @@ bool TopSitesImpl::SetPageThumbnail(const GURL& url, |
| return SetPageThumbnailEncoded(url, thumbnail_data.get(), score); |
| } |
| -bool TopSitesImpl::SetPageThumbnailToJPEGBytes( |
| - const GURL& url, |
| - const base::RefCountedMemory* memory, |
| - const ThumbnailScore& score) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - |
| - if (!loaded_) { |
| - // TODO(sky): I need to cache these and apply them after the load |
| - // completes. |
| - return false; |
| - } |
| - |
| - bool add_temp_thumbnail = false; |
| - if (!IsKnownURL(url)) { |
| - if (!IsNonForcedFull()) { |
| - add_temp_thumbnail = true; |
| - } else { |
| - return false; // This URL is not known to us. |
| - } |
| - } |
| - |
| - if (!can_add_url_to_history_.Run(url)) |
| - return false; // It's not a real webpage. |
| - |
| - if (add_temp_thumbnail) { |
| - // Always remove the existing entry and then add it back. That way if we end |
| - // up with too many temp thumbnails we'll prune the oldest first. |
| - RemoveTemporaryThumbnailByURL(url); |
| - AddTemporaryThumbnail(url, memory, score); |
| - return true; |
| - } |
| - |
| - return SetPageThumbnailEncoded(url, memory, score); |
| -} |
| - |
| // WARNING: this function may be invoked on any thread. |
| void TopSitesImpl::GetMostVisitedURLs( |
| const GetMostVisitedURLsCallback& callback, |
| @@ -366,6 +331,79 @@ void TopSitesImpl::ClearBlacklistedURLs() { |
| NotifyTopSitesChanged(TopSitesObserver::ChangeReason::BLACKLIST); |
| } |
| +bool TopSitesImpl::IsKnownURL(const GURL& url) { |
|
sdefresne
2016/12/21 12:57:09
I assume you are just reordering function to match
Marc Treib
2016/12/26 19:56:51
Yup, exactly. The only change apart from the reord
|
| + return loaded_ && cache_->IsKnownURL(url); |
| +} |
| + |
| +bool TopSitesImpl::IsNonForcedFull() { |
| + return loaded_ && cache_->GetNumNonForcedURLs() >= kNonForcedTopSitesNumber; |
| +} |
| + |
| +bool TopSitesImpl::IsForcedFull() { |
| + return loaded_ && cache_->GetNumForcedURLs() >= kForcedTopSitesNumber; |
| +} |
| + |
| +PrepopulatedPageList TopSitesImpl::GetPrepopulatedPages() { |
| + return prepopulated_pages_; |
| +} |
| + |
| +bool TopSitesImpl::loaded() const { |
| + return loaded_; |
| +} |
| + |
| +bool TopSitesImpl::AddForcedURL(const GURL& url, const base::Time& time) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + if (!loaded_) { |
| + // Optimally we could cache this and apply it after the load completes, but |
| + // in practice it's not an issue since AddForcedURL will be called again |
| + // next time the user hits the NTP. |
| + return false; |
| + } |
| + |
| + size_t num_forced = cache_->GetNumForcedURLs(); |
| + MostVisitedURLList new_list(cache_->top_sites()); |
| + MostVisitedURL new_url; |
| + |
| + if (cache_->IsKnownURL(url)) { |
| + size_t index = cache_->GetURLIndex(url); |
| + // Do nothing if we currently have that URL as non-forced. |
| + if (new_list[index].last_forced_time.is_null()) |
| + return false; |
| + |
| + // Update the |last_forced_time| of the already existing URL. Delete it and |
| + // reinsert it at the right location. |
| + new_url = new_list[index]; |
| + new_list.erase(new_list.begin() + index); |
| + num_forced--; |
| + } else { |
| + new_url.url = url; |
| + new_url.redirects.push_back(url); |
| + } |
| + new_url.last_forced_time = time; |
| + // Add forced URLs and sort. Added to the end of the list of forced URLs |
| + // since this is almost always where it needs to go, unless the user's local |
| + // clock is fiddled with. |
| + MostVisitedURLList::iterator mid = new_list.begin() + num_forced; |
| + new_list.insert(mid, new_url); |
| + mid = new_list.begin() + num_forced; // Mid was invalidated. |
| + std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator); |
| + SetTopSites(new_list, CALL_LOCATION_FROM_FORCED_URLS); |
| + return true; |
| +} |
| + |
| +void TopSitesImpl::OnNavigationCommitted(const GURL& url) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!loaded_ || IsNonForcedFull()) |
| + return; |
| + |
| + if (!cache_->IsKnownURL(url) && can_add_url_to_history_.Run(url)) { |
| + // To avoid slamming history we throttle requests when the url updates. To |
| + // do otherwise negatively impacts perf tests. |
| + RestartQueryForTopSitesTimer(GetUpdateDelay()); |
| + } |
| +} |
| + |
| void TopSitesImpl::ShutdownOnUIThread() { |
| history_service_ = nullptr; |
| history_service_observer_.RemoveAll(); |
| @@ -382,6 +420,20 @@ void TopSitesImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
| registry->RegisterDictionaryPref(kMostVisitedURLsBlacklist); |
| } |
| +TopSitesImpl::~TopSitesImpl() = default; |
| + |
| +void TopSitesImpl::StartQueryForMostVisited() { |
| + DCHECK(loaded_); |
| + if (!history_service_) |
| + return; |
| + |
| + history_service_->QueryMostVisitedURLs( |
| + num_results_to_request_from_history(), kDaysOfHistory, |
| + base::Bind(&TopSitesImpl::OnTopSitesAvailableFromHistory, |
| + base::Unretained(this)), |
| + &cancelable_task_tracker_); |
| +} |
| + |
| // static |
| void TopSitesImpl::DiffMostVisited(const MostVisitedURLList& old_list, |
| const MostVisitedURLList& new_list, |
| @@ -444,37 +496,6 @@ void TopSitesImpl::DiffMostVisited(const MostVisitedURLList& old_list, |
| } |
| } |
| -base::CancelableTaskTracker::TaskId TopSitesImpl::StartQueryForMostVisited() { |
| - DCHECK(loaded_); |
| - if (!history_service_) |
| - return base::CancelableTaskTracker::kBadTaskId; |
| - |
| - return history_service_->QueryMostVisitedURLs( |
| - num_results_to_request_from_history(), kDaysOfHistory, |
| - base::Bind(&TopSitesImpl::OnTopSitesAvailableFromHistory, |
| - base::Unretained(this)), |
| - &cancelable_task_tracker_); |
| -} |
| - |
| -bool TopSitesImpl::IsKnownURL(const GURL& url) { |
| - return loaded_ && cache_->IsKnownURL(url); |
| -} |
| - |
| -const std::string& TopSitesImpl::GetCanonicalURLString(const GURL& url) const { |
| - return cache_->GetCanonicalURL(url).spec(); |
| -} |
| - |
| -bool TopSitesImpl::IsNonForcedFull() { |
| - return loaded_ && cache_->GetNumNonForcedURLs() >= kNonForcedTopSitesNumber; |
| -} |
| - |
| -bool TopSitesImpl::IsForcedFull() { |
| - return loaded_ && cache_->GetNumForcedURLs() >= kForcedTopSitesNumber; |
| -} |
| - |
| -TopSitesImpl::~TopSitesImpl() { |
| -} |
| - |
| bool TopSitesImpl::SetPageThumbnailNoDB( |
| const GURL& url, |
| const base::RefCountedMemory* thumbnail_data, |
| @@ -581,67 +602,6 @@ int TopSitesImpl::GetRedirectDistanceForURL(const MostVisitedURL& most_visited, |
| return 0; |
| } |
| -PrepopulatedPageList TopSitesImpl::GetPrepopulatedPages() { |
| - return prepopulated_pages_; |
| -} |
| - |
| -bool TopSitesImpl::loaded() const { |
| - return loaded_; |
| -} |
| - |
| -bool TopSitesImpl::AddForcedURL(const GURL& url, const base::Time& time) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - |
| - if (!loaded_) { |
| - // Optimally we could cache this and apply it after the load completes, but |
| - // in practice it's not an issue since AddForcedURL will be called again |
| - // next time the user hits the NTP. |
| - return false; |
| - } |
| - |
| - size_t num_forced = cache_->GetNumForcedURLs(); |
| - MostVisitedURLList new_list(cache_->top_sites()); |
| - MostVisitedURL new_url; |
| - |
| - if (cache_->IsKnownURL(url)) { |
| - size_t index = cache_->GetURLIndex(url); |
| - // Do nothing if we currently have that URL as non-forced. |
| - if (new_list[index].last_forced_time.is_null()) |
| - return false; |
| - |
| - // Update the |last_forced_time| of the already existing URL. Delete it and |
| - // reinsert it at the right location. |
| - new_url = new_list[index]; |
| - new_list.erase(new_list.begin() + index); |
| - num_forced--; |
| - } else { |
| - new_url.url = url; |
| - new_url.redirects.push_back(url); |
| - } |
| - new_url.last_forced_time = time; |
| - // Add forced URLs and sort. Added to the end of the list of forced URLs |
| - // since this is almost always where it needs to go, unless the user's local |
| - // clock is fiddled with. |
| - MostVisitedURLList::iterator mid = new_list.begin() + num_forced; |
| - new_list.insert(mid, new_url); |
| - mid = new_list.begin() + num_forced; // Mid was invalidated. |
| - std::inplace_merge(new_list.begin(), mid, mid + 1, ForcedURLComparator); |
| - SetTopSites(new_list, CALL_LOCATION_FROM_FORCED_URLS); |
| - return true; |
| -} |
| - |
| -void TopSitesImpl::OnNavigationCommitted(const GURL& url) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - if (!loaded_ || IsNonForcedFull()) |
| - return; |
| - |
| - if (!cache_->IsKnownURL(url) && can_add_url_to_history_.Run(url)) { |
| - // To avoid slamming history we throttle requests when the url updates. To |
| - // do otherwise negatively impacts perf tests. |
| - RestartQueryForTopSitesTimer(GetUpdateDelay()); |
| - } |
| -} |
| - |
| bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls, |
| size_t num_forced_urls) { |
| bool added = false; |