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

Side by Side Diff: chrome/browser/signin/oauth2_token_service_delegate_android.cc

Issue 1256283002: GAIA ID migration for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simple version 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 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/signin/oauth2_token_service_delegate_android.h" 5 #include "chrome/browser/signin/oauth2_token_service_delegate_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 scope += " "; 124 scope += " ";
125 scope += *it; 125 scope += *it;
126 } 126 }
127 return scope; 127 return scope;
128 } 128 }
129 129
130 } // namespace 130 } // namespace
131 131
132 bool OAuth2TokenServiceDelegateAndroid::is_testing_profile_ = false; 132 bool OAuth2TokenServiceDelegateAndroid::is_testing_profile_ = false;
133 133
134 OAuth2TokenServiceDelegateAndroid::OAuth2TokenServiceDelegateAndroid() { 134 OAuth2TokenServiceDelegateAndroid::OAuth2TokenServiceDelegateAndroid()
135 : account_tracker_service_(nullptr) {
135 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ctor"; 136 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ctor";
136 JNIEnv* env = AttachCurrentThread(); 137 JNIEnv* env = AttachCurrentThread();
137 base::android::ScopedJavaLocalRef<jobject> local_java_ref = 138 base::android::ScopedJavaLocalRef<jobject> local_java_ref =
138 Java_OAuth2TokenService_create(env, reinterpret_cast<intptr_t>(this)); 139 Java_OAuth2TokenService_create(env, reinterpret_cast<intptr_t>(this));
139 java_ref_.Reset(env, local_java_ref.obj()); 140 java_ref_.Reset(env, local_java_ref.obj());
140 } 141 }
141 142
142 OAuth2TokenServiceDelegateAndroid::~OAuth2TokenServiceDelegateAndroid() { 143 OAuth2TokenServiceDelegateAndroid::~OAuth2TokenServiceDelegateAndroid() {
143 } 144 }
144 145
(...skipping 10 matching lines...) Expand all
155 ->java_ref_.obj(); 156 ->java_ref_.obj();
156 } 157 }
157 158
158 static jobject GetForProfile(JNIEnv* env, 159 static jobject GetForProfile(JNIEnv* env,
159 jclass clazz, 160 jclass clazz,
160 jobject j_profile_android) { 161 jobject j_profile_android) {
161 return OAuth2TokenServiceDelegateAndroid::GetForProfile(env, clazz, 162 return OAuth2TokenServiceDelegateAndroid::GetForProfile(env, clazz,
162 j_profile_android); 163 j_profile_android);
163 } 164 }
164 165
165 void OAuth2TokenServiceDelegateAndroid::Initialize() { 166 void OAuth2TokenServiceDelegateAndroid::Initialize(
167 AccountTrackerService* account_tracker_service) {
166 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::Initialize"; 168 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::Initialize";
169 account_tracker_service_ = account_tracker_service;
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 DCHECK(account_tracker_service); ?
gogerald1 2015/08/13 18:12:12 Done.
167 if (!is_testing_profile_) { 170 if (!is_testing_profile_) {
168 Java_OAuth2TokenService_validateAccounts( 171 Java_OAuth2TokenService_validateAccounts(
169 AttachCurrentThread(), java_ref_.obj(), 172 AttachCurrentThread(), java_ref_.obj(),
170 base::android::GetApplicationContext(), JNI_TRUE); 173 base::android::GetApplicationContext(), JNI_TRUE);
171 } 174 }
175 if (account_tracker_service_->GetMigrationState() !=
176 AccountTrackerService::MIGRATION_NOT_STARTED) {
177 account_tracker_service_->SetMigrationDone();
178 }
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 Is it correct to mark migration done here? Since
gogerald1 2015/08/13 18:12:12 Done.
172 } 179 }
173 180
174 bool OAuth2TokenServiceDelegateAndroid::RefreshTokenIsAvailable( 181 bool OAuth2TokenServiceDelegateAndroid::RefreshTokenIsAvailable(
175 const std::string& account_id) const { 182 const std::string& account_id) const {
183 std::string accountid = MapUserAccountIdToOs(account_id);
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 local_account_id ? Same below.
gogerald1 2015/08/13 18:12:12 Done.
184 if (accountid.empty())
185 accountid = account_id;
176 JNIEnv* env = AttachCurrentThread(); 186 JNIEnv* env = AttachCurrentThread();
177 ScopedJavaLocalRef<jstring> j_account_id = 187 ScopedJavaLocalRef<jstring> j_account_id =
178 ConvertUTF8ToJavaString(env, account_id); 188 ConvertUTF8ToJavaString(env, accountid);
179 jboolean refresh_token_is_available = 189 jboolean refresh_token_is_available =
180 Java_OAuth2TokenService_hasOAuth2RefreshToken( 190 Java_OAuth2TokenService_hasOAuth2RefreshToken(
181 env, base::android::GetApplicationContext(), j_account_id.obj()); 191 env, base::android::GetApplicationContext(), j_account_id.obj());
182 return refresh_token_is_available == JNI_TRUE; 192 return refresh_token_is_available == JNI_TRUE;
183 } 193 }
184 194
185 void OAuth2TokenServiceDelegateAndroid::UpdateAuthError( 195 void OAuth2TokenServiceDelegateAndroid::UpdateAuthError(
186 const std::string& account_id, 196 const std::string& account_id,
187 const GoogleServiceAuthError& error) { 197 const GoogleServiceAuthError& error) {
188 // TODO(rogerta): do we need to update anything, or does the system handle it? 198 // TODO(rogerta): do we need to update anything, or does the system handle it?
189 } 199 }
190 200
191 std::vector<std::string> OAuth2TokenServiceDelegateAndroid::GetAccounts() { 201 std::vector<std::string>
202 OAuth2TokenServiceDelegateAndroid::GetPersistentAccounts() {
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 Today accounts are persisted as usernames. During
gogerald1 2015/08/13 18:12:12 Done.
192 std::vector<std::string> accounts; 203 std::vector<std::string> accounts;
193 JNIEnv* env = AttachCurrentThread(); 204 JNIEnv* env = AttachCurrentThread();
194 ScopedJavaLocalRef<jobjectArray> j_accounts = 205 ScopedJavaLocalRef<jobjectArray> j_accounts =
195 Java_OAuth2TokenService_getAccounts( 206 Java_OAuth2TokenService_getAccounts(
196 env, base::android::GetApplicationContext()); 207 env, base::android::GetApplicationContext());
197 // TODO(fgorski): We may decide to filter out some of the accounts. 208 // TODO(fgorski): We may decide to filter out some of the accounts.
198 base::android::AppendJavaStringArrayToStringVector(env, j_accounts.obj(), 209 base::android::AppendJavaStringArrayToStringVector(env, j_accounts.obj(),
199 &accounts); 210 &accounts);
200 return accounts; 211 return accounts;
201 } 212 }
202 213
214 std::vector<std::string> OAuth2TokenServiceDelegateAndroid::GetAccounts() {
215 std::vector<std::string> accounts_name = GetPersistentAccounts();
216 std::vector<std::string> accounts_id;
217 for (std::vector<std::string>::iterator it = accounts_name.begin();
218 it != accounts_name.end(); ++it) {
219 std::string account_id = MapOsAccountIdToUser(*it);
220 if (!account_id.empty())
221 accounts_id.push_back(account_id);
222 }
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 When does this mapping need to be done here? Befo
gogerald1 2015/08/13 18:12:12 Done.
223 return accounts_id;
224 }
225
203 std::vector<std::string> 226 std::vector<std::string>
204 OAuth2TokenServiceDelegateAndroid::GetSystemAccounts() { 227 OAuth2TokenServiceDelegateAndroid::GetSystemAccounts() {
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 Rename this to GetSystemUsernames(). The system a
gogerald1 2015/08/13 18:12:12 Acknowledged.
205 std::vector<std::string> accounts; 228 std::vector<std::string> accounts;
206 JNIEnv* env = AttachCurrentThread(); 229 JNIEnv* env = AttachCurrentThread();
207 ScopedJavaLocalRef<jobjectArray> j_accounts = 230 ScopedJavaLocalRef<jobjectArray> j_accounts =
208 Java_OAuth2TokenService_getSystemAccounts( 231 Java_OAuth2TokenService_getSystemAccounts(
209 env, base::android::GetApplicationContext()); 232 env, base::android::GetApplicationContext());
210 base::android::AppendJavaStringArrayToStringVector(env, j_accounts.obj(), 233 base::android::AppendJavaStringArrayToStringVector(env, j_accounts.obj(),
211 &accounts); 234 &accounts);
212 return accounts; 235 return accounts;
213 } 236 }
214 237
215 OAuth2AccessTokenFetcher* 238 OAuth2AccessTokenFetcher*
216 OAuth2TokenServiceDelegateAndroid::CreateAccessTokenFetcher( 239 OAuth2TokenServiceDelegateAndroid::CreateAccessTokenFetcher(
217 const std::string& account_id, 240 const std::string& account_id,
218 net::URLRequestContextGetter* getter, 241 net::URLRequestContextGetter* getter,
219 OAuth2AccessTokenConsumer* consumer) { 242 OAuth2AccessTokenConsumer* consumer) {
220 ValidateAccountId(account_id); 243 std::string accountid = MapUserAccountIdToOs(account_id);
221 return new AndroidAccessTokenFetcher(consumer, account_id); 244 if (accountid.empty())
245 accountid = account_id;
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 When would MapUserAccountIdToOs() return an empty
gogerald1 2015/08/13 18:12:12 Done.
246 ValidateAccountId(accountid);
247 return new AndroidAccessTokenFetcher(consumer, accountid);
222 } 248 }
223 249
224 void OAuth2TokenServiceDelegateAndroid::InvalidateAccessToken( 250 void OAuth2TokenServiceDelegateAndroid::InvalidateAccessToken(
225 const std::string& account_id, 251 const std::string& account_id,
226 const std::string& client_id, 252 const std::string& client_id,
227 const OAuth2TokenService::ScopeSet& scopes, 253 const OAuth2TokenService::ScopeSet& scopes,
228 const std::string& access_token) { 254 const std::string& access_token) {
229 ValidateAccountId(account_id); 255 ValidateAccountId(MapUserAccountIdToOs(account_id));
230 JNIEnv* env = AttachCurrentThread(); 256 JNIEnv* env = AttachCurrentThread();
231 ScopedJavaLocalRef<jstring> j_access_token = 257 ScopedJavaLocalRef<jstring> j_access_token =
232 ConvertUTF8ToJavaString(env, access_token); 258 ConvertUTF8ToJavaString(env, access_token);
233 Java_OAuth2TokenService_invalidateOAuth2AuthToken( 259 Java_OAuth2TokenService_invalidateOAuth2AuthToken(
234 env, base::android::GetApplicationContext(), j_access_token.obj()); 260 env, base::android::GetApplicationContext(), j_access_token.obj());
235 } 261 }
236 262
237 void OAuth2TokenServiceDelegateAndroid::ValidateAccounts( 263 void OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
238 JNIEnv* env, 264 JNIEnv* env,
239 jobject obj, 265 jobject obj,
240 jstring j_current_acc, 266 jstring j_current_acc,
241 jboolean j_force_notifications) { 267 jboolean j_force_notifications) {
242 std::string signed_in_account; 268 std::string signed_in_account;
243 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts from java"; 269 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts from java";
244 if (j_current_acc) 270 if (j_current_acc)
245 signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); 271 signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc);
246 if (!signed_in_account.empty()) 272 if (!signed_in_account.empty())
247 signed_in_account = gaia::CanonicalizeEmail(signed_in_account); 273 signed_in_account = gaia::CanonicalizeEmail(signed_in_account);
248 ValidateAccounts(signed_in_account, j_force_notifications != JNI_FALSE); 274 ValidateAccountsWithOsTypeIds(signed_in_account,
275 j_force_notifications != JNI_FALSE);
249 } 276 }
250 277
251 void OAuth2TokenServiceDelegateAndroid::ValidateAccounts( 278 void OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
252 const std::string& signed_in_account, 279 const std::string& signed_in_account,
253 bool force_notifications) { 280 bool force_notifications) {
254 std::vector<std::string> prev_ids = GetAccounts(); 281 ValidateAccountsWithOsTypeIds(MapUserAccountIdToOs(signed_in_account),
282 force_notifications);
283 }
284
285 void OAuth2TokenServiceDelegateAndroid::ValidateAccountsWithOsTypeIds(
286 const std::string& signed_in_account,
287 bool force_notifications) {
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 I don't think we should be validating accounts wit
gogerald1 2015/08/13 18:12:12 Done.
288 std::vector<std::string> prev_ids = GetPersistentAccounts();
255 std::vector<std::string> curr_ids = GetSystemAccounts(); 289 std::vector<std::string> curr_ids = GetSystemAccounts();
256 std::vector<std::string> refreshed_ids; 290 std::vector<std::string> refreshed_ids;
257 std::vector<std::string> revoked_ids; 291 std::vector<std::string> revoked_ids;
258 292
259 // Canonicalize system accounts. |prev_ids| is already done. 293 // Canonicalize system accounts. |prev_ids| is already done.
260 for (size_t i = 0; i < curr_ids.size(); ++i) 294 for (size_t i = 0; i < curr_ids.size(); ++i)
261 curr_ids[i] = gaia::CanonicalizeEmail(curr_ids[i]); 295 curr_ids[i] = gaia::CanonicalizeEmail(curr_ids[i]);
262 for (size_t i = 0; i < prev_ids.size(); ++i) 296 for (size_t i = 0; i < prev_ids.size(); ++i)
263 ValidateAccountId(prev_ids[i]); 297 ValidateAccountId(prev_ids[i]);
264 298
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 403
370 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenAvailable( 404 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenAvailable(
371 const std::string& account_id) { 405 const std::string& account_id) {
372 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokenAvailable id=" 406 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokenAvailable id="
373 << account_id; 407 << account_id;
374 JNIEnv* env = AttachCurrentThread(); 408 JNIEnv* env = AttachCurrentThread();
375 ScopedJavaLocalRef<jstring> account_name = 409 ScopedJavaLocalRef<jstring> account_name =
376 ConvertUTF8ToJavaString(env, account_id); 410 ConvertUTF8ToJavaString(env, account_id);
377 Java_OAuth2TokenService_notifyRefreshTokenAvailable(env, java_ref_.obj(), 411 Java_OAuth2TokenService_notifyRefreshTokenAvailable(env, java_ref_.obj(),
378 account_name.obj()); 412 account_name.obj());
379 OAuth2TokenServiceDelegate::FireRefreshTokenAvailable(account_id); 413 OAuth2TokenServiceDelegate::FireRefreshTokenAvailable(
414 MapOsAccountIdToUser(account_id));
380 } 415 }
381 416
382 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevokedFromJava( 417 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevokedFromJava(
383 JNIEnv* env, 418 JNIEnv* env,
384 jobject obj, 419 jobject obj,
385 const jstring account_name) { 420 const jstring account_name) {
386 std::string account_id = ConvertJavaStringToUTF8(env, account_name); 421 std::string account_id = ConvertJavaStringToUTF8(env, account_name);
387 // Notify native observers. 422 // Notify native observers.
388 FireRefreshTokenRevoked(account_id); 423 FireRefreshTokenRevoked(account_id);
389 } 424 }
390 425
391 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevoked( 426 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevoked(
392 const std::string& account_id) { 427 const std::string& account_id) {
393 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevoked id=" 428 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevoked id="
394 << account_id; 429 << account_id;
395 JNIEnv* env = AttachCurrentThread(); 430 JNIEnv* env = AttachCurrentThread();
396 ScopedJavaLocalRef<jstring> account_name = 431 ScopedJavaLocalRef<jstring> account_name =
397 ConvertUTF8ToJavaString(env, account_id); 432 ConvertUTF8ToJavaString(env, account_id);
398 Java_OAuth2TokenService_notifyRefreshTokenRevoked(env, java_ref_.obj(), 433 Java_OAuth2TokenService_notifyRefreshTokenRevoked(env, java_ref_.obj(),
399 account_name.obj()); 434 account_name.obj());
400 OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(account_id); 435 OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(
436 MapOsAccountIdToUser(account_id));
401 } 437 }
402 438
403 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokensLoadedFromJava( 439 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokensLoadedFromJava(
404 JNIEnv* env, 440 JNIEnv* env,
405 jobject obj) { 441 jobject obj) {
406 // Notify native observers. 442 // Notify native observers.
407 FireRefreshTokensLoaded(); 443 FireRefreshTokensLoaded();
408 } 444 }
409 445
410 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokensLoaded() { 446 void OAuth2TokenServiceDelegateAndroid::FireRefreshTokensLoaded() {
411 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokensLoaded"; 447 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokensLoaded";
412 JNIEnv* env = AttachCurrentThread(); 448 JNIEnv* env = AttachCurrentThread();
413 Java_OAuth2TokenService_notifyRefreshTokensLoaded(env, java_ref_.obj()); 449 Java_OAuth2TokenService_notifyRefreshTokensLoaded(env, java_ref_.obj());
414 OAuth2TokenServiceDelegate::FireRefreshTokensLoaded(); 450 OAuth2TokenServiceDelegate::FireRefreshTokensLoaded();
415 } 451 }
416 452
417 void OAuth2TokenServiceDelegateAndroid::RevokeAllCredentials() { 453 void OAuth2TokenServiceDelegateAndroid::RevokeAllCredentials() {
418 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::RevokeAllCredentials"; 454 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::RevokeAllCredentials";
419 ScopedBatchChange batch(this); 455 ScopedBatchChange batch(this);
420 std::vector<std::string> accounts = GetAccounts(); 456 std::vector<std::string> accounts = GetPersistentAccounts();
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 This is case where the code assumes GetPersistentA
gogerald1 2015/08/13 18:12:12 Done.
421 for (std::vector<std::string>::iterator it = accounts.begin(); 457 for (std::vector<std::string>::iterator it = accounts.begin();
422 it != accounts.end(); it++) { 458 it != accounts.end(); it++) {
423 FireRefreshTokenRevoked(*it); 459 FireRefreshTokenRevoked(*it);
424 } 460 }
425 461
426 // Clear everything on the Java side as well. 462 // Clear everything on the Java side as well.
427 std::vector<std::string> empty; 463 std::vector<std::string> empty;
428 JNIEnv* env = AttachCurrentThread(); 464 JNIEnv* env = AttachCurrentThread();
429 ScopedJavaLocalRef<jobjectArray> java_accounts( 465 ScopedJavaLocalRef<jobjectArray> java_accounts(
430 base::android::ToJavaArrayOfStrings(env, empty)); 466 base::android::ToJavaArrayOfStrings(env, empty));
431 Java_OAuth2TokenService_saveStoredAccounts( 467 Java_OAuth2TokenService_saveStoredAccounts(
432 env, base::android::GetApplicationContext(), java_accounts.obj()); 468 env, base::android::GetApplicationContext(), java_accounts.obj());
433 } 469 }
434 470
471 std::string OAuth2TokenServiceDelegateAndroid::MapUserAccountIdToOs(
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 Maybe call this function: MapAccountIdToSystemUser
gogerald1 2015/08/13 18:12:12 Acknowledged.
472 const std::string& user_account_id) const {
473 if (account_tracker_service_->GetMigrationState() !=
474 AccountTrackerService::MIGRATION_NOT_STARTED) {
475 return account_tracker_service_->GetAccountInfo(user_account_id).email;
476 }
477 return user_account_id;
478 }
479
480 std::string OAuth2TokenServiceDelegateAndroid::MapOsAccountIdToUser(
481 const std::string& os_account_id) const {
482 if (account_tracker_service_->GetMigrationState() !=
483 AccountTrackerService::MIGRATION_NOT_STARTED) {
484 return account_tracker_service_->FindAccountInfoByEmail(os_account_id)
485 .account_id;
486 }
487
488 return os_account_id;
489 }
490
491 void OAuth2TokenServiceDelegateAndroid::SeedAccountsInfo(
492 JNIEnv* env,
493 jobject obj,
494 jobjectArray gaiaids,
495 jobjectArray usernames) {
496 std::vector<std::string> gaia_ids;
497 std::vector<std::string> account_names;
498 base::android::AppendJavaStringArrayToStringVector(env, gaiaids, &gaia_ids);
499 base::android::AppendJavaStringArrayToStringVector(env, usernames,
500 &account_names);
Roger Tawa OOO till Jul 10th 2015/08/12 15:28:47 DCHECK that arrays are same length.
gogerald1 2015/08/13 18:12:12 Done.
501
502 for (unsigned int i = 0; i < gaia_ids.size(); i++) {
503 account_tracker_service_->SeedAccountInfo(gaia_ids[i], account_names[i]);
504 }
505 }
435 // Called from Java when fetching of an OAuth2 token is finished. The 506 // Called from Java when fetching of an OAuth2 token is finished. The
436 // |authToken| param is only valid when |result| is true. 507 // |authToken| param is only valid when |result| is true.
437 void OAuth2TokenFetched(JNIEnv* env, 508 void OAuth2TokenFetched(JNIEnv* env,
438 jclass clazz, 509 jclass clazz,
439 jstring authToken, 510 jstring authToken,
440 jlong nativeCallback) { 511 jlong nativeCallback) {
441 std::string token; 512 std::string token;
442 if (authToken) 513 if (authToken)
443 token = ConvertJavaStringToUTF8(env, authToken); 514 token = ConvertJavaStringToUTF8(env, authToken);
444 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( 515 scoped_ptr<FetchOAuth2TokenCallback> heap_callback(
445 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); 516 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback));
446 // Android does not provide enough information to know if the credentials are 517 // Android does not provide enough information to know if the credentials are
447 // wrong, so assume any error is transient by using CONNECTION_FAILED. 518 // wrong, so assume any error is transient by using CONNECTION_FAILED.
448 GoogleServiceAuthError err(authToken 519 GoogleServiceAuthError err(authToken
449 ? GoogleServiceAuthError::NONE 520 ? GoogleServiceAuthError::NONE
450 : GoogleServiceAuthError::CONNECTION_FAILED); 521 : GoogleServiceAuthError::CONNECTION_FAILED);
451 heap_callback->Run(err, token, base::Time()); 522 heap_callback->Run(err, token, base::Time());
452 } 523 }
453 524
454 // static 525 // static
455 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { 526 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) {
456 return RegisterNativesImpl(env); 527 return RegisterNativesImpl(env);
457 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698