OLD | NEW |
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/context_utils.h" | 7 #include "base/android/context_utils.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 fire_refresh_token_loaded_ = RT_LOADED; | 357 fire_refresh_token_loaded_ = RT_LOADED; |
358 FireRefreshTokensLoaded(); | 358 FireRefreshTokensLoaded(); |
359 } else if (fire_refresh_token_loaded_ == RT_LOAD_NOT_START) { | 359 } else if (fire_refresh_token_loaded_ == RT_LOAD_NOT_START) { |
360 fire_refresh_token_loaded_ = RT_HAS_BEEN_VALIDATED; | 360 fire_refresh_token_loaded_ = RT_HAS_BEEN_VALIDATED; |
361 } | 361 } |
362 | 362 |
363 // Clear accounts no longer exist on device from AccountTrackerService. | 363 // Clear accounts no longer exist on device from AccountTrackerService. |
364 std::vector<AccountInfo> accounts_info = | 364 std::vector<AccountInfo> accounts_info = |
365 account_tracker_service_->GetAccounts(); | 365 account_tracker_service_->GetAccounts(); |
366 for (const AccountInfo& info : accounts_info) { | 366 for (const AccountInfo& info : accounts_info) { |
367 if (!ContainsValue(curr_ids, info.account_id)) | 367 if (!base::ContainsValue(curr_ids, info.account_id)) |
368 account_tracker_service_->RemoveAccount(info.account_id); | 368 account_tracker_service_->RemoveAccount(info.account_id); |
369 } | 369 } |
370 | 370 |
371 // No need to wait for SigninManager to finish migration if not signed in. | 371 // No need to wait for SigninManager to finish migration if not signed in. |
372 if (account_tracker_service_->GetMigrationState() == | 372 if (account_tracker_service_->GetMigrationState() == |
373 AccountTrackerService::MIGRATION_IN_PROGRESS && | 373 AccountTrackerService::MIGRATION_IN_PROGRESS && |
374 signed_in_account_id.empty()) { | 374 signed_in_account_id.empty()) { |
375 account_tracker_service_->SetMigrationDone(); | 375 account_tracker_service_->SetMigrationDone(); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 bool OAuth2TokenServiceDelegateAndroid::ValidateAccounts( | 379 bool OAuth2TokenServiceDelegateAndroid::ValidateAccounts( |
380 const std::string& signed_in_id, | 380 const std::string& signed_in_id, |
381 const std::vector<std::string>& prev_ids, | 381 const std::vector<std::string>& prev_ids, |
382 const std::vector<std::string>& curr_ids, | 382 const std::vector<std::string>& curr_ids, |
383 std::vector<std::string>* refreshed_ids, | 383 std::vector<std::string>* refreshed_ids, |
384 std::vector<std::string>* revoked_ids, | 384 std::vector<std::string>* revoked_ids, |
385 bool force_notifications) { | 385 bool force_notifications) { |
386 bool currently_signed_in = ContainsValue(curr_ids, signed_in_id); | 386 bool currently_signed_in = base::ContainsValue(curr_ids, signed_in_id); |
387 if (currently_signed_in) { | 387 if (currently_signed_in) { |
388 // Revoke token for ids that have been removed from the device. | 388 // Revoke token for ids that have been removed from the device. |
389 for (const std::string& prev_id : prev_ids) { | 389 for (const std::string& prev_id : prev_ids) { |
390 if (prev_id == signed_in_id) | 390 if (prev_id == signed_in_id) |
391 continue; | 391 continue; |
392 if (!ContainsValue(curr_ids, prev_id)) { | 392 if (!base::ContainsValue(curr_ids, prev_id)) { |
393 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" | 393 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" |
394 << "revoked=" << prev_id; | 394 << "revoked=" << prev_id; |
395 revoked_ids->push_back(prev_id); | 395 revoked_ids->push_back(prev_id); |
396 } | 396 } |
397 } | 397 } |
398 | 398 |
399 // Refresh token for new ids or all ids if |force_notifications|. | 399 // Refresh token for new ids or all ids if |force_notifications|. |
400 if (force_notifications || | 400 if (force_notifications || !base::ContainsValue(prev_ids, signed_in_id)) { |
401 !ContainsValue(prev_ids, signed_in_id)) { | |
402 // Always fire the primary signed in account first. | 401 // Always fire the primary signed in account first. |
403 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" | 402 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" |
404 << "refreshed=" << signed_in_id; | 403 << "refreshed=" << signed_in_id; |
405 refreshed_ids->push_back(signed_in_id); | 404 refreshed_ids->push_back(signed_in_id); |
406 } | 405 } |
407 for (const std::string& curr_id : curr_ids) { | 406 for (const std::string& curr_id : curr_ids) { |
408 if (curr_id == signed_in_id) | 407 if (curr_id == signed_in_id) |
409 continue; | 408 continue; |
410 if (force_notifications || | 409 if (force_notifications || !base::ContainsValue(prev_ids, curr_id)) { |
411 !ContainsValue(prev_ids, curr_id)) { | |
412 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" | 410 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" |
413 << "refreshed=" << curr_id; | 411 << "refreshed=" << curr_id; |
414 refreshed_ids->push_back(curr_id); | 412 refreshed_ids->push_back(curr_id); |
415 } | 413 } |
416 } | 414 } |
417 } else { | 415 } else { |
418 if (ContainsValue(prev_ids, signed_in_id)) { | 416 if (base::ContainsValue(prev_ids, signed_in_id)) { |
419 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" | 417 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" |
420 << "revoked=" << signed_in_id; | 418 << "revoked=" << signed_in_id; |
421 revoked_ids->push_back(signed_in_id); | 419 revoked_ids->push_back(signed_in_id); |
422 } | 420 } |
423 for (const std::string& prev_id : prev_ids) { | 421 for (const std::string& prev_id : prev_ids) { |
424 if (prev_id == signed_in_id) | 422 if (prev_id == signed_in_id) |
425 continue; | 423 continue; |
426 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" | 424 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:" |
427 << "revoked=" << prev_id; | 425 << "revoked=" << prev_id; |
428 revoked_ids->push_back(prev_id); | 426 revoked_ids->push_back(prev_id); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 : isTransientError | 567 : isTransientError |
570 ? GoogleServiceAuthError::CONNECTION_FAILED | 568 ? GoogleServiceAuthError::CONNECTION_FAILED |
571 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 569 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
572 heap_callback->Run(err, token, base::Time()); | 570 heap_callback->Run(err, token, base::Time()); |
573 } | 571 } |
574 | 572 |
575 // static | 573 // static |
576 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { | 574 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { |
577 return RegisterNativesImpl(env); | 575 return RegisterNativesImpl(env); |
578 } | 576 } |
OLD | NEW |