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

Side by Side Diff: chrome/browser/android/ntp/most_visited_sites_bridge.cc

Issue 2000653002: Replace the usage of SkBitmap with gfx::Image in the suggestion service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: accidental up load. This patchset was not committed with this CL Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/android/ntp/most_visited_sites_bridge.h ('k') | components/ntp_tiles/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/ntp/most_visited_sites_bridge.h" 5 #include "chrome/browser/android/ntp/most_visited_sites_bridge.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "chrome/browser/android/ntp/popular_sites.h" 15 #include "chrome/browser/android/ntp/popular_sites.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/history/top_sites_factory.h" 17 #include "chrome/browser/history/top_sites_factory.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_android.h" 19 #include "chrome/browser/profiles/profile_android.h"
20 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
20 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 21 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
21 #include "chrome/browser/search_engines/template_url_service_factory.h" 22 #include "chrome/browser/search_engines/template_url_service_factory.h"
22 #include "chrome/browser/supervised_user/supervised_user_service.h" 23 #include "chrome/browser/supervised_user/supervised_user_service.h"
23 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 24 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
24 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" 25 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
25 #include "chrome/browser/thumbnails/thumbnail_list_source.h" 26 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
26 #include "components/history/core/browser/top_sites.h" 27 #include "components/history/core/browser/top_sites.h"
27 #include "components/ntp_tiles/popular_sites.h" 28 #include "components/ntp_tiles/popular_sites.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/url_data_source.h" 30 #include "content/public/browser/url_data_source.h"
30 #include "jni/MostVisitedSites_jni.h" 31 #include "jni/MostVisitedSites_jni.h"
31 #include "ui/gfx/android/java_bitmap.h" 32 #include "ui/gfx/android/java_bitmap.h"
32 #include "url/gurl.h" 33 #include "url/gurl.h"
33 34
34 using base::android::AttachCurrentThread; 35 using base::android::AttachCurrentThread;
35 using base::android::ConvertJavaStringToUTF8; 36 using base::android::ConvertJavaStringToUTF8;
36 using base::android::ScopedJavaGlobalRef; 37 using base::android::ScopedJavaGlobalRef;
37 using base::android::ScopedJavaLocalRef; 38 using base::android::ScopedJavaLocalRef;
38 using base::android::ToJavaArrayOfStrings; 39 using base::android::ToJavaArrayOfStrings;
39 using content::BrowserThread; 40 using content::BrowserThread;
40 using suggestions::SuggestionsServiceFactory; 41 using suggestions::SuggestionsServiceFactory;
41 42
42 namespace {
43
44 void CallJavaWithBitmap(
45 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback,
46 bool is_local_thumbnail,
47 const SkBitmap* bitmap) {
48 JNIEnv* env = AttachCurrentThread();
49 ScopedJavaLocalRef<jobject> j_bitmap;
50 if (bitmap)
51 j_bitmap = gfx::ConvertToJavaBitmap(bitmap);
52 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable(
53 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail);
54 }
55
56 } // namespace
57
58 MostVisitedSitesBridge::SupervisorBridge::SupervisorBridge(Profile* profile) 43 MostVisitedSitesBridge::SupervisorBridge::SupervisorBridge(Profile* profile)
59 : profile_(profile), 44 : profile_(profile),
60 supervisor_observer_(nullptr), 45 supervisor_observer_(nullptr),
61 register_observer_(this) { 46 register_observer_(this) {
62 register_observer_.Add(SupervisedUserServiceFactory::GetForProfile(profile_)); 47 register_observer_.Add(SupervisedUserServiceFactory::GetForProfile(profile_));
63 } 48 }
64 49
65 MostVisitedSitesBridge::SupervisorBridge::~SupervisorBridge() {} 50 MostVisitedSitesBridge::SupervisorBridge::~SupervisorBridge() {}
66 51
67 void MostVisitedSitesBridge::SupervisorBridge::SetObserver( 52 void MostVisitedSitesBridge::SupervisorBridge::SetObserver(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile) 151 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile)
167 : supervisor_(profile), 152 : supervisor_(profile),
168 most_visited_(BrowserThread::GetBlockingPool(), 153 most_visited_(BrowserThread::GetBlockingPool(),
169 profile->GetPrefs(), 154 profile->GetPrefs(),
170 TemplateURLServiceFactory::GetForProfile(profile), 155 TemplateURLServiceFactory::GetForProfile(profile),
171 g_browser_process->variations_service(), 156 g_browser_process->variations_service(),
172 profile->GetRequestContext(), 157 profile->GetRequestContext(),
173 ChromePopularSites::GetDirectory(), 158 ChromePopularSites::GetDirectory(),
174 TopSitesFactory::GetForProfile(profile), 159 TopSitesFactory::GetForProfile(profile),
175 SuggestionsServiceFactory::GetForProfile(profile), 160 SuggestionsServiceFactory::GetForProfile(profile),
176 &supervisor_) { 161 &supervisor_,
162 new suggestions::ImageDecoderImpl()) {
177 // Register the thumbnails debugging page. 163 // Register the thumbnails debugging page.
178 // TODO(sfiera): find thumbnails a home. They don't belong here. 164 // TODO(sfiera): find thumbnails a home. They don't belong here.
179 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); 165 content::URLDataSource::Add(profile, new ThumbnailListSource(profile));
180 } 166 }
181 167
182 MostVisitedSitesBridge::~MostVisitedSitesBridge() {} 168 MostVisitedSitesBridge::~MostVisitedSitesBridge() {}
183 169
184 void MostVisitedSitesBridge::Destroy( 170 void MostVisitedSitesBridge::Destroy(
185 JNIEnv* env, const JavaParamRef<jobject>& obj) { 171 JNIEnv* env, const JavaParamRef<jobject>& obj) {
186 delete this; 172 delete this;
187 } 173 }
188 174
189 void MostVisitedSitesBridge::SetMostVisitedURLsObserver( 175 void MostVisitedSitesBridge::SetMostVisitedURLsObserver(
190 JNIEnv* env, 176 JNIEnv* env,
191 const JavaParamRef<jobject>& obj, 177 const JavaParamRef<jobject>& obj,
192 const JavaParamRef<jobject>& j_observer, 178 const JavaParamRef<jobject>& j_observer,
193 jint num_sites) { 179 jint num_sites) {
194 java_observer_.reset(new JavaObserver(env, j_observer)); 180 java_observer_.reset(new JavaObserver(env, j_observer));
195 most_visited_.SetMostVisitedURLsObserver(java_observer_.get(), num_sites); 181 most_visited_.SetMostVisitedURLsObserver(java_observer_.get(), num_sites);
196 } 182 }
197 183
198 void MostVisitedSitesBridge::GetURLThumbnail(
199 JNIEnv* env,
200 const JavaParamRef<jobject>& obj,
201 const JavaParamRef<jstring>& j_url,
202 const JavaParamRef<jobject>& j_callback_obj) {
203 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback(
204 new ScopedJavaGlobalRef<jobject>(env, j_callback_obj));
205 auto callback = base::Bind(&CallJavaWithBitmap, base::Passed(&j_callback));
206 GURL url(ConvertJavaStringToUTF8(env, j_url));
207 most_visited_.GetURLThumbnail(url, callback);
208 }
209
210 void MostVisitedSitesBridge::AddOrRemoveBlacklistedUrl( 184 void MostVisitedSitesBridge::AddOrRemoveBlacklistedUrl(
211 JNIEnv* env, 185 JNIEnv* env,
212 const JavaParamRef<jobject>& obj, 186 const JavaParamRef<jobject>& obj,
213 const JavaParamRef<jstring>& j_url, 187 const JavaParamRef<jstring>& j_url,
214 jboolean add_url) { 188 jboolean add_url) {
215 GURL url(ConvertJavaStringToUTF8(env, j_url)); 189 GURL url(ConvertJavaStringToUTF8(env, j_url));
216 most_visited_.AddOrRemoveBlacklistedUrl(url, add_url); 190 most_visited_.AddOrRemoveBlacklistedUrl(url, add_url);
217 } 191 }
218 192
219 void MostVisitedSitesBridge::RecordTileTypeMetrics( 193 void MostVisitedSitesBridge::RecordTileTypeMetrics(
(...skipping 19 matching lines...) Expand all
239 } 213 }
240 214
241 static jlong Init(JNIEnv* env, 215 static jlong Init(JNIEnv* env,
242 const JavaParamRef<jobject>& obj, 216 const JavaParamRef<jobject>& obj,
243 const JavaParamRef<jobject>& jprofile) { 217 const JavaParamRef<jobject>& jprofile) {
244 MostVisitedSitesBridge* most_visited_sites = 218 MostVisitedSitesBridge* most_visited_sites =
245 new MostVisitedSitesBridge( 219 new MostVisitedSitesBridge(
246 ProfileAndroid::FromProfileAndroid(jprofile)); 220 ProfileAndroid::FromProfileAndroid(jprofile));
247 return reinterpret_cast<intptr_t>(most_visited_sites); 221 return reinterpret_cast<intptr_t>(most_visited_sites);
248 } 222 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/most_visited_sites_bridge.h ('k') | components/ntp_tiles/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698