0

[iOS] ChromeAccountManagerService: rename pref_service_ -> local_state_

The name "pref_service" is typically understood to refer to the
*profile* pref service, but ChromeAccountManagerService actually uses
the *local state* pref service.

While we're here, this also adds a CHECK_IS_TEST() to ensure the pref
service can only be null in tests.

Bug: none
Change-Id: I1e290bc810477c25f3c7fce36082ffb51921b068
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5964924
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Jérôme Lebel <jlebel@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1374582}
This commit is contained in:
Marc Treib
2024-10-28 13:29:16 +00:00
committed by Chromium LUCI CQ
parent 26198b17db
commit 62ceef6a5e
2 changed files with 20 additions and 16 deletions

@ -61,7 +61,7 @@ class ChromeAccountManagerService : public KeyedService,
// Initializes the service, getting identities corresponding to `profile_name` // Initializes the service, getting identities corresponding to `profile_name`
// from the AccountProfileMapper. // from the AccountProfileMapper.
ChromeAccountManagerService(PrefService* pref_service, ChromeAccountManagerService(PrefService* local_state,
std::string_view profile_name); std::string_view profile_name);
ChromeAccountManagerService(const ChromeAccountManagerService&) = delete; ChromeAccountManagerService(const ChromeAccountManagerService&) = delete;
ChromeAccountManagerService& operator=(const ChromeAccountManagerService&) = ChromeAccountManagerService& operator=(const ChromeAccountManagerService&) =
@ -116,16 +116,16 @@ class ChromeAccountManagerService : public KeyedService,
id<RefreshAccessTokenError> error) override; id<RefreshAccessTokenError> error) override;
private: private:
// Updates PatternAccountRestriction with the current `pref_service_`. If // Updates PatternAccountRestriction with the current `local_state_`. If
// `pref_service_` is null, no identity will be filtered. // `local_state_` is null, no identity will be filtered.
void UpdateRestriction(); void UpdateRestriction();
// Returns a ResizedAvatarCache based on `avatar_size`. // Returns a ResizedAvatarCache based on `avatar_size`.
ResizedAvatarCache* GetAvatarCacheForIdentityAvatarSize( ResizedAvatarCache* GetAvatarCacheForIdentityAvatarSize(
IdentityAvatarSize avatar_size); IdentityAvatarSize avatar_size);
// Used to retrieve restricted patterns. // The local-state pref service, used to retrieve restricted patterns.
raw_ptr<PrefService> pref_service_ = nullptr; raw_ptr<PrefService> local_state_ = nullptr;
// Used to filter ChromeIdentities. // Used to filter ChromeIdentities.
PatternAccountRestriction restriction_; PatternAccountRestriction restriction_;
// Used to listen pref change. // Used to listen pref change.

@ -7,6 +7,7 @@
#import <string_view> #import <string_view>
#import "base/check.h" #import "base/check.h"
#import "base/check_is_test.h"
#import "base/memory/raw_ref.h" #import "base/memory/raw_ref.h"
#import "base/strings/sys_string_conversions.h" #import "base/strings/sys_string_conversions.h"
#import "components/prefs/pref_service.h" #import "components/prefs/pref_service.h"
@ -166,21 +167,24 @@ typename Collector::ResultType IterateOverIdentities(
// Returns the PatternAccountRestriction according to the given PrefService. // Returns the PatternAccountRestriction according to the given PrefService.
PatternAccountRestriction PatternAccountRestrictionFromPreference( PatternAccountRestriction PatternAccountRestrictionFromPreference(
PrefService* pref_service) { PrefService* local_state) {
return PatternAccountRestrictionFromValue( return PatternAccountRestrictionFromValue(
pref_service->GetList(prefs::kRestrictAccountsToPatterns)); local_state->GetList(prefs::kRestrictAccountsToPatterns));
} }
} // anonymous namespace. } // anonymous namespace.
ChromeAccountManagerService::ChromeAccountManagerService( ChromeAccountManagerService::ChromeAccountManagerService(
PrefService* pref_service, PrefService* local_state,
std::string_view profile_name) std::string_view profile_name)
: pref_service_(pref_service), profile_name_(profile_name) { : local_state_(local_state), profile_name_(profile_name) {
// pref_service is null in test environment. In prod environment pref_service // `local_state_` may be null in a test environment. In the prod environment,
// comes from GetApplicationContext()->GetLocalState() and couldn't be null. // `local_state_` comes from GetApplicationContext()->GetLocalState() and
if (pref_service_) { // couldn't be null.
registrar_.Init(pref_service_); if (!local_state_) {
CHECK_IS_TEST();
} else {
registrar_.Init(local_state_);
registrar_.Add( registrar_.Add(
prefs::kRestrictAccountsToPatterns, prefs::kRestrictAccountsToPatterns,
base::BindRepeating(&ChromeAccountManagerService::UpdateRestriction, base::BindRepeating(&ChromeAccountManagerService::UpdateRestriction,
@ -267,9 +271,9 @@ void ChromeAccountManagerService::Shutdown() {
for (auto& observer : observer_list_) { for (auto& observer : observer_list_) {
observer.OnChromeAccountManagerServiceShutdown(this); observer.OnChromeAccountManagerServiceShutdown(this);
} }
if (pref_service_) { if (local_state_) {
registrar_.RemoveAll(); registrar_.RemoveAll();
pref_service_ = nullptr; local_state_ = nullptr;
} }
} }
@ -309,7 +313,7 @@ void ChromeAccountManagerService::OnIdentityAccessTokenRefreshFailed(
} }
void ChromeAccountManagerService::UpdateRestriction() { void ChromeAccountManagerService::UpdateRestriction() {
restriction_ = PatternAccountRestrictionFromPreference(pref_service_); restriction_ = PatternAccountRestrictionFromPreference(local_state_);
OnIdentityListChanged(); OnIdentityListChanged();
} }