| 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..db27b961744fe879c457a767d470b7d2dd3724c7 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;
|
| }
|
|
|
| void AndroidProfileOAuth2TokenService::InvalidateToken(
|
| @@ -85,28 +79,33 @@ 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());
|
| + // TODO(fgorski): We may decide to filter out some of the accounts.
|
| + base::android::AppendJavaStringArrayToStringVector(env,
|
| + j_accounts.obj(),
|
| + &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);
|
|
|
|
|