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

Side by Side Diff: chrome/browser/android/profiles/profile_downloader_android.cc

Issue 1288183004: jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some newlines for readability Created 5 years, 4 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
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // such as during first run when we can still get tokens and want to fetch 113 // such as during first run when we can still get tokens and want to fetch
114 // the profile name and picture to display. 114 // the profile name and picture to display.
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 jstring GetCachedFullNameForPrimaryAccount(JNIEnv* env, 123 ScopedJavaLocalRef<jstring> GetCachedFullNameForPrimaryAccount(
124 jclass clazz, 124 JNIEnv* env,
125 jobject jprofile) { 125 jclass clazz,
126 jobject jprofile) {
126 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 127 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
127 ProfileInfoInterface& info = 128 ProfileInfoInterface& info =
128 g_browser_process->profile_manager()->GetProfileInfoCache(); 129 g_browser_process->profile_manager()->GetProfileInfoCache();
129 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); 130 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
130 131
131 base::string16 name; 132 base::string16 name;
132 if (index != std::string::npos) 133 if (index != std::string::npos)
133 name = info.GetGAIANameOfProfileAtIndex(index); 134 name = info.GetGAIANameOfProfileAtIndex(index);
134 135
135 return base::android::ConvertUTF16ToJavaString(env, name).Release(); 136 return base::android::ConvertUTF16ToJavaString(env, name);
136 } 137 }
137 138
138 // static 139 // static
139 jstring GetCachedGivenNameForPrimaryAccount(JNIEnv* env, 140 ScopedJavaLocalRef<jstring> GetCachedGivenNameForPrimaryAccount(
140 jclass clazz, 141 JNIEnv* env,
141 jobject jprofile) { 142 jclass clazz,
143 jobject jprofile) {
142 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 144 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
143 ProfileInfoInterface& info = 145 ProfileInfoInterface& info =
144 g_browser_process->profile_manager()->GetProfileInfoCache(); 146 g_browser_process->profile_manager()->GetProfileInfoCache();
145 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); 147 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
146 148
147 base::string16 name; 149 base::string16 name;
148 if (index != std::string::npos) 150 if (index != std::string::npos)
149 name = info.GetGAIAGivenNameOfProfileAtIndex(index); 151 name = info.GetGAIAGivenNameOfProfileAtIndex(index);
150 152
151 return base::android::ConvertUTF16ToJavaString(env, name).Release(); 153 return base::android::ConvertUTF16ToJavaString(env, name);
152 } 154 }
153 155
154 // static 156 // static
155 jobject GetCachedAvatarForPrimaryAccount(JNIEnv* env, 157 ScopedJavaLocalRef<jobject> GetCachedAvatarForPrimaryAccount(JNIEnv* env,
156 jclass clazz, 158 jclass clazz,
157 jobject jprofile) { 159 jobject jprofile) {
158 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 160 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
159 ProfileInfoInterface& info = 161 ProfileInfoInterface& info =
160 g_browser_process->profile_manager()->GetProfileInfoCache(); 162 g_browser_process->profile_manager()->GetProfileInfoCache();
161 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); 163 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
162 164
163 ScopedJavaLocalRef<jobject> jbitmap; 165 ScopedJavaLocalRef<jobject> jbitmap;
164 if (index != std::string::npos) { 166 if (index != std::string::npos) {
165 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index); 167 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index);
166 if (!avatar_image.IsEmpty() && 168 if (!avatar_image.IsEmpty() &&
167 avatar_image.Width() > profiles::kAvatarIconWidth && 169 avatar_image.Width() > profiles::kAvatarIconWidth &&
168 avatar_image.Height() > profiles::kAvatarIconHeight && 170 avatar_image.Height() > profiles::kAvatarIconHeight &&
169 avatar_image.AsImageSkia().bitmap()) { 171 avatar_image.AsImageSkia().bitmap()) {
170 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap()); 172 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap());
171 } 173 }
172 } 174 }
173 175
174 return jbitmap.Release(); 176 return jbitmap;
175 } 177 }
176 178
177 // static 179 // static
178 void StartFetchingAccountInfoFor( 180 void StartFetchingAccountInfoFor(
179 JNIEnv* env, 181 JNIEnv* env,
180 jclass clazz, 182 jclass clazz,
181 jobject jprofile, 183 jobject jprofile,
182 jstring jemail, 184 jstring jemail,
183 jint image_side_pixels, 185 jint image_side_pixels,
184 jboolean is_pre_signin) { 186 jboolean is_pre_signin) {
185 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 187 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
186 const std::string email = 188 const std::string email =
187 base::android::ConvertJavaStringToUTF8(env, jemail); 189 base::android::ConvertJavaStringToUTF8(env, jemail);
188 // 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
189 // 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.
190 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, 192 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED,
191 AccountTrackerServiceFactory::GetForProfile(profile)-> 193 AccountTrackerServiceFactory::GetForProfile(profile)->
192 GetMigrationState()); 194 GetMigrationState());
193 AccountInfoRetriever* retriever = 195 AccountInfoRetriever* retriever =
194 new AccountInfoRetriever( 196 new AccountInfoRetriever(
195 profile, gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)), email, 197 profile, gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)), email,
196 image_side_pixels, is_pre_signin); 198 image_side_pixels, is_pre_signin);
197 retriever->Start(); 199 retriever->Start();
198 } 200 }
199 201
200 // static 202 // static
201 bool RegisterProfileDownloader(JNIEnv* env) { 203 bool RegisterProfileDownloader(JNIEnv* env) {
202 return RegisterNativesImpl(env); 204 return RegisterNativesImpl(env);
203 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698