Chromium Code Reviews| 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/android_profile_oauth2_token_service.h" | 5 #include "chrome/browser/signin/android_profile_oauth2_token_service.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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 std::vector<std::string> account_ids; | 164 std::vector<std::string> account_ids; |
| 165 base::android::AppendJavaStringArrayToStringVector(env, | 165 base::android::AppendJavaStringArrayToStringVector(env, |
| 166 accounts, | 166 accounts, |
| 167 &account_ids); | 167 &account_ids); |
| 168 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); | 168 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); |
| 169 ValidateAccounts(signed_in_account, account_ids); | 169 ValidateAccounts(signed_in_account, account_ids); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void AndroidProfileOAuth2TokenService::ValidateAccounts( | 172 void AndroidProfileOAuth2TokenService::ValidateAccounts( |
| 173 const std::string& signed_in_account, | 173 const std::string& signed_in_account, |
| 174 const std::vector<std::string>& account_ids) { | 174 const std::vector<std::string>& last_seen_ids) { |
| 175 if (signed_in_account.empty()) | 175 if (signed_in_account.empty()) |
| 176 return; | 176 return; |
| 177 | 177 |
| 178 std::vector<std::string> account_ids = GetAccounts(); | |
| 178 if (std::find(account_ids.begin(), | 179 if (std::find(account_ids.begin(), |
| 179 account_ids.end(), | 180 account_ids.end(), |
| 180 signed_in_account) != account_ids.end()) { | 181 signed_in_account) != account_ids.end()) { |
| 181 // Currently signed in account still exists among accounts on system. | 182 // Test to see if an account is removed from the Android AccountManager. |
| 182 std::vector<std::string> ids = GetAccounts(); | 183 // If so, invoke FireRefreshTokenRevoked to notify the reconcilor. |
| 184 for (std::vector<std::string>::const_iterator it = last_seen_ids.begin(); | |
| 185 it != last_seen_ids.end(); it++) { | |
| 186 if (*it == signed_in_account) | |
| 187 continue; | |
| 188 | |
| 189 if (std::find(account_ids.begin(), | |
| 190 account_ids.end(), | |
| 191 *it) == account_ids.end()) { | |
| 192 FireRefreshTokenRevoked(*it); | |
| 193 } | |
| 194 } | |
| 183 | 195 |
| 184 // Always fire the primary signed in account first. | 196 // Always fire the primary signed in account first. |
| 185 FireRefreshTokenAvailable(signed_in_account); | 197 FireRefreshTokenAvailable(signed_in_account); |
| 186 | 198 |
| 187 for (std::vector<std::string>::iterator it = ids.begin(); | 199 for (std::vector<std::string>::iterator it = account_ids.begin(); |
| 188 it != ids.end(); it++) { | 200 it != account_ids.end(); it++) { |
| 189 if (*it != signed_in_account) { | 201 if (*it != signed_in_account) { |
| 190 FireRefreshTokenAvailable(*it); | 202 FireRefreshTokenAvailable(*it); |
| 191 } | 203 } |
| 192 } | 204 } |
| 193 } else { | 205 } else { |
| 194 // Currently signed in account does not any longer exist among accounts on | 206 // Currently signed in account does not any longer exist among accounts on |
| 195 // system. | 207 // system. |
| 196 FireRefreshTokenRevoked(signed_in_account); | 208 FireRefreshTokenRevoked(signed_in_account); |
|
Roger Tawa OOO till Jul 10th
2014/04/02 14:57:53
Should also fire revoke for all last seen accounts
| |
| 197 } | 209 } |
| 198 } | 210 } |
| 199 | 211 |
| 200 void AndroidProfileOAuth2TokenService::FireRefreshTokenAvailableFromJava( | 212 void AndroidProfileOAuth2TokenService::FireRefreshTokenAvailableFromJava( |
| 201 JNIEnv* env, | 213 JNIEnv* env, |
| 202 jobject obj, | 214 jobject obj, |
| 203 const jstring account_name) { | 215 const jstring account_name) { |
| 204 std::string account_id = ConvertJavaStringToUTF8(env, account_name); | 216 std::string account_id = ConvertJavaStringToUTF8(env, account_name); |
| 205 AndroidProfileOAuth2TokenService::FireRefreshTokenAvailable(account_id); | 217 AndroidProfileOAuth2TokenService::FireRefreshTokenAvailable(account_id); |
| 206 } | 218 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 257 |
| 246 void AndroidProfileOAuth2TokenService::FireRefreshTokensLoaded() { | 258 void AndroidProfileOAuth2TokenService::FireRefreshTokensLoaded() { |
| 247 // Notify native observers. | 259 // Notify native observers. |
| 248 OAuth2TokenService::FireRefreshTokensLoaded(); | 260 OAuth2TokenService::FireRefreshTokensLoaded(); |
| 249 // Notify Java observers. | 261 // Notify Java observers. |
| 250 JNIEnv* env = AttachCurrentThread(); | 262 JNIEnv* env = AttachCurrentThread(); |
| 251 Java_OAuth2TokenService_notifyRefreshTokensLoaded( | 263 Java_OAuth2TokenService_notifyRefreshTokensLoaded( |
| 252 env, java_ref_.obj()); | 264 env, java_ref_.obj()); |
| 253 } | 265 } |
| 254 | 266 |
| 267 void AndroidProfileOAuth2TokenService::RevokeAllCredentials() { | |
| 268 std::vector<std::string> accounts = GetAccounts(); | |
| 269 for (std::vector<std::string>::iterator it = accounts.begin(); | |
| 270 it != accounts.end(); it++) { | |
| 271 FireRefreshTokenRevoked(*it); | |
| 272 } | |
| 273 } | |
| 274 | |
| 255 // Called from Java when fetching of an OAuth2 token is finished. The | 275 // Called from Java when fetching of an OAuth2 token is finished. The |
| 256 // |authToken| param is only valid when |result| is true. | 276 // |authToken| param is only valid when |result| is true. |
| 257 void OAuth2TokenFetched(JNIEnv* env, jclass clazz, | 277 void OAuth2TokenFetched(JNIEnv* env, jclass clazz, |
| 258 jstring authToken, | 278 jstring authToken, |
| 259 jboolean result, | 279 jboolean result, |
| 260 jlong nativeCallback) { | 280 jlong nativeCallback) { |
| 261 std::string token = ConvertJavaStringToUTF8(env, authToken); | 281 std::string token = ConvertJavaStringToUTF8(env, authToken); |
| 262 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( | 282 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( |
| 263 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); | 283 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); |
| 264 // Android does not provide enough information to know if the credentials are | 284 // Android does not provide enough information to know if the credentials are |
| 265 // wrong, so assume any error is transient by using CONNECTION_FAILED. | 285 // wrong, so assume any error is transient by using CONNECTION_FAILED. |
| 266 GoogleServiceAuthError err(result ? | 286 GoogleServiceAuthError err(result ? |
| 267 GoogleServiceAuthError::NONE : | 287 GoogleServiceAuthError::NONE : |
| 268 GoogleServiceAuthError::CONNECTION_FAILED); | 288 GoogleServiceAuthError::CONNECTION_FAILED); |
| 269 heap_callback->Run(err, token, base::Time()); | 289 heap_callback->Run(err, token, base::Time()); |
| 270 } | 290 } |
| 271 | 291 |
| 272 // static | 292 // static |
| 273 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { | 293 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { |
| 274 return RegisterNativesImpl(env); | 294 return RegisterNativesImpl(env); |
| 275 } | 295 } |
| OLD | NEW |