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 42a6516214644c8ef7ad350e8ea526da60a7d465..334a27dbc8ec886a0bf751b93faa1dd664930571 100644 |
| --- a/chrome/browser/signin/android_profile_oauth2_token_service.cc |
| +++ b/chrome/browser/signin/android_profile_oauth2_token_service.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/signin/android_profile_oauth2_token_service.h" |
| #include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| #include "base/android/jni_string.h" |
| #include "base/bind.h" |
| #include "base/logging.h" |
| @@ -15,7 +16,6 @@ |
| #include "jni/AndroidProfileOAuth2TokenServiceHelper_jni.h" |
| using base::android::AttachCurrentThread; |
| -using base::android::CheckException; |
| using base::android::ConvertJavaStringToUTF8; |
| using base::android::ConvertUTF8ToJavaString; |
| using base::android::ScopedJavaLocalRef; |
| @@ -54,22 +54,16 @@ AndroidProfileOAuth2TokenService::AndroidProfileOAuth2TokenService() { |
| AndroidProfileOAuth2TokenService::~AndroidProfileOAuth2TokenService() { |
| } |
| -scoped_ptr<OAuth2TokenService::Request> |
| - AndroidProfileOAuth2TokenService::StartRequestForUsername( |
| - const std::string& username, |
| - const OAuth2TokenService::ScopeSet& scopes, |
| - OAuth2TokenService::Consumer* consumer) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| - |
| - scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); |
| - FetchOAuth2TokenWithUsername(request.get(), username, scopes); |
| - return request.PassAs<Request>(); |
| -} |
| - |
| -bool AndroidProfileOAuth2TokenService::RefreshTokenIsAvailable() { |
| - SigninManagerBase* signin_manager = |
| - SigninManagerFactory::GetForProfile(profile()); |
| - return !signin_manager->GetAuthenticatedUsername().empty(); |
| +bool AndroidProfileOAuth2TokenService::RefreshTokenIsAvailable( |
| + const std::string& account_id) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jstring> j_account_id = |
| + ConvertUTF8ToJavaString(env, account_id); |
| + jboolean refresh_token_is_available = |
| + Java_AndroidProfileOAuth2TokenServiceHelper_hasOAuth2RefreshToken( |
| + env, base::android::GetApplicationContext(), |
| + j_account_id.obj()); |
| + return (bool)refresh_token_is_available; |
|
fgorski
2013/08/30 22:29:03
I am not sure what the preferred treatment of the
nyquist
2013/08/31 17:51:10
This is what what you do does behind the scenes no
fgorski
2013/09/03 20:50:40
Done.
|
| } |
| void AndroidProfileOAuth2TokenService::InvalidateToken( |
| @@ -85,32 +79,36 @@ void AndroidProfileOAuth2TokenService::InvalidateToken( |
| j_invalid_token.obj()); |
| } |
| +std::vector<std::string> AndroidProfileOAuth2TokenService::GetAccounts() { |
| + std::vector<std::string> accounts; |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jobjectArray> j_accounts = |
| + Java_AndroidProfileOAuth2TokenServiceHelper_getAccounts( |
| + env, base::android::GetApplicationContext()); |
| + base::android::AppendJavaStringArrayToStringVector(env, |
| + j_accounts.obj(), |
|
Andrew T Wilson (Slow)
2013/09/03 14:04:24
Is the idea that we'll ultimately give the user co
fgorski
2013/09/03 20:50:40
I raised that with Roger in a phone call before I
|
| + &accounts); |
| + return accounts; |
| +} |
| + |
| void AndroidProfileOAuth2TokenService::FetchOAuth2Token( |
| RequestImpl* request, |
| + const std::string& account_id, |
| net::URLRequestContextGetter* getter, |
| const std::string& client_id, |
| const std::string& client_secret, |
| const OAuth2TokenService::ScopeSet& scopes) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| - std::string username = SigninManagerFactory::GetForProfile(profile())-> |
| - GetAuthenticatedUsername(); |
| - DCHECK(!username.empty()); |
| - // Just ignore client_id, getter, etc since we don't use them on Android. |
| - FetchOAuth2TokenWithUsername(request, username, scopes); |
| -} |
| + DCHECK(!account_id.empty()); |
| -void AndroidProfileOAuth2TokenService::FetchOAuth2TokenWithUsername( |
| - RequestImpl* request, |
| - const std::string& username, |
| - const OAuth2TokenService::ScopeSet& scopes) { |
| JNIEnv* env = AttachCurrentThread(); |
| std::string scope = CombineScopes(scopes); |
| ScopedJavaLocalRef<jstring> j_username = |
| - ConvertUTF8ToJavaString(env, username); |
| + ConvertUTF8ToJavaString(env, account_id); |
| ScopedJavaLocalRef<jstring> j_scope = |
| ConvertUTF8ToJavaString(env, scope); |
| - // Allocate a copy of the request WeakPtr on the heap, because the object |
| + // Allocate a copy of the request WeakPtr on the heap, because the object |
|
Andrew T Wilson (Slow)
2013/09/03 14:04:24
nit: indent
fgorski
2013/09/03 20:50:40
Done.
|
| // needs to be passed through JNI as an int. |
| // It will be passed back to OAuth2TokenFetched(), where it will be freed. |
| scoped_ptr<FetchOAuth2TokenCallback> heap_callback( |