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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 bool is_pre_signin_; | 115 bool is_pre_signin_; |
116 | 116 |
117 DISALLOW_COPY_AND_ASSIGN(AccountInfoRetriever); | 117 DISALLOW_COPY_AND_ASSIGN(AccountInfoRetriever); |
118 }; | 118 }; |
119 | 119 |
120 } // namespace | 120 } // namespace |
121 | 121 |
122 // static | 122 // static |
123 ScopedJavaLocalRef<jstring> GetCachedFullNameForPrimaryAccount( | 123 ScopedJavaLocalRef<jstring> GetCachedFullNameForPrimaryAccount( |
124 JNIEnv* env, | 124 JNIEnv* env, |
125 jclass clazz, | 125 const JavaParamRef<jclass>& clazz, |
126 jobject jprofile) { | 126 const JavaParamRef<jobject>& jprofile) { |
127 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 127 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
128 ProfileInfoInterface& info = | 128 ProfileInfoInterface& info = |
129 g_browser_process->profile_manager()->GetProfileInfoCache(); | 129 g_browser_process->profile_manager()->GetProfileInfoCache(); |
130 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); | 130 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); |
131 | 131 |
132 base::string16 name; | 132 base::string16 name; |
133 if (index != std::string::npos) | 133 if (index != std::string::npos) |
134 name = info.GetGAIANameOfProfileAtIndex(index); | 134 name = info.GetGAIANameOfProfileAtIndex(index); |
135 | 135 |
136 return base::android::ConvertUTF16ToJavaString(env, name); | 136 return base::android::ConvertUTF16ToJavaString(env, name); |
137 } | 137 } |
138 | 138 |
139 // static | 139 // static |
140 ScopedJavaLocalRef<jstring> GetCachedGivenNameForPrimaryAccount( | 140 ScopedJavaLocalRef<jstring> GetCachedGivenNameForPrimaryAccount( |
141 JNIEnv* env, | 141 JNIEnv* env, |
142 jclass clazz, | 142 const JavaParamRef<jclass>& clazz, |
143 jobject jprofile) { | 143 const JavaParamRef<jobject>& jprofile) { |
144 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 144 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
145 ProfileInfoInterface& info = | 145 ProfileInfoInterface& info = |
146 g_browser_process->profile_manager()->GetProfileInfoCache(); | 146 g_browser_process->profile_manager()->GetProfileInfoCache(); |
147 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); | 147 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); |
148 | 148 |
149 base::string16 name; | 149 base::string16 name; |
150 if (index != std::string::npos) | 150 if (index != std::string::npos) |
151 name = info.GetGAIAGivenNameOfProfileAtIndex(index); | 151 name = info.GetGAIAGivenNameOfProfileAtIndex(index); |
152 | 152 |
153 return base::android::ConvertUTF16ToJavaString(env, name); | 153 return base::android::ConvertUTF16ToJavaString(env, name); |
154 } | 154 } |
155 | 155 |
156 // static | 156 // static |
157 ScopedJavaLocalRef<jobject> GetCachedAvatarForPrimaryAccount(JNIEnv* env, | 157 ScopedJavaLocalRef<jobject> GetCachedAvatarForPrimaryAccount( |
158 jclass clazz, | 158 JNIEnv* env, |
159 jobject jprofile) { | 159 const JavaParamRef<jclass>& clazz, |
| 160 const JavaParamRef<jobject>& jprofile) { |
160 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 161 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
161 ProfileInfoInterface& info = | 162 ProfileInfoInterface& info = |
162 g_browser_process->profile_manager()->GetProfileInfoCache(); | 163 g_browser_process->profile_manager()->GetProfileInfoCache(); |
163 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); | 164 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); |
164 | 165 |
165 ScopedJavaLocalRef<jobject> jbitmap; | 166 ScopedJavaLocalRef<jobject> jbitmap; |
166 if (index != std::string::npos) { | 167 if (index != std::string::npos) { |
167 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index); | 168 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index); |
168 if (!avatar_image.IsEmpty() && | 169 if (!avatar_image.IsEmpty() && |
169 avatar_image.Width() > profiles::kAvatarIconWidth && | 170 avatar_image.Width() > profiles::kAvatarIconWidth && |
170 avatar_image.Height() > profiles::kAvatarIconHeight && | 171 avatar_image.Height() > profiles::kAvatarIconHeight && |
171 avatar_image.AsImageSkia().bitmap()) { | 172 avatar_image.AsImageSkia().bitmap()) { |
172 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap()); | 173 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap()); |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
176 return jbitmap; | 177 return jbitmap; |
177 } | 178 } |
178 | 179 |
179 // static | 180 // static |
180 void StartFetchingAccountInfoFor( | 181 void StartFetchingAccountInfoFor(JNIEnv* env, |
181 JNIEnv* env, | 182 const JavaParamRef<jclass>& clazz, |
182 jclass clazz, | 183 const JavaParamRef<jobject>& jprofile, |
183 jobject jprofile, | 184 const JavaParamRef<jstring>& jemail, |
184 jstring jemail, | 185 jint image_side_pixels, |
185 jint image_side_pixels, | 186 jboolean is_pre_signin) { |
186 jboolean is_pre_signin) { | |
187 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 187 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
188 const std::string email = | 188 const std::string email = |
189 base::android::ConvertJavaStringToUTF8(env, jemail); | 189 base::android::ConvertJavaStringToUTF8(env, jemail); |
190 // TODO(rogerta): the java code will need to pass in the gaia-id | 190 // TODO(rogerta): the java code will need to pass in the gaia-id |
191 // of the account instead of the email when chrome uses gaia-id as key. | 191 // of the account instead of the email when chrome uses gaia-id as key. |
192 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, | 192 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, |
193 AccountTrackerServiceFactory::GetForProfile(profile)-> | 193 AccountTrackerServiceFactory::GetForProfile(profile)-> |
194 GetMigrationState()); | 194 GetMigrationState()); |
195 AccountInfoRetriever* retriever = | 195 AccountInfoRetriever* retriever = |
196 new AccountInfoRetriever( | 196 new AccountInfoRetriever( |
197 profile, gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)), email, | 197 profile, gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)), email, |
198 image_side_pixels, is_pre_signin); | 198 image_side_pixels, is_pre_signin); |
199 retriever->Start(); | 199 retriever->Start(); |
200 } | 200 } |
201 | 201 |
202 // static | 202 // static |
203 bool RegisterProfileDownloader(JNIEnv* env) { | 203 bool RegisterProfileDownloader(JNIEnv* env) { |
204 return RegisterNativesImpl(env); | 204 return RegisterNativesImpl(env); |
205 } | 205 } |
OLD | NEW |