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

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

Issue 2012473002: Remove NTP dependency on //content/... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 372090f08bd8bfc924ab982ee9b9716f3ee777cc..40e1ee342604432bd6ff3a6d39f2eef9de7e7258 100644
--- a/chrome/browser/android/ntp/most_visited_sites.cc
+++ b/chrome/browser/android/ntp/most_visited_sites.cc
@@ -22,12 +22,10 @@
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/variations/variations_associated_data.h"
-#include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "url/gurl.h"
-using content::BrowserThread;
using history::TopSites;
using suggestions::ChromeSuggestion;
using suggestions::SuggestionsProfile;
@@ -63,10 +61,10 @@ enum MostVisitedTileType {
NUM_TILE_TYPES,
};
+// May only be called from blocking thread pool.
std::unique_ptr<SkBitmap> MaybeFetchLocalThumbnail(
const GURL& url,
const scoped_refptr<TopSites>& top_sites) {
- DCHECK_CURRENTLY_ON(BrowserThread::DB);
scoped_refptr<base::RefCountedMemory> image;
std::unique_ptr<SkBitmap> bitmap;
if (top_sites && top_sites->GetPageThumbnail(url, false, &image))
@@ -169,6 +167,8 @@ MostVisitedSites::Suggestion&
MostVisitedSites::Suggestion::operator=(Suggestion&&) = default;
MostVisitedSites::MostVisitedSites(
+ scoped_refptr<base::SingleThreadTaskRunner> ui_thread,
+ scoped_refptr<base::SequencedWorkerPool> blocking_pool,
PrefService* prefs,
const TemplateURLService* template_url_service,
variations::VariationsService* variations_service,
@@ -192,6 +192,8 @@ MostVisitedSites::MostVisitedSites(
recorded_uma_(false),
scoped_observer_(this),
mv_source_(SUGGESTIONS_SERVICE),
+ ui_thread_(std::move(ui_thread)),
+ blocking_pool_(std::move(blocking_pool)),
weak_ptr_factory_(this) {
supervisor_->SetObserver(this);
}
@@ -209,9 +211,9 @@ void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer,
if (ShouldShowPopularSites() &&
NeedPopularSites(prefs_, num_sites_)) {
popular_sites_.reset(new PopularSites(
- prefs_, template_url_service_, variations_service_, download_context_,
- popular_sites_directory_, GetPopularSitesCountry(),
- GetPopularSitesVersion(), false,
+ ui_thread_, blocking_pool_, prefs_, template_url_service_,
+ variations_service_, download_context_, popular_sites_directory_,
+ GetPopularSitesCountry(), GetPopularSitesVersion(), false,
base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
base::Unretained(this))));
} else {
@@ -242,12 +244,14 @@ void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer,
void MostVisitedSites::GetURLThumbnail(const GURL& url,
const ThumbnailCallback& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(ui_thread_->BelongsToCurrentThread());
- // TODO(treib): Move this to the blocking pool? Doesn't seem related to DB.
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::DB, FROM_HERE,
- base::Bind(&MaybeFetchLocalThumbnail, url, top_sites_),
+ base::PostTaskAndReplyWithResult(
+ blocking_pool_
+ ->GetTaskRunnerWithShutdownBehavior(
+ base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)
+ .get(),
+ FROM_HERE, base::Bind(&MaybeFetchLocalThumbnail, url, top_sites_),
base::Bind(&MostVisitedSites::OnLocalThumbnailFetched,
weak_ptr_factory_.GetWeakPtr(), url, callback));
}
@@ -256,7 +260,7 @@ void MostVisitedSites::OnLocalThumbnailFetched(
const GURL& url,
const ThumbnailCallback& callback,
std::unique_ptr<SkBitmap> bitmap) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(ui_thread_->BelongsToCurrentThread());
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.
@@ -289,7 +293,7 @@ void MostVisitedSites::OnObtainedThumbnail(bool is_local_thumbnail,
const ThumbnailCallback& callback,
const GURL& url,
const SkBitmap* bitmap) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(ui_thread_->BelongsToCurrentThread());
callback.Run(is_local_thumbnail, bitmap);
}

Powered by Google App Engine
This is Rietveld 408576698