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

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..aea530b842f31f1642b959f7a7dda7835da59ca7 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 DB thread.
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,9 @@ MostVisitedSites::Suggestion&
MostVisitedSites::Suggestion::operator=(Suggestion&&) = default;
MostVisitedSites::MostVisitedSites(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
+ const scoped_refptr<base::TaskRunner>& blocking_runner,
PrefService* prefs,
const TemplateURLService* template_url_service,
variations::VariationsService* variations_service,
@@ -192,6 +193,9 @@ MostVisitedSites::MostVisitedSites(
recorded_uma_(false),
scoped_observer_(this),
mv_source_(SUGGESTIONS_SERVICE),
+ ui_thread_(ui_thread),
+ db_thread_(db_thread),
+ blocking_runner_(blocking_runner),
weak_ptr_factory_(this) {
supervisor_->SetObserver(this);
}
@@ -209,9 +213,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_runner_, prefs_, template_url_service_,
+ variations_service_, download_context_, popular_sites_directory_,
+ GetPopularSitesCountry(), GetPopularSitesVersion(), false,
base::Bind(&MostVisitedSites::OnPopularSitesAvailable,
base::Unretained(this))));
} else {
@@ -242,11 +246,11 @@ 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.
Marc Treib 2016/05/24 15:16:11 Hm, maybe now is the time to resolve this TODO, so
sfiera 2016/05/24 16:59:20 Done.
- BrowserThread::PostTaskAndReplyWithResult(
- BrowserThread::DB, FROM_HERE,
+ base::PostTaskAndReplyWithResult(
+ db_thread_.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