| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/profile_downloader_android.h" | 5 #include "chrome/browser/android/profiles/profile_downloader_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_android.h" | 10 #include "chrome/browser/profiles/profile_android.h" |
| 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 11 #include "chrome/browser/profiles/profile_downloader.h" | 12 #include "chrome/browser/profiles/profile_downloader.h" |
| 12 #include "chrome/browser/profiles/profile_downloader_delegate.h" | 13 #include "chrome/browser/profiles/profile_downloader_delegate.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "jni/ProfileDownloader_jni.h" | 15 #include "jni/ProfileDownloader_jni.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "ui/gfx/android/java_bitmap.h" | 17 #include "ui/gfx/android/java_bitmap.h" |
| 17 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
| 18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 jobject GetCachedAvatarForPrimaryAccount(JNIEnv* env, | 129 jobject GetCachedAvatarForPrimaryAccount(JNIEnv* env, |
| 129 jclass clazz, | 130 jclass clazz, |
| 130 jobject jprofile) { | 131 jobject jprofile) { |
| 131 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 132 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| 132 ProfileInfoInterface& info = | 133 ProfileInfoInterface& info = |
| 133 g_browser_process->profile_manager()->GetProfileInfoCache(); | 134 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 134 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); | 135 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); |
| 135 | 136 |
| 136 ScopedJavaLocalRef<jobject> jbitmap; | 137 ScopedJavaLocalRef<jobject> jbitmap; |
| 137 if (index != std::string::npos) { | 138 if (index != std::string::npos) { |
| 138 const gfx::Image& img = info.GetAvatarIconOfProfileAtIndex(index); | 139 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index); |
| 139 if (!img.IsEmpty() && img.AsImageSkia().bitmap()) | 140 if (!avatar_image.IsEmpty() && |
| 140 jbitmap = gfx::ConvertToJavaBitmap(img.AsImageSkia().bitmap()); | 141 avatar_image.Width() > profiles::kAvatarIconWidth && |
| 142 avatar_image.Height() > profiles::kAvatarIconHeight && |
| 143 avatar_image.AsImageSkia().bitmap()) { |
| 144 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap()); |
| 145 } |
| 141 } | 146 } |
| 142 | 147 |
| 143 return jbitmap.Release(); | 148 return jbitmap.Release(); |
| 144 } | 149 } |
| 145 | 150 |
| 146 // static | 151 // static |
| 147 void StartFetchingAccountInfoFor( | 152 void StartFetchingAccountInfoFor( |
| 148 JNIEnv* env, | 153 JNIEnv* env, |
| 149 jclass clazz, | 154 jclass clazz, |
| 150 jobject jprofile, | 155 jobject jprofile, |
| 151 jstring jaccount_id, | 156 jstring jaccount_id, |
| 152 jint image_side_pixels) { | 157 jint image_side_pixels) { |
| 153 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 158 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| 154 const std::string account_id = | 159 const std::string account_id = |
| 155 base::android::ConvertJavaStringToUTF8(env, jaccount_id); | 160 base::android::ConvertJavaStringToUTF8(env, jaccount_id); |
| 156 AccountInfoRetriever* retriever = | 161 AccountInfoRetriever* retriever = |
| 157 new AccountInfoRetriever(profile, account_id, image_side_pixels); | 162 new AccountInfoRetriever(profile, account_id, image_side_pixels); |
| 158 retriever->Start(); | 163 retriever->Start(); |
| 159 } | 164 } |
| 160 | 165 |
| 161 // static | 166 // static |
| 162 bool ProfileDownloaderAndroid::Register(JNIEnv* env) { | 167 bool ProfileDownloaderAndroid::Register(JNIEnv* env) { |
| 163 return RegisterNativesImpl(env); | 168 return RegisterNativesImpl(env); |
| 164 } | 169 } |
| OLD | NEW |