| 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/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 "base/path_service.h" |
| 15 #include "chrome/browser/android/ntp/popular_sites.h" | 16 #include "chrome/browser/android/ntp/popular_sites.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/history/top_sites_factory.h" | 18 #include "chrome/browser/history/top_sites_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_android.h" | 20 #include "chrome/browser/profiles/profile_android.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/thumbnails/thumbnail_list_source.h" | 23 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
| 24 #include "chrome/common/chrome_paths.h" |
| 23 #include "components/history/core/browser/top_sites.h" | 25 #include "components/history/core/browser/top_sites.h" |
| 24 #include "content/public/browser/url_data_source.h" | 26 #include "content/public/browser/url_data_source.h" |
| 25 #include "jni/MostVisitedSites_jni.h" | 27 #include "jni/MostVisitedSites_jni.h" |
| 26 #include "ui/gfx/android/java_bitmap.h" | 28 #include "ui/gfx/android/java_bitmap.h" |
| 27 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 28 | 30 |
| 29 using base::android::AttachCurrentThread; | 31 using base::android::AttachCurrentThread; |
| 30 using base::android::ConvertJavaStringToUTF8; | 32 using base::android::ConvertJavaStringToUTF8; |
| 31 using base::android::ScopedJavaGlobalRef; | 33 using base::android::ScopedJavaGlobalRef; |
| 32 using base::android::ScopedJavaLocalRef; | 34 using base::android::ScopedJavaLocalRef; |
| 33 using base::android::ToJavaArrayOfStrings; | 35 using base::android::ToJavaArrayOfStrings; |
| 34 using suggestions::SuggestionsServiceFactory; | 36 using suggestions::SuggestionsServiceFactory; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 void CallJavaWithBitmap( | 40 void CallJavaWithBitmap( |
| 39 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback, | 41 std::unique_ptr<ScopedJavaGlobalRef<jobject>> j_callback, |
| 40 bool is_local_thumbnail, | 42 bool is_local_thumbnail, |
| 41 const SkBitmap* bitmap) { | 43 const SkBitmap* bitmap) { |
| 42 JNIEnv* env = AttachCurrentThread(); | 44 JNIEnv* env = AttachCurrentThread(); |
| 43 ScopedJavaLocalRef<jobject> j_bitmap; | 45 ScopedJavaLocalRef<jobject> j_bitmap; |
| 44 if (bitmap) | 46 if (bitmap) |
| 45 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); | 47 j_bitmap = gfx::ConvertToJavaBitmap(bitmap); |
| 46 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( | 48 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( |
| 47 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail); | 49 env, j_callback->obj(), j_bitmap.obj(), is_local_thumbnail); |
| 48 } | 50 } |
| 49 | 51 |
| 52 base::FilePath GetPopularSitesDirectory() { |
| 53 base::FilePath dir; |
| 54 PathService::Get(chrome::DIR_USER_DATA, &dir); |
| 55 return dir; // empty if PathService::Get() failed. |
| 56 } |
| 57 |
| 50 } // namespace | 58 } // namespace |
| 51 | 59 |
| 52 class MostVisitedSitesBridge::Observer | 60 class MostVisitedSitesBridge::Observer |
| 53 : public MostVisitedSites::Observer { | 61 : public MostVisitedSites::Observer { |
| 54 public: | 62 public: |
| 55 Observer(JNIEnv* env, const JavaParamRef<jobject>& obj); | 63 Observer(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 56 | 64 |
| 57 void OnMostVisitedURLsAvailable( | 65 void OnMostVisitedURLsAvailable( |
| 58 const MostVisitedSites::SuggestionsVector& suggestions) override; | 66 const MostVisitedSites::SuggestionsVector& suggestions) override; |
| 59 | 67 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(), | 113 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(), |
| 106 ToJavaArrayOfStrings(env, favicon_urls).obj(), | 114 ToJavaArrayOfStrings(env, favicon_urls).obj(), |
| 107 ToJavaArrayOfStrings(env, large_icon_urls).obj()); | 115 ToJavaArrayOfStrings(env, large_icon_urls).obj()); |
| 108 } | 116 } |
| 109 | 117 |
| 110 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile) | 118 MostVisitedSitesBridge::MostVisitedSitesBridge(Profile* profile) |
| 111 : most_visited_(profile->GetPrefs(), | 119 : most_visited_(profile->GetPrefs(), |
| 112 TemplateURLServiceFactory::GetForProfile(profile), | 120 TemplateURLServiceFactory::GetForProfile(profile), |
| 113 g_browser_process->variations_service(), | 121 g_browser_process->variations_service(), |
| 114 profile->GetRequestContext(), | 122 profile->GetRequestContext(), |
| 123 GetPopularSitesDirectory(), |
| 115 TopSitesFactory::GetForProfile(profile), | 124 TopSitesFactory::GetForProfile(profile), |
| 116 SuggestionsServiceFactory::GetForProfile(profile), | 125 SuggestionsServiceFactory::GetForProfile(profile), |
| 117 profile->IsChild(), | 126 profile->IsChild(), |
| 118 profile) { | 127 profile) { |
| 119 // Register the thumbnails debugging page. | 128 // Register the thumbnails debugging page. |
| 120 // TODO(sfiera): find thumbnails a home. They don't belong here. | 129 // TODO(sfiera): find thumbnails a home. They don't belong here. |
| 121 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); | 130 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); |
| 122 } | 131 } |
| 123 | 132 |
| 124 MostVisitedSitesBridge::~MostVisitedSitesBridge() {} | 133 MostVisitedSitesBridge::~MostVisitedSitesBridge() {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 190 } |
| 182 | 191 |
| 183 static jlong Init(JNIEnv* env, | 192 static jlong Init(JNIEnv* env, |
| 184 const JavaParamRef<jobject>& obj, | 193 const JavaParamRef<jobject>& obj, |
| 185 const JavaParamRef<jobject>& jprofile) { | 194 const JavaParamRef<jobject>& jprofile) { |
| 186 MostVisitedSitesBridge* most_visited_sites = | 195 MostVisitedSitesBridge* most_visited_sites = |
| 187 new MostVisitedSitesBridge( | 196 new MostVisitedSitesBridge( |
| 188 ProfileAndroid::FromProfileAndroid(jprofile)); | 197 ProfileAndroid::FromProfileAndroid(jprofile)); |
| 189 return reinterpret_cast<intptr_t>(most_visited_sites); | 198 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 190 } | 199 } |
| OLD | NEW |