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

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

Issue 297233008: [NTP] Use server thumbnails from SuggestionsService on Android NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/most_visited_sites.cc
diff --git a/chrome/browser/android/most_visited_sites.cc b/chrome/browser/android/most_visited_sites.cc
index 6fc326f7d9426cbad6c43d979ed6810d674a4b71..a44ee116d906c3a35992c69a83fc49e2f12b9713 100644
--- a/chrome/browser/android/most_visited_sites.cc
+++ b/chrome/browser/android/most_visited_sites.cc
@@ -98,9 +98,38 @@ void AddForcedURLOnUIThread(scoped_refptr<history::TopSites> top_sites,
top_sites->AddForcedURL(url, base::Time::Now());
}
+void OnSuggestionsThumbnailAvailable(
+ ScopedJavaGlobalRef<jobject>* j_callback,
+ const GURL& url,
+ const SkBitmap* bitmap) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ JNIEnv* env = AttachCurrentThread();
+
+ ScopedJavaGlobalRef<jobject>* j_bitmap_ref =
+ new ScopedJavaGlobalRef<jobject>();
+ if (bitmap) {
+ j_bitmap_ref->Reset(
+ env,
+ gfx::ConvertToJavaBitmap(bitmap).obj());
+ }
+
+ Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable(
+ env, j_callback->obj(), j_bitmap_ref->obj());
+}
+
+void GetSuggestionsThumbnailOnUIThread(
+ const GURL& gurl,
Ted C 2014/05/28 00:21:59 +2 for the param lines
Mathieu 2014/05/28 02:48:17 Done.
+ SuggestionsService* suggestions_service,
+ ScopedJavaGlobalRef<jobject>* j_callback) {
+ suggestions_service->GetPageThumbnail(gurl,
+ base::Bind(&OnSuggestionsThumbnailAvailable,
+ base::Owned(new ScopedJavaGlobalRef<jobject>(*j_callback))));
+}
+
void GetUrlThumbnailTask(
std::string url_string,
scoped_refptr<TopSites> top_sites,
+ Profile* profile,
ScopedJavaGlobalRef<jobject>* j_callback) {
JNIEnv* env = AttachCurrentThread();
@@ -123,6 +152,17 @@ void GetUrlThumbnailTask(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(AddForcedURLOnUIThread, top_sites, gurl));
+
+ SuggestionsService* service =
+ SuggestionsServiceFactory::GetForProfile(profile);
Ted C 2014/05/28 00:21:59 BrowserContextKeyedBaseFactory is NonThreadSafe, s
Mathieu 2014/05/28 02:48:17 Ah, thanks. Passing the profile pointer instead sh
Ted C 2014/05/28 17:45:38 I don't think profile is thread safe either. And
+ if (service) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(GetSuggestionsThumbnailOnUIThread, gurl, service,
+ base::Owned(
+ new ScopedJavaGlobalRef<jobject>(*j_callback))));
+ return;
+ }
}
// Since j_callback is owned by this callback, when the callback falls out of
@@ -191,7 +231,7 @@ void MostVisitedSites::GetURLThumbnail(JNIEnv* env,
BrowserThread::DB, FROM_HERE, base::Bind(
&GetUrlThumbnailTask,
url_string,
- top_sites, base::Owned(j_callback)));
+ top_sites, profile_, base::Owned(j_callback)));
}
void MostVisitedSites::BlacklistUrl(JNIEnv* env,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698