OLD | NEW |
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/most_visited_sites.h" | 5 #include "chrome/browser/android/most_visited_sites.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 SkBitmap ExtractThumbnail(const base::RefCountedMemory& image_data) { | 96 SkBitmap ExtractThumbnail(const base::RefCountedMemory& image_data) { |
97 scoped_ptr<SkBitmap> image(gfx::JPEGCodec::Decode( | 97 scoped_ptr<SkBitmap> image(gfx::JPEGCodec::Decode( |
98 image_data.front(), | 98 image_data.front(), |
99 image_data.size())); | 99 image_data.size())); |
100 return image.get() ? *image : SkBitmap(); | 100 return image.get() ? *image : SkBitmap(); |
101 } | 101 } |
102 | 102 |
103 void AddForcedURLOnUIThread(scoped_refptr<history::TopSites> top_sites, | 103 void AddForcedURLOnUIThread(scoped_refptr<history::TopSites> top_sites, |
104 const GURL& url) { | 104 const GURL& url) { |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
106 top_sites->AddForcedURL(url, base::Time::Now()); | 106 top_sites->AddForcedURL(url, base::Time::Now()); |
107 } | 107 } |
108 | 108 |
109 // Runs on the DB thread. | 109 // Runs on the DB thread. |
110 void GetUrlThumbnailTask( | 110 void GetUrlThumbnailTask( |
111 std::string url_string, | 111 std::string url_string, |
112 scoped_refptr<TopSites> top_sites, | 112 scoped_refptr<TopSites> top_sites, |
113 ScopedJavaGlobalRef<jobject>* j_callback, | 113 ScopedJavaGlobalRef<jobject>* j_callback, |
114 MostVisitedSites::LookupSuccessCallback lookup_success_ui_callback, | 114 MostVisitedSites::LookupSuccessCallback lookup_success_ui_callback, |
115 base::Closure lookup_failed_ui_callback) { | 115 base::Closure lookup_failed_ui_callback) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // TopSites changes. | 237 // TopSites changes. |
238 scoped_observer_.Add(top_sites.get()); | 238 scoped_observer_.Add(top_sites.get()); |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 // Called from the UI Thread. | 242 // Called from the UI Thread. |
243 void MostVisitedSites::GetURLThumbnail(JNIEnv* env, | 243 void MostVisitedSites::GetURLThumbnail(JNIEnv* env, |
244 jobject obj, | 244 jobject obj, |
245 jstring url, | 245 jstring url, |
246 jobject j_callback_obj) { | 246 jobject j_callback_obj) { |
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 247 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
248 ScopedJavaGlobalRef<jobject>* j_callback = | 248 ScopedJavaGlobalRef<jobject>* j_callback = |
249 new ScopedJavaGlobalRef<jobject>(); | 249 new ScopedJavaGlobalRef<jobject>(); |
250 j_callback->Reset(env, j_callback_obj); | 250 j_callback->Reset(env, j_callback_obj); |
251 | 251 |
252 std::string url_string = ConvertJavaStringToUTF8(env, url); | 252 std::string url_string = ConvertJavaStringToUTF8(env, url); |
253 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); | 253 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); |
254 | 254 |
255 // If the Suggestions service is enabled and in use, create a callback to | 255 // If the Suggestions service is enabled and in use, create a callback to |
256 // fetch a server thumbnail from it, in case the local thumbnail is not found. | 256 // fetch a server thumbnail from it, in case the local thumbnail is not found. |
257 SuggestionsService* suggestions_service = | 257 SuggestionsService* suggestions_service = |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( | 441 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( |
442 env, | 442 env, |
443 j_observer->obj(), | 443 j_observer->obj(), |
444 ToJavaArrayOfStrings(env, titles).obj(), | 444 ToJavaArrayOfStrings(env, titles).obj(), |
445 ToJavaArrayOfStrings(env, urls).obj()); | 445 ToJavaArrayOfStrings(env, urls).obj()); |
446 } | 446 } |
447 | 447 |
448 void MostVisitedSites::OnObtainedThumbnail( | 448 void MostVisitedSites::OnObtainedThumbnail( |
449 ScopedJavaGlobalRef<jobject>* bitmap, | 449 ScopedJavaGlobalRef<jobject>* bitmap, |
450 ScopedJavaGlobalRef<jobject>* j_callback) { | 450 ScopedJavaGlobalRef<jobject>* j_callback) { |
451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 451 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
452 JNIEnv* env = AttachCurrentThread(); | 452 JNIEnv* env = AttachCurrentThread(); |
453 if (bitmap->obj()) { | 453 if (bitmap->obj()) { |
454 num_local_thumbs_++; | 454 num_local_thumbs_++; |
455 } else { | 455 } else { |
456 num_empty_thumbs_++; | 456 num_empty_thumbs_++; |
457 } | 457 } |
458 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( | 458 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( |
459 env, j_callback->obj(), bitmap->obj()); | 459 env, j_callback->obj(), bitmap->obj()); |
460 } | 460 } |
461 | 461 |
462 void MostVisitedSites::GetSuggestionsThumbnailOnUIThread( | 462 void MostVisitedSites::GetSuggestionsThumbnailOnUIThread( |
463 SuggestionsService* suggestions_service, | 463 SuggestionsService* suggestions_service, |
464 const std::string& url_string, | 464 const std::string& url_string, |
465 ScopedJavaGlobalRef<jobject>* j_callback) { | 465 ScopedJavaGlobalRef<jobject>* j_callback) { |
466 suggestions_service->GetPageThumbnail( | 466 suggestions_service->GetPageThumbnail( |
467 GURL(url_string), | 467 GURL(url_string), |
468 base::Bind(&MostVisitedSites::OnSuggestionsThumbnailAvailable, | 468 base::Bind(&MostVisitedSites::OnSuggestionsThumbnailAvailable, |
469 weak_ptr_factory_.GetWeakPtr(), | 469 weak_ptr_factory_.GetWeakPtr(), |
470 base::Owned(new ScopedJavaGlobalRef<jobject>(*j_callback)))); | 470 base::Owned(new ScopedJavaGlobalRef<jobject>(*j_callback)))); |
471 } | 471 } |
472 | 472 |
473 void MostVisitedSites::OnSuggestionsThumbnailAvailable( | 473 void MostVisitedSites::OnSuggestionsThumbnailAvailable( |
474 ScopedJavaGlobalRef<jobject>* j_callback, | 474 ScopedJavaGlobalRef<jobject>* j_callback, |
475 const GURL& url, | 475 const GURL& url, |
476 const SkBitmap* bitmap) { | 476 const SkBitmap* bitmap) { |
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 477 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
478 JNIEnv* env = AttachCurrentThread(); | 478 JNIEnv* env = AttachCurrentThread(); |
479 | 479 |
480 ScopedJavaGlobalRef<jobject>* j_bitmap_ref = | 480 ScopedJavaGlobalRef<jobject>* j_bitmap_ref = |
481 new ScopedJavaGlobalRef<jobject>(); | 481 new ScopedJavaGlobalRef<jobject>(); |
482 if (bitmap) { | 482 if (bitmap) { |
483 num_server_thumbs_++; | 483 num_server_thumbs_++; |
484 j_bitmap_ref->Reset( | 484 j_bitmap_ref->Reset( |
485 env, | 485 env, |
486 gfx::ConvertToJavaBitmap(bitmap).obj()); | 486 gfx::ConvertToJavaBitmap(bitmap).obj()); |
487 } else { | 487 } else { |
(...skipping 22 matching lines...) Expand all Loading... |
510 // The displayed suggestions are invalidated. | 510 // The displayed suggestions are invalidated. |
511 QueryMostVisitedURLs(); | 511 QueryMostVisitedURLs(); |
512 } | 512 } |
513 } | 513 } |
514 | 514 |
515 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { | 515 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { |
516 MostVisitedSites* most_visited_sites = | 516 MostVisitedSites* most_visited_sites = |
517 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 517 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
518 return reinterpret_cast<intptr_t>(most_visited_sites); | 518 return reinterpret_cast<intptr_t>(most_visited_sites); |
519 } | 519 } |
OLD | NEW |