| 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/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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 jclass clazz, | 155 jclass clazz, |
| 156 jobject j_profile_android) { | 156 jobject j_profile_android) { |
| 157 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile_android); | 157 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile_android); |
| 158 ProfileOAuth2TokenService* service = | 158 ProfileOAuth2TokenService* service = |
| 159 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 159 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 160 OAuth2TokenServiceDelegate* delegate = service->GetDelegate(); | 160 OAuth2TokenServiceDelegate* delegate = service->GetDelegate(); |
| 161 return ScopedJavaLocalRef<jobject>( | 161 return ScopedJavaLocalRef<jobject>( |
| 162 static_cast<OAuth2TokenServiceDelegateAndroid*>(delegate)->java_ref_); | 162 static_cast<OAuth2TokenServiceDelegateAndroid*>(delegate)->java_ref_); |
| 163 } | 163 } |
| 164 | 164 |
| 165 static ScopedJavaLocalRef<jobject> GetForProfile(JNIEnv* env, | 165 static ScopedJavaLocalRef<jobject> GetForProfile( |
| 166 jclass clazz, | 166 JNIEnv* env, |
| 167 jobject j_profile_android) { | 167 const JavaParamRef<jclass>& clazz, |
| 168 const JavaParamRef<jobject>& j_profile_android) { |
| 168 return OAuth2TokenServiceDelegateAndroid::GetForProfile(env, clazz, | 169 return OAuth2TokenServiceDelegateAndroid::GetForProfile(env, clazz, |
| 169 j_profile_android); | 170 j_profile_android); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void OAuth2TokenServiceDelegateAndroid::Initialize() { | 173 void OAuth2TokenServiceDelegateAndroid::Initialize() { |
| 173 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::Initialize"; | 174 DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::Initialize"; |
| 174 if (!is_testing_profile_) { | 175 if (!is_testing_profile_) { |
| 175 Java_OAuth2TokenService_validateAccounts( | 176 Java_OAuth2TokenService_validateAccounts( |
| 176 AttachCurrentThread(), java_ref_.obj(), | 177 AttachCurrentThread(), java_ref_.obj(), |
| 177 base::android::GetApplicationContext(), JNI_TRUE); | 178 base::android::GetApplicationContext(), JNI_TRUE); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 JNIEnv* env = AttachCurrentThread(); | 455 JNIEnv* env = AttachCurrentThread(); |
| 455 ScopedJavaLocalRef<jobjectArray> java_accounts( | 456 ScopedJavaLocalRef<jobjectArray> java_accounts( |
| 456 base::android::ToJavaArrayOfStrings(env, empty)); | 457 base::android::ToJavaArrayOfStrings(env, empty)); |
| 457 Java_OAuth2TokenService_saveStoredAccounts( | 458 Java_OAuth2TokenService_saveStoredAccounts( |
| 458 env, base::android::GetApplicationContext(), java_accounts.obj()); | 459 env, base::android::GetApplicationContext(), java_accounts.obj()); |
| 459 } | 460 } |
| 460 | 461 |
| 461 // Called from Java when fetching of an OAuth2 token is finished. The | 462 // Called from Java when fetching of an OAuth2 token is finished. The |
| 462 // |authToken| param is only valid when |result| is true. | 463 // |authToken| param is only valid when |result| is true. |
| 463 void OAuth2TokenFetched(JNIEnv* env, | 464 void OAuth2TokenFetched(JNIEnv* env, |
| 464 jclass clazz, | 465 const JavaParamRef<jclass>& clazz, |
| 465 jstring authToken, | 466 const JavaParamRef<jstring>& authToken, |
| 466 jboolean isTransientError, | 467 jboolean isTransientError, |
| 467 jlong nativeCallback) { | 468 jlong nativeCallback) { |
| 468 std::string token; | 469 std::string token; |
| 469 if (authToken) | 470 if (authToken) |
| 470 token = ConvertJavaStringToUTF8(env, authToken); | 471 token = ConvertJavaStringToUTF8(env, authToken); |
| 471 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( | 472 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( |
| 472 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); | 473 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); |
| 473 GoogleServiceAuthError | 474 GoogleServiceAuthError |
| 474 err(authToken | 475 err(authToken |
| 475 ? GoogleServiceAuthError::NONE | 476 ? GoogleServiceAuthError::NONE |
| 476 : isTransientError | 477 : isTransientError |
| 477 ? GoogleServiceAuthError::CONNECTION_FAILED | 478 ? GoogleServiceAuthError::CONNECTION_FAILED |
| 478 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 479 : GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 479 heap_callback->Run(err, token, base::Time()); | 480 heap_callback->Run(err, token, base::Time()); |
| 480 } | 481 } |
| 481 | 482 |
| 482 // static | 483 // static |
| 483 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { | 484 bool OAuth2TokenServiceDelegateAndroid::Register(JNIEnv* env) { |
| 484 return RegisterNativesImpl(env); | 485 return RegisterNativesImpl(env); |
| 485 } | 486 } |
| OLD | NEW |