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

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

Issue 1308363003: Revert of jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 ScopedJavaLocalRef<jstring> GetCachedFullNameForPrimaryAccount( 123 jstring GetCachedFullNameForPrimaryAccount(JNIEnv* env,
124 JNIEnv* env, 124 jclass clazz,
125 jclass clazz, 125 jobject jprofile) {
126 jobject jprofile) {
127 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 126 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
128 ProfileInfoInterface& info = 127 ProfileInfoInterface& info =
129 g_browser_process->profile_manager()->GetProfileInfoCache(); 128 g_browser_process->profile_manager()->GetProfileInfoCache();
130 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); 129 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
131 130
132 base::string16 name; 131 base::string16 name;
133 if (index != std::string::npos) 132 if (index != std::string::npos)
134 name = info.GetGAIANameOfProfileAtIndex(index); 133 name = info.GetGAIANameOfProfileAtIndex(index);
135 134
136 return base::android::ConvertUTF16ToJavaString(env, name); 135 return base::android::ConvertUTF16ToJavaString(env, name).Release();
137 } 136 }
138 137
139 // static 138 // static
140 ScopedJavaLocalRef<jstring> GetCachedGivenNameForPrimaryAccount( 139 jstring GetCachedGivenNameForPrimaryAccount(JNIEnv* env,
141 JNIEnv* env, 140 jclass clazz,
142 jclass clazz, 141 jobject jprofile) {
143 jobject jprofile) {
144 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 142 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
145 ProfileInfoInterface& info = 143 ProfileInfoInterface& info =
146 g_browser_process->profile_manager()->GetProfileInfoCache(); 144 g_browser_process->profile_manager()->GetProfileInfoCache();
147 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); 145 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
148 146
149 base::string16 name; 147 base::string16 name;
150 if (index != std::string::npos) 148 if (index != std::string::npos)
151 name = info.GetGAIAGivenNameOfProfileAtIndex(index); 149 name = info.GetGAIAGivenNameOfProfileAtIndex(index);
152 150
153 return base::android::ConvertUTF16ToJavaString(env, name); 151 return base::android::ConvertUTF16ToJavaString(env, name).Release();
154 } 152 }
155 153
156 // static 154 // static
157 ScopedJavaLocalRef<jobject> GetCachedAvatarForPrimaryAccount(JNIEnv* env, 155 jobject GetCachedAvatarForPrimaryAccount(JNIEnv* env,
158 jclass clazz, 156 jclass clazz,
159 jobject jprofile) { 157 jobject jprofile) {
160 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 158 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
161 ProfileInfoInterface& info = 159 ProfileInfoInterface& info =
162 g_browser_process->profile_manager()->GetProfileInfoCache(); 160 g_browser_process->profile_manager()->GetProfileInfoCache();
163 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath()); 161 const size_t index = info.GetIndexOfProfileWithPath(profile->GetPath());
164 162
165 ScopedJavaLocalRef<jobject> jbitmap; 163 ScopedJavaLocalRef<jobject> jbitmap;
166 if (index != std::string::npos) { 164 if (index != std::string::npos) {
167 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index); 165 gfx::Image avatar_image = info.GetAvatarIconOfProfileAtIndex(index);
168 if (!avatar_image.IsEmpty() && 166 if (!avatar_image.IsEmpty() &&
169 avatar_image.Width() > profiles::kAvatarIconWidth && 167 avatar_image.Width() > profiles::kAvatarIconWidth &&
170 avatar_image.Height() > profiles::kAvatarIconHeight && 168 avatar_image.Height() > profiles::kAvatarIconHeight &&
171 avatar_image.AsImageSkia().bitmap()) { 169 avatar_image.AsImageSkia().bitmap()) {
172 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap()); 170 jbitmap = gfx::ConvertToJavaBitmap(avatar_image.AsImageSkia().bitmap());
173 } 171 }
174 } 172 }
175 173
176 return jbitmap; 174 return jbitmap.Release();
177 } 175 }
178 176
179 // static 177 // static
180 void StartFetchingAccountInfoFor( 178 void StartFetchingAccountInfoFor(
181 JNIEnv* env, 179 JNIEnv* env,
182 jclass clazz, 180 jclass clazz,
183 jobject jprofile, 181 jobject jprofile,
184 jstring jemail, 182 jstring jemail,
185 jint image_side_pixels, 183 jint image_side_pixels,
186 jboolean is_pre_signin) { 184 jboolean is_pre_signin) {
187 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 185 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
188 const std::string email = 186 const std::string email =
189 base::android::ConvertJavaStringToUTF8(env, jemail); 187 base::android::ConvertJavaStringToUTF8(env, jemail);
190 // TODO(rogerta): the java code will need to pass in the gaia-id 188 // 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. 189 // of the account instead of the email when chrome uses gaia-id as key.
192 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, 190 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED,
193 AccountTrackerServiceFactory::GetForProfile(profile)-> 191 AccountTrackerServiceFactory::GetForProfile(profile)->
194 GetMigrationState()); 192 GetMigrationState());
195 AccountInfoRetriever* retriever = 193 AccountInfoRetriever* retriever =
196 new AccountInfoRetriever( 194 new AccountInfoRetriever(
197 profile, gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)), email, 195 profile, gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)), email,
198 image_side_pixels, is_pre_signin); 196 image_side_pixels, is_pre_signin);
199 retriever->Start(); 197 retriever->Start();
200 } 198 }
201 199
202 // static 200 // static
203 bool RegisterProfileDownloader(JNIEnv* env) { 201 bool RegisterProfileDownloader(JNIEnv* env) {
204 return RegisterNativesImpl(env); 202 return RegisterNativesImpl(env);
205 } 203 }
OLDNEW
« no previous file with comments | « chrome/browser/android/preferences/pref_service_bridge.cc ('k') | chrome/browser/android/tab_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698