Chromium Code Reviews| Index: chrome/browser/signin/android_profile_oauth2_token_service.cc |
| diff --git a/chrome/browser/signin/android_profile_oauth2_token_service.cc b/chrome/browser/signin/android_profile_oauth2_token_service.cc |
| index 71fe1c3b684c752705b2089b178ef77ef6c1e1ac..0cc2f397e3b655e42a1fa0fc979332e6a9661a85 100644 |
| --- a/chrome/browser/signin/android_profile_oauth2_token_service.cc |
| +++ b/chrome/browser/signin/android_profile_oauth2_token_service.cc |
| @@ -157,13 +157,14 @@ void AndroidProfileOAuth2TokenService::InvalidateOAuth2Token( |
| j_access_token.obj()); |
| } |
| -void AndroidProfileOAuth2TokenService::ValidateAccounts(JNIEnv* env, |
| - jobject obj, |
| - jobjectArray accounts, |
| - jstring j_current_acc) { |
| +void AndroidProfileOAuth2TokenService::ValidateAccounts( |
| + JNIEnv* env, |
| + jobject obj, |
| + jobjectArray prev_account_ids, |
| + jstring j_current_acc) { |
| std::vector<std::string> account_ids; |
| base::android::AppendJavaStringArrayToStringVector(env, |
| - accounts, |
| + prev_account_ids, |
| &account_ids); |
| std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); |
| ValidateAccounts(signed_in_account, account_ids); |
| @@ -171,29 +172,44 @@ void AndroidProfileOAuth2TokenService::ValidateAccounts(JNIEnv* env, |
| void AndroidProfileOAuth2TokenService::ValidateAccounts( |
| const std::string& signed_in_account, |
| - const std::vector<std::string>& account_ids) { |
| + const std::vector<std::string>& prev_account_ids) { |
| if (signed_in_account.empty()) |
| return; |
| + std::vector<std::string> account_ids = GetAccounts(); |
| if (std::find(account_ids.begin(), |
| account_ids.end(), |
| signed_in_account) != account_ids.end()) { |
| - // Currently signed in account still exists among accounts on system. |
| - std::vector<std::string> ids = GetAccounts(); |
| + // Test to see if an account is removed from the Android AccountManager. |
| + // If so, invoke FireRefreshTokenRevoked to notify the reconcilor. |
| + for (std::vector<std::string>::const_iterator it = prev_account_ids.begin(); |
| + it != prev_account_ids.end(); it++) { |
| + if (*it == signed_in_account) |
| + continue; |
| + |
| + if (std::find(account_ids.begin(), |
| + account_ids.end(), |
| + *it) == account_ids.end()) { |
| + FireRefreshTokenRevoked(*it); |
| + } |
| + } |
| // Always fire the primary signed in account first. |
| FireRefreshTokenAvailable(signed_in_account); |
| - for (std::vector<std::string>::iterator it = ids.begin(); |
| - it != ids.end(); it++) { |
| + for (std::vector<std::string>::iterator it = account_ids.begin(); |
| + it != account_ids.end(); it++) { |
| if (*it != signed_in_account) { |
| FireRefreshTokenAvailable(*it); |
| } |
| } |
| } else { |
| // Currently signed in account does not any longer exist among accounts on |
| - // system. |
| - FireRefreshTokenRevoked(signed_in_account); |
| + // system together with all other accounts. |
| + for (std::vector<std::string>::iterator it = account_ids.begin(); |
| + it != account_ids.end(); it++) { |
|
Roger Tawa OOO till Jul 10th
2014/04/08 20:40:53
Should this be |prev_account_ids| instead of |acco
acleung1
2014/04/09 00:55:00
Yes. It will cover the case where user deletes ano
|
| + FireRefreshTokenRevoked(*it); |
| + } |
| } |
| } |
| @@ -252,6 +268,14 @@ void AndroidProfileOAuth2TokenService::FireRefreshTokensLoaded() { |
| env, java_ref_.obj()); |
| } |
| +void AndroidProfileOAuth2TokenService::RevokeAllCredentials() { |
| + std::vector<std::string> accounts = GetAccounts(); |
| + for (std::vector<std::string>::iterator it = accounts.begin(); |
| + it != accounts.end(); it++) { |
| + FireRefreshTokenRevoked(*it); |
| + } |
| +} |
| + |
| // Called from Java when fetching of an OAuth2 token is finished. The |
| // |authToken| param is only valid when |result| is true. |
| void OAuth2TokenFetched(JNIEnv* env, jclass clazz, |