Commit 8e7a16f3 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Remove explicit conversion from std::string to CoreAccountId.

This CL removes the explicit conversion from (and to) std::string and
CoreAccountId.

Bug: 959157

Change-Id: Ibfc5ca50bf595a089e63ed1462361cbe8a316001
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1926482Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717650}
parent 05ec582a
...@@ -42,5 +42,6 @@ static void JNI_ConsentAuditorBridge_RecordConsent( ...@@ -42,5 +42,6 @@ static void JNI_ConsentAuditorBridge_RecordConsent(
} }
ConsentAuditorFactory::GetForProfile( ConsentAuditorFactory::GetForProfile(
ProfileAndroid::FromProfileAndroid(j_profile)) ProfileAndroid::FromProfileAndroid(j_profile))
->RecordSyncConsent(ConvertJavaStringToUTF8(j_account_id), sync_consent); ->RecordSyncConsent(CoreAccountId(ConvertJavaStringToUTF8(j_account_id)),
sync_consent);
} }
...@@ -33,10 +33,10 @@ jint JNI_SigninInvestigator_Investigate( ...@@ -33,10 +33,10 @@ jint JNI_SigninInvestigator_Investigate(
IdentityManagerFactory::GetForProfile(profile) IdentityManagerFactory::GetForProfile(profile)
->FindExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress( ->FindExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
email); email);
std::string account_id; std::string gaia_id;
if (maybe_account_info.has_value()) if (maybe_account_info.has_value())
account_id = maybe_account_info.value().account_id; gaia_id = maybe_account_info.value().gaia;
return static_cast<int>( return static_cast<int>(
SigninInvestigator(email, account_id, &provider).Investigate()); SigninInvestigator(email, gaia_id, &provider).Investigate());
} }
...@@ -64,7 +64,7 @@ void UserPolicySigninService::ShutdownUserCloudPolicyManager() { ...@@ -64,7 +64,7 @@ void UserPolicySigninService::ShutdownUserCloudPolicyManager() {
void UserPolicySigninService::RegisterForPolicyWithAccountId( void UserPolicySigninService::RegisterForPolicyWithAccountId(
const std::string& username, const std::string& username,
const std::string& account_id, const CoreAccountId& account_id,
PolicyRegistrationCallback callback) { PolicyRegistrationCallback callback) {
// Create a new CloudPolicyClient for fetching the DMToken. // Create a new CloudPolicyClient for fetching the DMToken.
std::unique_ptr<CloudPolicyClient> policy_client = std::unique_ptr<CloudPolicyClient> policy_client =
......
...@@ -51,7 +51,7 @@ class UserPolicySigninService : public UserPolicySigninServiceBase { ...@@ -51,7 +51,7 @@ class UserPolicySigninService : public UserPolicySigninServiceBase {
// |callback| is invoked once we have registered this device to fetch policy, // |callback| is invoked once we have registered this device to fetch policy,
// or once it is determined that |username| is not a managed account. // or once it is determined that |username| is not a managed account.
void RegisterForPolicyWithAccountId(const std::string& username, void RegisterForPolicyWithAccountId(const std::string& username,
const std::string& account_id, const CoreAccountId& account_id,
PolicyRegistrationCallback callback); PolicyRegistrationCallback callback);
// Overridden from UserPolicySigninServiceBase to cancel the pending delayed // Overridden from UserPolicySigninServiceBase to cancel the pending delayed
...@@ -59,11 +59,6 @@ class UserPolicySigninService : public UserPolicySigninServiceBase { ...@@ -59,11 +59,6 @@ class UserPolicySigninService : public UserPolicySigninServiceBase {
void ShutdownUserCloudPolicyManager() override; void ShutdownUserCloudPolicyManager() override;
private: private:
void RegisterForPolicyInternal(const std::string& username,
const std::string& account_id,
const std::string& access_token,
PolicyRegistrationCallback callback);
void CallPolicyRegistrationCallback(std::unique_ptr<CloudPolicyClient> client, void CallPolicyRegistrationCallback(std::unique_ptr<CloudPolicyClient> client,
PolicyRegistrationCallback callback); PolicyRegistrationCallback callback);
......
...@@ -165,7 +165,7 @@ OAuth2TokenServiceDelegateAndroid::OAuth2TokenServiceDelegateAndroid( ...@@ -165,7 +165,7 @@ OAuth2TokenServiceDelegateAndroid::OAuth2TokenServiceDelegateAndroid(
AccountInfo account_info = AccountInfo account_info =
account_tracker_service_->FindAccountInfoByEmail(account_name.id); account_tracker_service_->FindAccountInfoByEmail(account_name.id);
DCHECK(!account_info.gaia.empty()); DCHECK(!account_info.gaia.empty());
accounts_id.push_back(account_info.gaia); accounts_id.push_back(CoreAccountId(account_info.gaia));
} }
SetAccounts(accounts_id); SetAccounts(accounts_id);
} }
...@@ -283,9 +283,8 @@ OAuth2TokenServiceDelegateAndroid::GetValidAccounts() { ...@@ -283,9 +283,8 @@ OAuth2TokenServiceDelegateAndroid::GetValidAccounts() {
void OAuth2TokenServiceDelegateAndroid::SetAccounts( void OAuth2TokenServiceDelegateAndroid::SetAccounts(
const std::vector<CoreAccountId>& accounts) { const std::vector<CoreAccountId>& accounts) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
std::vector<std::string> str_ids(accounts.begin(), accounts.end());
ScopedJavaLocalRef<jobjectArray> java_accounts( ScopedJavaLocalRef<jobjectArray> java_accounts(
base::android::ToJavaArrayOfStrings(env, str_ids)); base::android::ToJavaArrayOfStrings(env, ToStringList(accounts)));
signin::Java_OAuth2TokenService_setAccounts(env, java_accounts); signin::Java_OAuth2TokenService_setAccounts(env, java_accounts);
} }
......
...@@ -98,7 +98,7 @@ TEST_F(OAuth2TokenServiceDelegateAndroidTest, ...@@ -98,7 +98,7 @@ TEST_F(OAuth2TokenServiceDelegateAndroidTest,
UpdateAccountListWith0SystemAccount0AccountAndNotSignedIn) { UpdateAccountListWith0SystemAccount0AccountAndNotSignedIn) {
EXPECT_CALL(*delegate_, SetAccounts(kEmptyVector)).WillOnce(Return()); EXPECT_CALL(*delegate_, SetAccounts(kEmptyVector)).WillOnce(Return());
// No observer call expected // No observer call expected
delegate_->UpdateAccountList(std::string(), {}, {}); delegate_->UpdateAccountList(CoreAccountId(), {}, {});
EXPECT_TRUE(account_tracker_service_.GetAccounts().empty()); EXPECT_TRUE(account_tracker_service_.GetAccounts().empty());
} }
...@@ -106,7 +106,7 @@ TEST_F(OAuth2TokenServiceDelegateAndroidTest, ...@@ -106,7 +106,7 @@ TEST_F(OAuth2TokenServiceDelegateAndroidTest,
UpdateAccountListWith1SystemAccount0AccountAndNotSignedIn) { UpdateAccountListWith1SystemAccount0AccountAndNotSignedIn) {
EXPECT_CALL(*delegate_, SetAccounts(kEmptyVector)).WillOnce(Return()); EXPECT_CALL(*delegate_, SetAccounts(kEmptyVector)).WillOnce(Return());
// No observer call expected // No observer call expected
delegate_->UpdateAccountList(std::string(), {}, {account1_.account_id}); delegate_->UpdateAccountList(CoreAccountId(), {}, {account1_.account_id});
EXPECT_EQ(std::vector<AccountInfo>{account1_}, EXPECT_EQ(std::vector<AccountInfo>{account1_},
account_tracker_service_.GetAccounts()); account_tracker_service_.GetAccounts());
} }
...@@ -122,7 +122,7 @@ TEST_F(OAuth2TokenServiceDelegateAndroidTest, ...@@ -122,7 +122,7 @@ TEST_F(OAuth2TokenServiceDelegateAndroidTest,
.InSequence(seq) .InSequence(seq)
.WillOnce(Return()); .WillOnce(Return());
delegate_->UpdateAccountList(std::string(), {account1_.account_id}, delegate_->UpdateAccountList(CoreAccountId(), {account1_.account_id},
{account1_.account_id}); {account1_.account_id});
EXPECT_EQ(std::vector<AccountInfo>{account1_}, EXPECT_EQ(std::vector<AccountInfo>{account1_},
account_tracker_service_.GetAccounts()); account_tracker_service_.GetAccounts());
......
...@@ -2318,7 +2318,7 @@ TEST_F(IdentityManagerTest, ForceRefreshOfExtendedAccountInfo) { ...@@ -2318,7 +2318,7 @@ TEST_F(IdentityManagerTest, ForceRefreshOfExtendedAccountInfo) {
SimulateSuccessfulFetchOfAccountInfo( SimulateSuccessfulFetchOfAccountInfo(
identity_manager(), account_info.account_id, account_info.email, identity_manager(), account_info.account_id, account_info.email,
account_info.account_id, kTestHostedDomain, kTestFullName, kTestGivenName, account_info.gaia, kTestHostedDomain, kTestFullName, kTestGivenName,
kTestLocale, kTestPictureUrl); kTestLocale, kTestPictureUrl);
const AccountInfo& refreshed_account_info = const AccountInfo& refreshed_account_info =
......
...@@ -52,8 +52,7 @@ void JniIdentityMutator::ReloadAllAccountsFromSystemWithPrimaryAccount( ...@@ -52,8 +52,7 @@ void JniIdentityMutator::ReloadAllAccountsFromSystemWithPrimaryAccount(
DCHECK(device_accounts_synchronizer); DCHECK(device_accounts_synchronizer);
base::Optional<CoreAccountId> primary_account_id; base::Optional<CoreAccountId> primary_account_id;
if (j_primary_account_id) { if (j_primary_account_id) {
primary_account_id = CoreAccountId(); primary_account_id =
primary_account_id->id =
ConvertFromJavaCoreAccountId(env, j_primary_account_id); ConvertFromJavaCoreAccountId(env, j_primary_account_id);
} }
device_accounts_synchronizer->ReloadAllAccountsFromSystemWithPrimaryAccount( device_accounts_synchronizer->ReloadAllAccountsFromSystemWithPrimaryAccount(
......
...@@ -22,12 +22,6 @@ CoreAccountId::CoreAccountId(std::string&& id) : id(std::move(id)) {} ...@@ -22,12 +22,6 @@ CoreAccountId::CoreAccountId(std::string&& id) : id(std::move(id)) {}
CoreAccountId::CoreAccountId(const std::string& id) : id(id) {} CoreAccountId::CoreAccountId(const std::string& id) : id(id) {}
#if defined(OS_ANDROID)
CoreAccountId::operator std::string() const {
return id;
}
#endif
bool CoreAccountId::empty() const { bool CoreAccountId::empty() const {
return id.empty(); return id.empty();
} }
......
...@@ -24,19 +24,9 @@ struct CoreAccountId { ...@@ -24,19 +24,9 @@ struct CoreAccountId {
CoreAccountId& operator=(const CoreAccountId&); CoreAccountId& operator=(const CoreAccountId&);
CoreAccountId& operator=(CoreAccountId&&) noexcept; CoreAccountId& operator=(CoreAccountId&&) noexcept;
#if defined(OS_ANDROID)
// Those implicit constructor and conversion operator allow to
// progressively migrate the code to use this struct. Removing
// them is tracked by https://crbug.com/959161
CoreAccountId(const char* id);
CoreAccountId(std::string&& id);
CoreAccountId(const std::string& id);
operator std::string() const;
#else
explicit CoreAccountId(const char* id); explicit CoreAccountId(const char* id);
explicit CoreAccountId(std::string&& id); explicit CoreAccountId(std::string&& id);
explicit CoreAccountId(const std::string& id); explicit CoreAccountId(const std::string& id);
#endif
// Checks if the account is valid or not. // Checks if the account is valid or not.
// TODO(triploblastic): Possibly rename of remove this after // TODO(triploblastic): Possibly rename of remove this after
......
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