Skip to content

Instantly share code, notes, and snippets.

@uazo
Created July 10, 2022 10:05
Show Gist options
  • Save uazo/aaa68a31ca1d40a1a34e32b36865963c to your computer and use it in GitHub Desktop.
Save uazo/aaa68a31ca1d40a1a34e32b36865963c to your computer and use it in GitHub Desktop.
diff --git a/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.cc b/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.cc
index ef5e58dcf3..ec7ad49b02 100644
--- a/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.cc
+++ b/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.cc
@@ -14,7 +14,6 @@
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
-#include "components/signin/public/android/jni_headers/ProfileOAuth2TokenServiceDelegate_jni.h"
#include "components/signin/public/base/account_consistency_method.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "google_apis/gaia/gaia_auth_util.h"
@@ -91,20 +90,7 @@ AndroidAccessTokenFetcher::~AndroidAccessTokenFetcher() {}
void AndroidAccessTokenFetcher::Start(const std::string& client_id,
const std::string& client_secret,
const std::vector<std::string>& scopes) {
- JNIEnv* env = AttachCurrentThread();
- std::string scope = CombineScopes(scopes);
- ScopedJavaLocalRef<jstring> j_email =
- ConvertUTF8ToJavaString(env, account_id_);
- ScopedJavaLocalRef<jstring> j_scope = ConvertUTF8ToJavaString(env, scope);
- std::unique_ptr<FetchOAuth2TokenCallback> heap_callback(
- new FetchOAuth2TokenCallback(
- base::BindOnce(&AndroidAccessTokenFetcher::OnAccessTokenResponse,
- weak_factory_.GetWeakPtr())));
-
- // Call into Java to get a new token.
- signin::Java_ProfileOAuth2TokenServiceDelegate_getAccessTokenFromNative(
- env, oauth2_token_service_delegate_->GetJavaObject(), j_email, j_scope,
- reinterpret_cast<intptr_t>(heap_callback.release()));
+ CancelRequest();
}
void AndroidAccessTokenFetcher::CancelRequest() {
@@ -153,27 +139,6 @@ ProfileOAuth2TokenServiceDelegateAndroid::
fire_refresh_token_loaded_(RT_LOAD_NOT_START) {
DVLOG(1) << "ProfileOAuth2TokenServiceDelegateAndroid::ctor";
DCHECK(account_tracker_service_);
-
- JNIEnv* env = AttachCurrentThread();
- base::android::ScopedJavaLocalRef<jobject> local_java_ref =
- signin::Java_ProfileOAuth2TokenServiceDelegate_Constructor(
- env, reinterpret_cast<intptr_t>(this),
- account_tracker_service_->GetJavaObject());
- java_ref_.Reset(env, local_java_ref.obj());
-
- if (account_tracker_service_->GetMigrationState() ==
- AccountTrackerService::MIGRATION_IN_PROGRESS) {
- std::vector<CoreAccountId> accounts = GetAccounts();
- std::vector<CoreAccountId> accounts_id;
- for (auto account_name : accounts) {
- std::string email = account_name.ToString();
- AccountInfo account_info =
- account_tracker_service_->FindAccountInfoByEmail(email);
- DCHECK(!account_info.gaia.empty());
- accounts_id.push_back(CoreAccountId::FromGaiaId(account_info.gaia));
- }
- SetAccounts(accounts_id);
- }
}
ProfileOAuth2TokenServiceDelegateAndroid::
@@ -181,30 +146,12 @@ ProfileOAuth2TokenServiceDelegateAndroid::
ScopedJavaLocalRef<jobject>
ProfileOAuth2TokenServiceDelegateAndroid::GetJavaObject() {
- return ScopedJavaLocalRef<jobject>(java_ref_);
+ return nullptr;
}
bool ProfileOAuth2TokenServiceDelegateAndroid::RefreshTokenIsAvailable(
const CoreAccountId& account_id) const {
- DVLOG(1)
- << "ProfileOAuth2TokenServiceDelegateAndroid::RefreshTokenIsAvailable"
- << " account= " << account_id;
- std::string account_name = MapAccountIdToAccountName(account_id);
- if (account_name.empty()) {
- // This corresponds to the case when the account with id |account_id| is not
- // present on the device and thus was not seeded.
- DVLOG(1)
- << "ProfileOAuth2TokenServiceDelegateAndroid::RefreshTokenIsAvailable"
- << " cannot find account name for account id " << account_id;
- return false;
- }
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> j_account_name =
- ConvertUTF8ToJavaString(env, account_name);
- jboolean refresh_token_is_available =
- signin::Java_ProfileOAuth2TokenServiceDelegate_hasOAuth2RefreshToken(
- env, java_ref_, j_account_name);
- return refresh_token_is_available == JNI_TRUE;
+ return false;
}
GoogleServiceAuthError ProfileOAuth2TokenServiceDelegateAndroid::GetAuthError(
@@ -277,26 +224,11 @@ void ProfileOAuth2TokenServiceDelegateAndroid::OnAccessTokenInvalidated(
const std::string& client_id,
const OAuth2AccessTokenManager::ScopeSet& scopes,
const std::string& access_token) {
- ValidateAccountId(account_id);
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> j_access_token =
- ConvertUTF8ToJavaString(env, access_token);
- signin::Java_ProfileOAuth2TokenServiceDelegate_invalidateAccessToken(
- env, java_ref_, j_access_token);
}
void ProfileOAuth2TokenServiceDelegateAndroid::
ReloadAllAccountsFromSystemWithPrimaryAccount(
const absl::optional<CoreAccountId>& primary_account_id) {
- JNIEnv* env = AttachCurrentThread();
-
- ScopedJavaLocalRef<jstring> j_account_id =
- primary_account_id.has_value()
- ? ConvertUTF8ToJavaString(env, primary_account_id->ToString())
- : nullptr;
- signin::
- Java_ProfileOAuth2TokenServiceDelegate_seedAndReloadAccountsWithPrimaryAccount(
- env, java_ref_, j_account_id);
}
void ProfileOAuth2TokenServiceDelegateAndroid::
diff --git a/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h b/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h
index 4fddcb3c27..166b044b65 100644
--- a/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h
+++ b/components/signin/internal/identity_manager/profile_oauth2_token_service_delegate_android.h
@@ -117,8 +117,6 @@ class ProfileOAuth2TokenServiceDelegateAndroid
// Set accounts that have been advertised by OnRefreshTokenAvailable.
virtual void SetAccounts(const std::vector<CoreAccountId>& accounts);
- base::android::ScopedJavaGlobalRef<jobject> java_ref_;
-
// Accounts that have been advertised by OnRefreshTokenAvailable.
std::vector<CoreAccountId> accounts_;
diff --git a/components/signin/public/android/BUILD.gn b/components/signin/public/android/BUILD.gn
index 58f91c0b2e..baad9f2c21 100644
--- a/components/signin/public/android/BUILD.gn
+++ b/components/signin/public/android/BUILD.gn
@@ -67,7 +67,6 @@ generate_jni("jni_headers") {
"java/src/org/chromium/components/signin/identitymanager/IdentityManager.java",
"java/src/org/chromium/components/signin/identitymanager/IdentityMutator.java",
"java/src/org/chromium/components/signin/identitymanager/PrimaryAccountChangeEvent.java",
- "java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java",
]
}
diff --git a/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java b/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java
index 8d0920498e..ee74ef6e49 100644
--- a/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java
+++ b/components/signin/public/android/java/src/org/chromium/components/signin/identitymanager/ProfileOAuth2TokenServiceDelegate.java
@@ -59,7 +59,6 @@ final class ProfileOAuth2TokenServiceDelegate {
private final AccountManagerFacade mAccountManagerFacade;
@VisibleForTesting
- @CalledByNative
ProfileOAuth2TokenServiceDelegate(long nativeProfileOAuth2TokenServiceDelegate,
AccountTrackerService accountTrackerService) {
assert nativeProfileOAuth2TokenServiceDelegate
@@ -78,35 +77,8 @@ final class ProfileOAuth2TokenServiceDelegate {
* completion.
*/
@MainThread
- @CalledByNative
private void getAccessTokenFromNative(
String accountEmail, String scope, final long nativeCallback) {
- assert accountEmail != null : "Account email cannot be null!";
- mAccountManagerFacade.getAccounts().then(accounts -> {
- final Account account = AccountUtils.findAccountByName(accounts, accountEmail);
- if (account == null) {
- ThreadUtils.postOnUiThread(() -> {
- ProfileOAuth2TokenServiceDelegateJni.get().onOAuth2TokenFetched(
- null, AccessTokenData.NO_KNOWN_EXPIRATION_TIME, false, nativeCallback);
- });
- return;
- }
- String oauth2Scope = OAUTH2_SCOPE_PREFIX + scope;
- getAccessToken(account, oauth2Scope, new GetAccessTokenCallback() {
- @Override
- public void onGetTokenSuccess(AccessTokenData token) {
- ProfileOAuth2TokenServiceDelegateJni.get().onOAuth2TokenFetched(
- token.getToken(), token.getExpirationTimeSecs(), false, nativeCallback);
- }
-
- @Override
- public void onGetTokenFailure(boolean isTransientError) {
- ProfileOAuth2TokenServiceDelegateJni.get().onOAuth2TokenFetched(null,
- AccessTokenData.NO_KNOWN_EXPIRATION_TIME, isTransientError,
- nativeCallback);
- }
- });
- });
}
/**
@@ -139,7 +111,6 @@ final class ProfileOAuth2TokenServiceDelegate {
* asynchronously.
*/
@MainThread
- @CalledByNative
void invalidateAccessToken(String accessToken) {
mAccountManagerFacade.invalidateAccessToken(accessToken);
}
@@ -150,7 +121,6 @@ final class ProfileOAuth2TokenServiceDelegate {
* to check whether the account has an OAuth2 refresh token.
*/
@VisibleForTesting
- @CalledByNative
boolean hasOAuth2RefreshToken(String accountName) {
Promise<List<Account>> promise = mAccountManagerFacade.getAccounts();
return promise.isFulfilled()
@@ -158,35 +128,10 @@ final class ProfileOAuth2TokenServiceDelegate {
}
@VisibleForTesting
- @CalledByNative
void seedAndReloadAccountsWithPrimaryAccount(@Nullable String primaryAccountId) {
- ThreadUtils.assertOnUiThread();
- mAccountTrackerService.seedAccountsIfNeeded(() -> {
- final List<Account> accounts = AccountUtils.getAccountsIfFulfilledOrEmpty(
- AccountManagerFacadeProvider.getInstance().getAccounts());
- ProfileOAuth2TokenServiceDelegateJni.get()
- .reloadAllAccountsWithPrimaryAccountAfterSeeding(
- mNativeProfileOAuth2TokenServiceDelegate, primaryAccountId,
- AccountUtils.toAccountNames(accounts).toArray(new String[0]));
- });
}
@NativeMethods
interface Natives {
- /**
- * Called to C++ when fetching of an OAuth2 token is finished.
- * @param authToken The string value of the OAuth2 token.
- * @param expirationTimeSecs The number of seconds after the Unix epoch when the token is
- * scheduled to expire. It is set to 0 if there's no known expiration time.
- * @param isTransientError Indicates if the error is transient (network timeout or
- * * unavailable, etc) or persistent (bad credentials, permission denied, etc).
- * @param nativeCallback the pointer to the native callback that should be run upon
- * completion.
- */
- void onOAuth2TokenFetched(String authToken, long expirationTimeSecs,
- boolean isTransientError, long nativeCallback);
- void reloadAllAccountsWithPrimaryAccountAfterSeeding(
- long nativeProfileOAuth2TokenServiceDelegateAndroid, @Nullable String accountId,
- String[] deviceAccountNames);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment