Commit 05b6c937 authored by Pâris MEULEMAN's avatar Pâris MEULEMAN Committed by Commit Bot

Move CoreAccountInfo retrieval to SigninManager.java

Move retrieval of CoreAccountInfo by account name (email), from
signin_manager_android.cc to SigninManager.java. This adds a mutable
member to SigninManager's SignInState, which will hold the
CoreAccountInfo when available, i.e. as soon as the account seeding is
complete.

This follows the creation of IdentityManager.java,
PrimaryAccountMutator.java and is a step towards migrating all
SigninManager.java accesses to IdentityManager through the java classes
directly.

A follow up CL will remove the remaining accesses by
signin_manager_android, this includes move
LegacyReloadAccountsFromSystem to IdentityManager.java.

Bug: 934688
Change-Id: Iad797a835febb1a6bbb290cabf44e2e9125989b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789230
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Auto-Submit: Pâris Meuleman <pmeuleman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695975}
parent 53fe330f
...@@ -131,6 +131,12 @@ public class SigninManager ...@@ -131,6 +131,12 @@ public class SigninManager
*/ */
boolean mBlockedOnAccountSeeding; boolean mBlockedOnAccountSeeding;
/**
* Contains the full Core account info, which can be retrieved only once account seeding is
* complete
*/
CoreAccountInfo mCoreAccountInfo;
/** /**
* @param account The account to sign in to. * @param account The account to sign in to.
* @param activity Reference to the UI to use for dialogs. Null means forced signin. * @param activity Reference to the UI to use for dialogs. Null means forced signin.
...@@ -465,6 +471,14 @@ public class SigninManager ...@@ -465,6 +471,14 @@ public class SigninManager
Log.w(TAG, "Ignoring sign in progress request as no pending sign in."); Log.w(TAG, "Ignoring sign in progress request as no pending sign in.");
return; return;
} }
// TODO(crbug.com/1002056) When changing SignIn signature to use CoreAccountInfo, change the
// following line to use it instead of retrieving from IdentityManager.
mSignInState.mCoreAccountInfo =
mIdentityManager.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
mSignInState.mAccount.name);
// CoreAccountInfo must be set and valid to progress
assert mSignInState.mCoreAccountInfo != null;
if (mSignInState.isActivityInvisible()) { if (mSignInState.isActivityInvisible()) {
abortSignIn(); abortSignIn();
...@@ -472,7 +486,7 @@ public class SigninManager ...@@ -472,7 +486,7 @@ public class SigninManager
} }
Log.d(TAG, "Checking if account has policy management enabled"); Log.d(TAG, "Checking if account has policy management enabled");
fetchAndApplyCloudPolicy(mSignInState.mAccount.name, this::onPolicyFetchedBeforeSignIn); fetchAndApplyCloudPolicy(mSignInState.mCoreAccountInfo, this::onPolicyFetchedBeforeSignIn);
} }
@VisibleForTesting @VisibleForTesting
...@@ -486,15 +500,9 @@ public class SigninManager ...@@ -486,15 +500,9 @@ public class SigninManager
private void finishSignIn() { private void finishSignIn() {
// This method should be called at most once per sign-in flow. // This method should be called at most once per sign-in flow.
assert mSignInState != null; assert mSignInState != null && mSignInState.mCoreAccountInfo != null;
// TODO(crbug.com/1002056) When changing SignIn signature to use CoreAccountInfo, change the if (!mPrimaryAccountMutator.setPrimaryAccount(mSignInState.mCoreAccountInfo.getId())) {
// following line to use it instead of retrieving from IdentityManager.
if (!mPrimaryAccountMutator.setPrimaryAccount(
mIdentityManager
.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
mSignInState.mAccount.name)
.getId())) {
Log.w(TAG, "Failed to set the PrimaryAccount in IdentityManager, aborting signin"); Log.w(TAG, "Failed to set the PrimaryAccount in IdentityManager, aborting signin");
abortSignIn(); abortSignIn();
return; return;
...@@ -502,8 +510,9 @@ public class SigninManager ...@@ -502,8 +510,9 @@ public class SigninManager
// Cache the signed-in account name. This must be done after the native call, otherwise // Cache the signed-in account name. This must be done after the native call, otherwise
// sync tries to start without being signed in natively and crashes. // sync tries to start without being signed in natively and crashes.
ChromeSigninController.get().setSignedInAccountName(mSignInState.mAccount.name); ChromeSigninController.get().setSignedInAccountName(
enableSync(mSignInState.mAccount); mSignInState.mCoreAccountInfo.getName());
enableSync(mSignInState.mCoreAccountInfo.getAccount());
if (mSignInState.mCallback != null) { if (mSignInState.mCallback != null) {
mSignInState.mCallback.onSignInComplete(); mSignInState.mCallback.onSignInComplete();
...@@ -731,8 +740,14 @@ public class SigninManager ...@@ -731,8 +740,14 @@ public class SigninManager
* @param callback The callback that will receive true if the account is managed, false * @param callback The callback that will receive true if the account is managed, false
* otherwise. * otherwise.
*/ */
// TODO(crbug.com/1002408) Update API to use CoreAccountInfo instead of email
public void isAccountManaged(String email, final Callback<Boolean> callback) { public void isAccountManaged(String email, final Callback<Boolean> callback) {
SigninManagerJni.get().isAccountManaged(mNativeSigninManagerAndroid, email, callback); assert email != null;
CoreAccountInfo account =
mIdentityManager.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
email);
assert account != null;
SigninManagerJni.get().isAccountManaged(mNativeSigninManagerAndroid, account, callback);
} }
public static String extractDomainName(String email) { public static String extractDomainName(String email) {
...@@ -750,9 +765,9 @@ public class SigninManager ...@@ -750,9 +765,9 @@ public class SigninManager
return !ExternalAuthUtils.getInstance().isGooglePlayServicesMissing(context); return !ExternalAuthUtils.getInstance().isGooglePlayServicesMissing(context);
} }
private void fetchAndApplyCloudPolicy(String username, final Runnable callback) { private void fetchAndApplyCloudPolicy(CoreAccountInfo account, final Runnable callback) {
SigninManagerJni.get().fetchAndApplyCloudPolicy( SigninManagerJni.get().fetchAndApplyCloudPolicy(
mNativeSigninManagerAndroid, username, callback); mNativeSigninManagerAndroid, account, callback);
} }
private void stopApplyingCloudPolicy() { private void stopApplyingCloudPolicy() {
...@@ -793,12 +808,12 @@ public class SigninManager ...@@ -793,12 +808,12 @@ public class SigninManager
boolean isMobileIdentityConsistencyEnabled(); boolean isMobileIdentityConsistencyEnabled();
void fetchAndApplyCloudPolicy( void fetchAndApplyCloudPolicy(
long nativeSigninManagerAndroid, String username, Runnable callback); long nativeSigninManagerAndroid, CoreAccountInfo account, Runnable callback);
void stopApplyingCloudPolicy(long nativeSigninManagerAndroid); void stopApplyingCloudPolicy(long nativeSigninManagerAndroid);
void isAccountManaged( void isAccountManaged(long nativeSigninManagerAndroid, CoreAccountInfo account,
long nativeSigninManagerAndroid, String username, Callback<Boolean> callback); Callback<Boolean> callback);
String getManagementDomain(long nativeSigninManagerAndroid); String getManagementDomain(long nativeSigninManagerAndroid);
......
...@@ -218,21 +218,9 @@ void SigninManagerAndroid::RegisterPolicyWithAccount( ...@@ -218,21 +218,9 @@ void SigninManagerAndroid::RegisterPolicyWithAccount(
void SigninManagerAndroid::FetchAndApplyCloudPolicy( void SigninManagerAndroid::FetchAndApplyCloudPolicy(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& j_username, const base::android::JavaParamRef<jobject>& j_account_info,
const base::android::JavaParamRef<jobject>& j_callback) { const base::android::JavaParamRef<jobject>& j_callback) {
std::string username = CoreAccountInfo account = ConvertFromJavaCoreAccountInfo(env, j_account_info);
base::android::ConvertJavaStringToUTF8(env, j_username);
DCHECK(!username.empty());
// TODO(bsazonov): Remove after migrating the sign-in flow to CoreAccountId.
// ExtractDomainName Dchecks that username is a valid email, in practice
// this checks that @ is present and is not the last character.
gaia::ExtractDomainName(username);
CoreAccountInfo account =
identity_manager_
->FindExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
username)
.value();
auto callback = auto callback =
base::BindOnce(base::android::RunRunnableAndroid, base::BindOnce(base::android::RunRunnableAndroid,
base::android::ScopedJavaGlobalRef<jobject>(j_callback)); base::android::ScopedJavaGlobalRef<jobject>(j_callback));
...@@ -274,19 +262,13 @@ void SigninManagerAndroid::FetchPolicyBeforeSignIn( ...@@ -274,19 +262,13 @@ void SigninManagerAndroid::FetchPolicyBeforeSignIn(
void SigninManagerAndroid::IsAccountManaged( void SigninManagerAndroid::IsAccountManaged(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jstring>& j_username, const JavaParamRef<jobject>& j_account_info,
const JavaParamRef<jobject>& j_callback) { const JavaParamRef<jobject>& j_callback) {
CoreAccountInfo account = ConvertFromJavaCoreAccountInfo(env, j_account_info);
base::android::ScopedJavaGlobalRef<jobject> callback(env, j_callback); base::android::ScopedJavaGlobalRef<jobject> callback(env, j_callback);
std::string username =
base::android::ConvertJavaStringToUTF8(env, j_username);
base::Optional<CoreAccountInfo> account =
identity_manager_
->FindExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
username);
RegisterPolicyWithAccount( RegisterPolicyWithAccount(
account.value_or(CoreAccountInfo{}), account,
base::BindOnce( base::BindOnce(
[](base::android::ScopedJavaGlobalRef<jobject> callback, [](base::android::ScopedJavaGlobalRef<jobject> callback,
const base::Optional<ManagementCredentials>& credentials) { const base::Optional<ManagementCredentials>& credentials) {
......
...@@ -57,14 +57,15 @@ class SigninManagerAndroid : public KeyedService { ...@@ -57,14 +57,15 @@ class SigninManagerAndroid : public KeyedService {
// the policy if necessary. // the policy if necessary.
void FetchAndApplyCloudPolicy( void FetchAndApplyCloudPolicy(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jstring>& username, const base::android::JavaParamRef<jobject>& j_account_info,
const base::android::JavaParamRef<jobject>& j_callback); const base::android::JavaParamRef<jobject>& j_callback);
void StopApplyingCloudPolicy(JNIEnv* env); void StopApplyingCloudPolicy(JNIEnv* env);
void IsAccountManaged(JNIEnv* env, void IsAccountManaged(
const base::android::JavaParamRef<jstring>& j_username, JNIEnv* env,
const base::android::JavaParamRef<jobject>& j_callback); const base::android::JavaParamRef<jobject>& j_account_info,
const base::android::JavaParamRef<jobject>& j_callback);
base::android::ScopedJavaLocalRef<jstring> GetManagementDomain(JNIEnv* env); base::android::ScopedJavaLocalRef<jstring> GetManagementDomain(JNIEnv* env);
......
...@@ -144,9 +144,22 @@ base::android::ScopedJavaLocalRef<jobject> ConvertToJavaCoreAccountId( ...@@ -144,9 +144,22 @@ base::android::ScopedJavaLocalRef<jobject> ConvertToJavaCoreAccountId(
env, base::android::ConvertUTF8ToJavaString(env, account_id.id)); env, base::android::ConvertUTF8ToJavaString(env, account_id.id));
} }
CoreAccountInfo ConvertFromJavaCoreAccountInfo(
JNIEnv* env,
const base::android::JavaRef<jobject>& j_core_account_info) {
CoreAccountInfo account;
account.account_id = ConvertFromJavaCoreAccountId(
env, signin::Java_CoreAccountInfo_getId(env, j_core_account_info));
account.gaia = base::android::ConvertJavaStringToUTF8(
signin::Java_CoreAccountInfo_getGaiaId(env, j_core_account_info));
account.email = base::android::ConvertJavaStringToUTF8(
signin::Java_CoreAccountInfo_getName(env, j_core_account_info));
return account;
}
CoreAccountId ConvertFromJavaCoreAccountId( CoreAccountId ConvertFromJavaCoreAccountId(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& j_core_account_id) { const base::android::JavaRef<jobject>& j_core_account_id) {
CoreAccountId id; CoreAccountId id;
id.id = base::android::ConvertJavaStringToUTF8( id.id = base::android::ConvertJavaStringToUTF8(
signin::Java_CoreAccountId_getId(env, j_core_account_id)); signin::Java_CoreAccountId_getId(env, j_core_account_id));
......
...@@ -90,10 +90,15 @@ base::android::ScopedJavaLocalRef<jobject> ConvertToJavaCoreAccountId( ...@@ -90,10 +90,15 @@ base::android::ScopedJavaLocalRef<jobject> ConvertToJavaCoreAccountId(
JNIEnv* env, JNIEnv* env,
const CoreAccountId& account_id); const CoreAccountId& account_id);
// Constructs a C++ CoreAccountId from the provided java CoreAccountId // Constructs a C++ CoreAccountInfo from the provided Java CoreAccountInfo
CoreAccountInfo ConvertFromJavaCoreAccountInfo(
JNIEnv* env,
const base::android::JavaRef<jobject>& j_core_account_info);
// Constructs a C++ CoreAccountId from the provided Java CoreAccountId
CoreAccountId ConvertFromJavaCoreAccountId( CoreAccountId ConvertFromJavaCoreAccountId(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& j_core_account_id); const base::android::JavaRef<jobject>& j_core_account_id);
#endif #endif
#endif // COMPONENTS_SIGNIN_PUBLIC_IDENTITY_MANAGER_ACCOUNT_INFO_H_ #endif // COMPONENTS_SIGNIN_PUBLIC_IDENTITY_MANAGER_ACCOUNT_INFO_H_
...@@ -62,6 +62,7 @@ public class CoreAccountInfo { ...@@ -62,6 +62,7 @@ public class CoreAccountInfo {
/** /**
* Returns a unique identifier of the current account. * Returns a unique identifier of the current account.
*/ */
@CalledByNative
public CoreAccountId getId() { public CoreAccountId getId() {
return mId; return mId;
} }
...@@ -69,6 +70,7 @@ public class CoreAccountInfo { ...@@ -69,6 +70,7 @@ public class CoreAccountInfo {
/** /**
* Returns a name of the current account. * Returns a name of the current account.
*/ */
@CalledByNative
public String getName() { public String getName() {
return mAccount.name; return mAccount.name;
} }
...@@ -76,6 +78,7 @@ public class CoreAccountInfo { ...@@ -76,6 +78,7 @@ public class CoreAccountInfo {
/** /**
* Returns the string representation of the Gaia ID * Returns the string representation of the Gaia ID
*/ */
@CalledByNative
public String getGaiaId() { public String getGaiaId() {
return mGaiaId; return mGaiaId;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment