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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 364 } |
365 | 365 |
366 void AndroidProfileOAuth2TokenService::RevokeAllCredentials() { | 366 void AndroidProfileOAuth2TokenService::RevokeAllCredentials() { |
367 VLOG(1) << "AndroidProfileOAuth2TokenService::RevokeAllCredentials"; | 367 VLOG(1) << "AndroidProfileOAuth2TokenService::RevokeAllCredentials"; |
368 ScopedBacthChange batch(this); | 368 ScopedBacthChange batch(this); |
369 std::vector<std::string> accounts = GetAccounts(); | 369 std::vector<std::string> accounts = GetAccounts(); |
370 for (std::vector<std::string>::iterator it = accounts.begin(); | 370 for (std::vector<std::string>::iterator it = accounts.begin(); |
371 it != accounts.end(); it++) { | 371 it != accounts.end(); it++) { |
372 FireRefreshTokenRevoked(*it); | 372 FireRefreshTokenRevoked(*it); |
373 } | 373 } |
| 374 |
| 375 // Clear everything on the Java side as well. |
| 376 std::vector<std::string> empty; |
| 377 JNIEnv* env = AttachCurrentThread(); |
| 378 ScopedJavaLocalRef<jobjectArray> java_accounts( |
| 379 base::android::ToJavaArrayOfStrings(env, empty)); |
| 380 Java_OAuth2TokenService_saveStoredAccounts( |
| 381 env, base::android::GetApplicationContext(), java_accounts.obj()); |
374 } | 382 } |
375 | 383 |
376 // Called from Java when fetching of an OAuth2 token is finished. The | 384 // Called from Java when fetching of an OAuth2 token is finished. The |
377 // |authToken| param is only valid when |result| is true. | 385 // |authToken| param is only valid when |result| is true. |
378 void OAuth2TokenFetched(JNIEnv* env, jclass clazz, | 386 void OAuth2TokenFetched(JNIEnv* env, jclass clazz, |
379 jstring authToken, | 387 jstring authToken, |
380 jboolean result, | 388 jboolean result, |
381 jlong nativeCallback) { | 389 jlong nativeCallback) { |
382 std::string token = ConvertJavaStringToUTF8(env, authToken); | 390 std::string token = ConvertJavaStringToUTF8(env, authToken); |
383 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( | 391 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( |
384 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); | 392 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); |
385 // Android does not provide enough information to know if the credentials are | 393 // Android does not provide enough information to know if the credentials are |
386 // wrong, so assume any error is transient by using CONNECTION_FAILED. | 394 // wrong, so assume any error is transient by using CONNECTION_FAILED. |
387 GoogleServiceAuthError err(result ? | 395 GoogleServiceAuthError err(result ? |
388 GoogleServiceAuthError::NONE : | 396 GoogleServiceAuthError::NONE : |
389 GoogleServiceAuthError::CONNECTION_FAILED); | 397 GoogleServiceAuthError::CONNECTION_FAILED); |
390 heap_callback->Run(err, token, base::Time()); | 398 heap_callback->Run(err, token, base::Time()); |
391 } | 399 } |
392 | 400 |
393 // static | 401 // static |
394 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { | 402 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { |
395 return RegisterNativesImpl(env); | 403 return RegisterNativesImpl(env); |
396 } | 404 } |
OLD | NEW |