0

[iOS] Use ChromeCoordinator's profile property.

Simplify code by using `self.profile` where appropriate.
Some uses with a local `profile = self.profile` are not
updated to optimize for better readability.

Created with git cl split.

This CL was uploaded by git cl split.

R=justincohen@chromium.org

Bug: 401523912
Change-Id: If94c70b242b317fb2d018283eb2baa7d35f14e39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6368494
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1435489}
This commit is contained in:
Stepan Khapugin 2025-03-20 09:33:21 -07:00 committed by Chromium LUCI CQ
parent cef0e70a83
commit e54d0eaa6f
4 changed files with 21 additions and 24 deletions
ios/chrome/browser

@ -31,7 +31,7 @@
- (void)start {
if (!self.findBarController) {
self.findBarController = [[FindBarControllerIOS alloc]
initWithIncognito:self.browser->GetProfile()->IsOffTheRecord()];
initWithIncognito:self.profile->IsOffTheRecord()];
self.findBarController.commandHandler = self.findInPageCommandHandler;
}
@ -91,7 +91,7 @@
}
auto* helper = GetConcreteFindTabHelperFromWebState(self.currentWebState);
DCHECK(helper && helper->IsFindUIActive());
if (!self.browser->GetProfile()->IsOffTheRecord()) {
if (!self.profile->IsOffTheRecord()) {
helper->RestoreSearchTerm();
}
[self.presentationDelegate setHeadersForFindBarCoordinator:self];

@ -74,14 +74,14 @@ const CGFloat kManagementContextMenuIconSize = 18;
return YES;
}
PrefService* prefService =
ProfileIOS::FromBrowserState(self.browser->GetProfile())->GetPrefs();
ProfileIOS::FromBrowserState(self.profile)->GetPrefs();
return prefService->GetBoolean(feed::prefs::kArticlesListVisible);
}
// True if the user is signed in.
- (bool)isSignedIn {
AuthenticationService* authService =
AuthenticationServiceFactory::GetForProfile(self.browser->GetProfile());
AuthenticationServiceFactory::GetForProfile(self.profile);
return authService->HasPrimaryIdentity(signin::ConsentLevel::kSignin);
}

@ -322,7 +322,7 @@
[sceneState addObserver:self];
// Configures incognito NTP if user is in incognito mode.
if (self.browser->GetProfile()->IsOffTheRecord()) {
if (self.profile->IsOffTheRecord()) {
DCHECK(!self.incognitoViewController);
UrlLoadingBrowserAgent* URLLoader =
UrlLoadingBrowserAgent::FromBrowser(self.browser);
@ -355,7 +355,7 @@
// Update the feed if the account is subject to parental controls.
signin::IdentityManager* identityManager =
IdentityManagerFactory::GetForProfile(self.browser->GetProfile());
IdentityManagerFactory::GetForProfile(self.profile);
signin::Tribool capability =
supervised_user::IsPrimaryAccountSubjectToParentalControls(
identityManager);
@ -386,7 +386,7 @@
SceneState* sceneState = self.browser->GetSceneState();
[sceneState removeObserver:self];
if (self.browser->GetProfile()->IsOffTheRecord()) {
if (self.profile->IsOffTheRecord()) {
self.incognitoViewController = nil;
self.started = NO;
return;
@ -504,7 +504,7 @@
}
- (void)reload {
if (self.browser->GetProfile()->IsOffTheRecord()) {
if (self.profile->IsOffTheRecord()) {
return;
}
[self.contentSuggestionsCoordinator refresh];
@ -529,7 +529,7 @@
}
- (void)constrainNamedGuideForFeedIPH {
if (self.browser->GetProfile()->IsOffTheRecord()) {
if (self.profile->IsOffTheRecord()) {
return;
}
UIView* viewToConstrain =
@ -577,7 +577,7 @@
}
- (BOOL)isFakeboxPinned {
if (self.browser->GetProfile()->IsOffTheRecord()) {
if (self.profile->IsOffTheRecord()) {
return YES;
}
return self.NTPViewController.isFakeboxPinned;
@ -617,7 +617,7 @@
// Gets all NTP services from the profile.
- (void)initializeServices {
ProfileIOS* profile = self.browser->GetProfile();
ProfileIOS* profile = self.profile;
self.authService = AuthenticationServiceFactory::GetForProfile(profile);
self.templateURLService =
ios::TemplateURLServiceFactory::GetForProfile(profile);
@ -638,7 +638,7 @@
// Start observing IdentityManager.
signin::IdentityManager* identityManager =
IdentityManagerFactory::GetForProfile(self.browser->GetProfile());
IdentityManagerFactory::GetForProfile(self.profile);
_identityObserverBridge =
std::make_unique<signin::IdentityManagerObserverBridge>(identityManager,
self);
@ -863,7 +863,7 @@
- (UIViewController*)viewController {
DCHECK(self.started);
if (self.browser->GetProfile()->IsOffTheRecord()) {
if (self.profile->IsOffTheRecord()) {
return self.incognitoViewController;
} else {
return self.containerViewController;
@ -1585,13 +1585,12 @@
#pragma mark - Private
- (bool)hasIdentitiesOnDevice {
ProfileIOS* profile = self.browser->GetProfile();
if (IsUseAccountListFromIdentityManagerEnabled()) {
return !IdentityManagerFactory::GetForProfile(profile)
return !IdentityManagerFactory::GetForProfile(self.profile)
->GetAccountsOnDevice()
.empty();
} else {
return ChromeAccountManagerServiceFactory::GetForProfile(profile)
return ChromeAccountManagerServiceFactory::GetForProfile(self.profile)
->HasIdentities();
}
}
@ -1628,7 +1627,7 @@
- (void)updateStartForVisibilityChange:(BOOL)visible {
if (visible && NewTabPageTabHelper::FromWebState(self.webState)
->ShouldShowStartSurface()) {
DiscoverFeedServiceFactory::GetForProfile(self.browser->GetProfile())
DiscoverFeedServiceFactory::GetForProfile(self.profile)
->SetIsShownOnStartSurface(true);
}
if (!visible && NewTabPageTabHelper::FromWebState(self.webState)
@ -1762,7 +1761,7 @@
self.visible = visible;
self.NTPViewController.NTPVisible = visible;
if (!self.browser->GetProfile()->IsOffTheRecord()) {
if (!self.profile->IsOffTheRecord()) {
if (visible) {
self.didAppearTime = base::TimeTicks::Now();
@ -1826,7 +1825,7 @@
// Returns whether the user policies allow them to sync.
- (BOOL)isSyncAllowedByPolicy {
return !SyncServiceFactory::GetForProfile(self.browser->GetProfile())
return !SyncServiceFactory::GetForProfile(self.profile)
->HasDisableReason(
syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY);
}
@ -1861,7 +1860,7 @@
_customizationCoordinator.delegate = self;
[_customizationCoordinator start];
[_customizationCoordinator presentCustomizationMenuPage:page];
feature_engagement::TrackerFactory::GetForProfile(self.browser->GetProfile())
feature_engagement::TrackerFactory::GetForProfile(self.profile)
->NotifyEvent(feature_engagement::events::kHomeCustomizationMenuUsed);
}

@ -37,9 +37,8 @@
- (void)start {
_fullscreenController = FullscreenController::FromBrowser(self.browser);
ProfileIOS* profile = self.browser->GetProfile();
feature_engagement::Tracker* engagementTracker =
feature_engagement::TrackerFactory::GetForProfile(profile);
feature_engagement::TrackerFactory::GetForProfile(self.profile);
_sideSwipeMediator = [[SideSwipeMediator alloc]
initWithWebStateList:self.browser->GetWebStateList()];
_sideSwipeMediator.engagementTracker = engagementTracker;
@ -169,8 +168,7 @@
// Checks if the user is navigating back to the Lens Overlay.
- (BOOL)navigatingBackToLensOverlay {
if (!IsLensOverlaySameTabNavigationEnabled(
self.browser->GetProfile()->GetPrefs()) ||
if (!IsLensOverlaySameTabNavigationEnabled(self.profile->GetPrefs()) ||
IsCompactHeight(self.baseViewController)) {
return NO;
}