0

[ios] Rename the method GetBrowserStateInfoCache

Since BrowserStateInfoCache is renamed ProfileAttributesStorageIOS,
rename the getter GetProfileAttributesStorage(). Leave a deprecated
method with the old name that calls the new one (until all clients
have been converted to the new name).

Bug: 359522668
Change-Id: Icb5d024a838039a4ff9f2d77f654fe5de2205548
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5797041
Reviewed-by: Mark Cogan <marq@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1345317}
This commit is contained in:
Sylvain Defresne
2024-08-22 09:42:04 +00:00
committed by Chromium LUCI CQ
parent 2d68ea086a
commit d0c63d3038
6 changed files with 56 additions and 46 deletions

@ -31,7 +31,7 @@
#import "ios/chrome/browser/push_notification/model/push_notification_profile_service_factory.h"
#import "ios/chrome/browser/segmentation_platform/model/segmentation_platform_service_factory.h"
#import "ios/chrome/browser/shared/model/prefs/pref_names.h"
#import "ios/chrome/browser/shared/model/profile/profile_attributes_storage_ios.h"
#import "ios/chrome/browser/shared/model/profile/profile_attributes_ios.h"
#import "ios/chrome/browser/shared/public/features/system_flags.h"
#import "ios/chrome/browser/signin/model/account_consistency_service_factory.h"
#import "ios/chrome/browser/signin/model/account_reconcilor_factory.h"
@ -153,7 +153,9 @@ void ChromeBrowserStateManagerImpl::BrowserStateInfo::AddCallback(
ChromeBrowserStateManagerImpl::ChromeBrowserStateManagerImpl(
PrefService* local_state,
const base::FilePath& data_dir)
: local_state_(local_state), data_dir_(data_dir) {
: local_state_(local_state),
data_dir_(data_dir),
profile_attributes_storage_(local_state) {
CHECK(local_state_);
CHECK(!data_dir_.empty());
}
@ -320,14 +322,10 @@ ChromeBrowserState* ChromeBrowserStateManagerImpl::CreateBrowserState(
return iter->second.browser_state();
}
BrowserStateInfoCache*
ChromeBrowserStateManagerImpl::GetBrowserStateInfoCache() {
ProfileAttributesStorageIOS*
ChromeBrowserStateManagerImpl::GetProfileAttributesStorage() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!browser_state_info_cache_) {
browser_state_info_cache_ =
std::make_unique<BrowserStateInfoCache>(local_state_.get());
}
return browser_state_info_cache_.get();
return &profile_attributes_storage_;
}
void ChromeBrowserStateManagerImpl::OnChromeBrowserStateCreationStarted(
@ -395,7 +393,7 @@ std::string ChromeBrowserStateManagerImpl::GetLastUsedBrowserStateName() const {
bool ChromeBrowserStateManagerImpl::BrowserStateWithNameExists(
std::string_view name) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return GetBrowserStateInfoCache()->GetIndexOfBrowserStateWithName(name) !=
return profile_attributes_storage_.GetIndexOfBrowserStateWithName(name) !=
std::string::npos;
}
@ -477,22 +475,28 @@ void ChromeBrowserStateManagerImpl::AddBrowserStateToCache(
ChromeBrowserState* browser_state) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!browser_state->IsOffTheRecord());
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForBrowserState(browser_state);
const CoreAccountInfo account_info =
identity_manager->GetPrimaryAccountInfo(signin::ConsentLevel::kSignin);
CoreAccountInfo account_info =
IdentityManagerFactory::GetForBrowserState(browser_state)
->GetPrimaryAccountInfo(signin::ConsentLevel::kSignin);
BrowserStateInfoCache* cache = GetBrowserStateInfoCache();
const size_t browser_state_index = cache->GetIndexOfBrowserStateWithName(
browser_state->GetBrowserStateName());
if (browser_state_index != std::string::npos) {
// The BrowserStateInfoCache's info must match the IdentityManager.
cache->SetAuthInfoOfBrowserStateAtIndex(
browser_state_index, account_info.gaia, account_info.email);
const std::string& profile_name = browser_state->GetBrowserStateName();
const size_t index =
profile_attributes_storage_.GetIndexOfBrowserStateWithName(profile_name);
if (index == std::string::npos) {
profile_attributes_storage_.AddBrowserState(profile_name, account_info.gaia,
account_info.email);
return;
}
cache->AddBrowserState(browser_state->GetBrowserStateName(),
account_info.gaia, account_info.email);
// The ProfileAttributes's info must match the IdentityManager.
profile_attributes_storage_.UpdateAttributesForProfileAtIndex(
index, base::BindOnce(
[](CoreAccountInfo account_info, ProfileAttributesIOS attr) {
attr.SetAuthenticationInfo(account_info.gaia,
account_info.email);
return attr;
},
std::move(account_info)));
}
void ChromeBrowserStateManagerImpl::DoFinalInit(

@ -324,7 +324,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserStates_IncoherentPrefs_3) {
TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserStateAsync) {
// Pretends that a BrowserState named `kProfileName1` exists. Required as
// LoadBrowserStateAsync(...) won't create new BrowserStates.
browser_state_manager().GetBrowserStateInfoCache()->AddBrowserState(
browser_state_manager().GetProfileAttributesStorage()->AddBrowserState(
kProfileName1, /*gaia_id=*/std::string(), /*user_name=*/std::string());
base::RunLoop run_loop;
@ -364,7 +364,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserStateAsync) {
TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserStateAsync_Reload) {
// Pretends that a BrowserState named `kProfileName1` exists. Required as
// LoadBrowserStateAsync(...) won't create new BrowserStates.
browser_state_manager().GetBrowserStateInfoCache()->AddBrowserState(
browser_state_manager().GetProfileAttributesStorage()->AddBrowserState(
kProfileName1, /*gaia_id=*/std::string(), /*user_name=*/std::string());
// Load the BrowserState a first time.
@ -439,7 +439,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserStateAsync_Missing) {
// cause LoadBrowserStateAsync(...) to fail since it does not create new
// BrowserStates.
ASSERT_EQ(browser_state_manager()
.GetBrowserStateInfoCache()
.GetProfileAttributesStorage()
->GetIndexOfBrowserStateWithName(kProfileName1),
std::string::npos);
@ -473,7 +473,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, CreateBrowserStateAsync) {
// Ensures that no BrowserState named `kProfileName1` exists. This will
// cause CreateBrowserStateAsync(...) to create a new ChromeBrowserSatet.
ASSERT_EQ(browser_state_manager()
.GetBrowserStateInfoCache()
.GetProfileAttributesStorage()
->GetIndexOfBrowserStateWithName(kProfileName1),
std::string::npos);
@ -515,7 +515,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, CreateBrowserStateAsync_Reload) {
// Ensures that no BrowserState named `kProfileName1` exists. This will
// cause CreateBrowserStateAsync(...) to create a new ChromeBrowserSatet.
ASSERT_EQ(browser_state_manager()
.GetBrowserStateInfoCache()
.GetProfileAttributesStorage()
->GetIndexOfBrowserStateWithName(kProfileName1),
std::string::npos);
@ -590,7 +590,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, CreateBrowserStateAsync_Reload) {
TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserState) {
// Pretends that a BrowserState named `kProfileName1` exists. Required as
// LoadBrowserState(...) won't create new BrowserStates.
browser_state_manager().GetBrowserStateInfoCache()->AddBrowserState(
browser_state_manager().GetProfileAttributesStorage()->AddBrowserState(
kProfileName1, /*gaia_id=*/std::string(), /*user_name=*/std::string());
// Load the BrowserState synchronously.
@ -612,7 +612,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, LoadBrowserState_Missing) {
// cause LoadBrowserState(...) to fail since it does not create new
// BrowserStates.
ASSERT_EQ(browser_state_manager()
.GetBrowserStateInfoCache()
.GetProfileAttributesStorage()
->GetIndexOfBrowserStateWithName(kProfileName1),
std::string::npos);
@ -630,7 +630,7 @@ TEST_F(ChromeBrowserStateManagerImplTest, CreateBrowserState) {
// Ensures that no BrowserState named `kProfileName1` exists. This will
// cause CreateBrowserStateAsync(...) to create a new ChromeBrowserSatet.
ASSERT_EQ(browser_state_manager()
.GetBrowserStateInfoCache()
.GetProfileAttributesStorage()
->GetIndexOfBrowserStateWithName(kProfileName1),
std::string::npos);

@ -55,7 +55,7 @@ class ChromeBrowserStateManagerImpl : public ChromeBrowserStateManager,
ChromeBrowserStateLoadedCallback created_callback) override;
ChromeBrowserState* LoadBrowserState(std::string_view name) override;
ChromeBrowserState* CreateBrowserState(std::string_view name) override;
BrowserStateInfoCache* GetBrowserStateInfoCache() override;
ProfileAttributesStorageIOS* GetProfileAttributesStorage() override;
// ChromeBrowserState::Delegate:
void OnChromeBrowserStateCreationStarted(
@ -111,8 +111,8 @@ class ChromeBrowserStateManagerImpl : public ChromeBrowserStateManager,
// Holds the ChromeBrowserState instances that this instance has created.
ChromeBrowserMap browser_states_;
// The owned BrowserStateInfoCache instance. Lazily created.
std::unique_ptr<BrowserStateInfoCache> browser_state_info_cache_;
// The owned ProfileAttributesStorageIOS instance.
ProfileAttributesStorageIOS profile_attributes_storage_;
// The list of registered observers.
base::ObserverList<ChromeBrowserStateManagerObserver, true> observers_;

@ -100,8 +100,14 @@ class ProfileManagerIOS {
// tests. Returns null if loading or creating the ChromeBrowserState failed.
virtual ChromeBrowserState* CreateBrowserState(std::string_view name) = 0;
// Returns the BrowserStateInfoCache associated with this manager.
virtual BrowserStateInfoCache* GetBrowserStateInfoCache() = 0;
// Returns the ProfileAttributesStorageIOS associated with this manager.
virtual ProfileAttributesStorageIOS* GetProfileAttributesStorage() = 0;
// Returns the ProfileAttributesStorageIOS associated with this manager.
// DEPRECATED: use GetProfileAttributesStorage() instead.
ProfileAttributesStorageIOS* GetBrowserStateInfoCache() {
return GetProfileAttributesStorage();
}
protected:
ProfileManagerIOS() {}

@ -48,7 +48,7 @@ class TestProfileManagerIOS : public ChromeBrowserStateManager {
ChromeBrowserStateLoadedCallback created_callback) override;
ChromeBrowserState* LoadBrowserState(std::string_view name) override;
ChromeBrowserState* CreateBrowserState(std::string_view name) override;
BrowserStateInfoCache* GetBrowserStateInfoCache() override;
ProfileAttributesStorageIOS* GetProfileAttributesStorage() override;
// Builds and adds a TestChromeBrowserState using `builder`. Asserts that
// no BrowserState share the same name. Returns a pointer to the new object.
@ -56,8 +56,8 @@ class TestProfileManagerIOS : public ChromeBrowserStateManager {
TestChromeBrowserState::Builder builder);
private:
// The BrowserStateInfoCache owned by this instance.
BrowserStateInfoCache browser_state_info_cache_;
// The ProfileAttributesStorageIOS owned by this instance.
ProfileAttributesStorageIOS profile_attributes_storage_;
// The path in which the ChromeBrowserStates are stored.
const base::FilePath data_dir_;

@ -14,7 +14,7 @@
#import "ios/chrome/test/testing_application_context.h"
TestProfileManagerIOS::TestProfileManagerIOS()
: browser_state_info_cache_(GetApplicationContext()->GetLocalState()),
: profile_attributes_storage_(GetApplicationContext()->GetLocalState()),
data_dir_(base::CreateUniqueTempDirectoryScopedToTest()) {
CHECK_EQ(GetApplicationContext()->GetChromeBrowserStateManager(), nullptr);
TestingApplicationContext::GetGlobal()->SetChromeBrowserStateManager(this);
@ -112,9 +112,9 @@ ChromeBrowserState* TestProfileManagerIOS::CreateBrowserState(
return GetBrowserStateByName(name);
}
BrowserStateInfoCache*
TestProfileManagerIOS::GetBrowserStateInfoCache() {
return &browser_state_info_cache_;
ProfileAttributesStorageIOS*
TestProfileManagerIOS::GetProfileAttributesStorage() {
return &profile_attributes_storage_;
}
TestChromeBrowserState*
@ -141,9 +141,9 @@ TestProfileManagerIOS::AddBrowserStateWithBuilder(
last_used_browser_state_name_ = browser_state_name;
}
browser_state_info_cache_.AddBrowserState(browser_state_name,
/*gaia_id=*/std::string(),
/*user_name=*/std::string());
profile_attributes_storage_.AddBrowserState(browser_state_name,
/*gaia_id=*/std::string(),
/*user_name=*/std::string());
for (auto& observer : observers_) {
observer.OnChromeBrowserStateLoaded(this, iterator->second.get());