Chromium Code Reviews| Index: chrome/browser/sync/profile_sync_service_android.cc |
| diff --git a/chrome/browser/sync/profile_sync_service_android.cc b/chrome/browser/sync/profile_sync_service_android.cc |
| index 7c32924d67ad22bc9e8ea695359489314049a294..882478c982a5edba83b2ea1e7690c250684c52ed 100644 |
| --- a/chrome/browser/sync/profile_sync_service_android.cc |
| +++ b/chrome/browser/sync/profile_sync_service_android.cc |
| @@ -15,6 +15,7 @@ |
| #include "base/time.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/signin/oauth2_token_service.h" |
| #include "chrome/browser/signin/signin_manager.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| #include "chrome/browser/signin/token_service.h" |
| @@ -169,6 +170,49 @@ void ProfileSyncServiceAndroid::TokenAvailable( |
| GaiaConstants::kSyncService, token); |
| } |
| +void ProfileSyncServiceAndroid::FetchOAuth2Token( |
| + const std::string& scope, const std::string& invalid_auth_token, |
| + const FetchOAuth2TokenCallback& callback) { |
| + const std::string& sync_username = |
| + SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername(); |
| + |
| + // Call into java to invalidate the current token and get a new one. |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jstring> j_sync_username = |
| + ConvertUTF8ToJavaString(env, sync_username); |
| + ScopedJavaLocalRef<jstring> j_scope = |
| + ConvertUTF8ToJavaString(env, scope); |
| + ScopedJavaLocalRef<jstring> j_invalid_auth_token; |
| + |
| + if (!invalid_auth_token.empty()) { |
| + j_invalid_auth_token.Reset( |
| + ConvertUTF8ToJavaString(env, invalid_auth_token)); |
| + } |
| + |
| + // Allocate a copy of the callback on the heap, because we need a pointer to |
|
Nicolas Zea
2013/03/25 18:13:18
nit: "we" here is ambiguous. Perhaps just "because
Patrick Dubroy
2013/03/25 18:52:55
Done.
|
| + // hold on to. |
| + scoped_ptr<FetchOAuth2TokenCallback> heap_callback( |
| + new FetchOAuth2TokenCallback(callback)); |
| + |
| + Java_ProfileSyncService_getOAuth2AuthToken( |
| + env, weak_java_profile_sync_service_.get(env).obj(), |
| + j_sync_username.obj(), |
| + j_scope.obj(), |
| + j_invalid_auth_token.obj(), |
| + reinterpret_cast<int>(heap_callback.release())); |
| +} |
| + |
| +void ProfileSyncServiceAndroid::OAuth2TokenFetched( |
| + JNIEnv* env, jobject, int callback, jstring auth_token, jboolean result) { |
| + std::string token = ConvertJavaStringToUTF8(env, auth_token); |
| + scoped_ptr<FetchOAuth2TokenCallback> heap_callback( |
| + reinterpret_cast<FetchOAuth2TokenCallback*>(callback)); |
| + GoogleServiceAuthError err(result ? |
| + GoogleServiceAuthError::NONE : |
| + GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| + heap_callback->Run(err, token, base::Time()); |
| +} |
| + |
| void ProfileSyncServiceAndroid::EnableSync(JNIEnv* env, jobject) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| // Don't need to do anything if we're already enabled. |
| @@ -534,6 +578,14 @@ void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env, |
| ConvertJavaStringToUTF8(env, state)); |
| } |
| +// static |
| +ProfileSyncServiceAndroid* |
| + ProfileSyncServiceAndroid::GetProfileSyncServiceAndroid() { |
| + return reinterpret_cast<ProfileSyncServiceAndroid*>( |
| + Java_ProfileSyncService_getProfileSyncServiceAndroid( |
| + AttachCurrentThread(), base::android::GetApplicationContext())); |
| +} |
| + |
| static int Init(JNIEnv* env, jobject obj) { |
| ProfileSyncServiceAndroid* profile_sync_service_android = |
| new ProfileSyncServiceAndroid(env, obj); |