Commit 480a9b96 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Reparent mainBrowserState to AppState.

Moves the ownership of the main browser state to the app state.

Bug: 1045659
Change-Id: I37eea450d29d12c5fa31cdbf4a447667dc039a12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414310
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809049}
parent 999679f4
......@@ -12,6 +12,7 @@
@class AppState;
@protocol BrowserLauncher;
class ChromeBrowserState;
@class CommandDispatcher;
@protocol ConnectionInformation;
@class SceneState;
......@@ -54,6 +55,9 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
// Most features should use the browser-level dispatcher instead.
@property(nonatomic, strong) CommandDispatcher* appCommandDispatcher;
// The ChromeBrowserState associated with the main (non-OTR) browsing mode.
@property(nonatomic, assign) ChromeBrowserState* mainBrowserState;
// YES if the user has ever interacted with the application. May be NO if the
// application has been woken up by the system for background work.
@property(nonatomic, readonly) BOOL userInteracted;
......
......@@ -260,9 +260,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
StartupTasks* _startupTasks;
}
// The ChromeBrowserState associated with the main (non-OTR) browsing mode.
@property(nonatomic, assign) ChromeBrowserState* mainBrowserState; // Weak.
// Handles collecting metrics on user triggered screenshots
@property(nonatomic, strong)
ScreenshotMetricsRecorder* screenshotMetricsRecorder;
......@@ -489,7 +486,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Initialize and set the main browser state.
[self initializeBrowserState:chromeBrowserState];
self.mainBrowserState = chromeBrowserState;
self.appState.mainBrowserState = chromeBrowserState;
if (base::FeatureList::IsEnabled(kLogBreadcrumbs)) {
[self startLoggingBreadcrumbs];
......@@ -499,26 +496,28 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// be done before creation of the UI to ensure the service is initialised
// before use (it is a security issue, so accessing the service CHECK if
// this is not the case).
DCHECK(self.mainBrowserState);
DCHECK(self.appState.mainBrowserState);
AuthenticationServiceFactory::CreateAndInitializeForBrowserState(
self.mainBrowserState,
self.appState.mainBrowserState,
std::make_unique<MainControllerAuthenticationServiceDelegate>(
self.mainBrowserState, self));
self.appState.mainBrowserState, self));
// Send "Chrome Opened" event to the feature_engagement::Tracker on cold
// start.
feature_engagement::TrackerFactory::GetForBrowserState(chromeBrowserState)
->NotifyEvent(feature_engagement::events::kChromeOpened);
_spotlightManager =
[SpotlightManager spotlightManagerWithBrowserState:self.mainBrowserState];
_spotlightManager = [SpotlightManager
spotlightManagerWithBrowserState:self.appState.mainBrowserState];
ShareExtensionService* service =
ShareExtensionServiceFactory::GetForBrowserState(self.mainBrowserState);
ShareExtensionServiceFactory::GetForBrowserState(
self.appState.mainBrowserState);
service->Initialize();
if (IsCredentialProviderExtensionSupported()) {
CredentialProviderServiceFactory::GetForBrowserState(self.mainBrowserState);
CredentialProviderServiceFactory::GetForBrowserState(
self.appState.mainBrowserState);
}
if ([PreviousSessionInfo sharedInstance].isFirstSessionAfterLanguageChange) {
......@@ -549,9 +548,9 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
connectedScenes:self.appState.connectedScenes];
if (self.isColdStart) {
[ContentSuggestionsSchedulerNotifications
notifyColdStart:self.mainBrowserState];
notifyColdStart:self.appState.mainBrowserState];
[ContentSuggestionsSchedulerNotifications
notifyForeground:self.mainBrowserState];
notifyForeground:self.appState.mainBrowserState];
}
ios::GetChromeBrowserProvider()->GetOverridesProvider()->InstallOverrides();
......@@ -683,14 +682,15 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
_spotlightManager = nil;
if (base::FeatureList::IsEnabled(kLogBreadcrumbs)) {
if (self.mainBrowserState->HasOffTheRecordChromeBrowserState()) {
if (self.appState.mainBrowserState->HasOffTheRecordChromeBrowserState()) {
breakpad::StopMonitoringBreadcrumbManagerService(
BreadcrumbManagerKeyedServiceFactory::GetForBrowserState(
self.mainBrowserState->GetOffTheRecordChromeBrowserState()));
self.appState.mainBrowserState
->GetOffTheRecordChromeBrowserState()));
}
breakpad::StopMonitoringBreadcrumbManagerService(
BreadcrumbManagerKeyedServiceFactory::GetForBrowserState(
self.mainBrowserState));
self.appState.mainBrowserState));
}
_extensionSearchEngineDataUpdater = nullptr;
......@@ -776,7 +776,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Track changes to default search engine.
TemplateURLService* service =
ios::TemplateURLServiceFactory::GetForBrowserState(
self.mainBrowserState);
self.appState.mainBrowserState);
_extensionSearchEngineDataUpdater =
std::make_unique<ExtensionSearchEngineDataUpdater>(
service);
......@@ -787,8 +787,8 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[[DeferredInitializationRunner sharedInstance]
enqueueBlockNamed:kSendInstallPingIfNecessary
block:^{
auto URLLoaderFactory =
self.mainBrowserState->GetSharedURLLoaderFactory();
auto URLLoaderFactory = self.appState.mainBrowserState
->GetSharedURLLoaderFactory();
const bool is_first_run = FirstRun::IsChromeFirstRun();
ios::GetChromeBrowserProvider()
->GetAppDistributionProvider()
......@@ -838,10 +838,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// ClearSessionCookies() is not synchronous.
if (cookie_util::ShouldClearSessionCookies()) {
cookie_util::ClearSessionCookies(
self.mainBrowserState->GetOriginalChromeBrowserState());
self.appState.mainBrowserState->GetOriginalChromeBrowserState());
if (!(self.otrBrowser->GetWebStateList()->empty())) {
cookie_util::ClearSessionCookies(
self.mainBrowserState->GetOffTheRecordChromeBrowserState());
self.appState.mainBrowserState->GetOffTheRecordChromeBrowserState());
}
}
......@@ -871,12 +871,13 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
enqueueBlockNamed:kMailtoHandlingInitialization
block:^{
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf || !strongSelf.mainBrowserState) {
if (!strongSelf || !strongSelf.appState.mainBrowserState) {
return;
}
ios::GetChromeBrowserProvider()
->GetMailtoHandlerProvider()
->PrepareMailtoHandling(strongSelf.mainBrowserState);
->PrepareMailtoHandling(
strongSelf.appState.mainBrowserState);
}];
}
......@@ -939,31 +940,31 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
- (void)startLoggingBreadcrumbs {
BreadcrumbManagerKeyedService* breadcrumbService =
BreadcrumbManagerKeyedServiceFactory::GetForBrowserState(
self.mainBrowserState);
self.appState.mainBrowserState);
breakpad::MonitorBreadcrumbManagerService(breadcrumbService);
__weak __typeof(self) weakSelf = self;
BreadcrumbPersistentStorageKeyedService* persistentStorageService =
BreadcrumbPersistentStorageKeyedServiceFactory::GetForBrowserState(
self.mainBrowserState);
self.appState.mainBrowserState);
// Get stored persistent breadcrumbs from last run and set them on the
// breadcrumb manager.
persistentStorageService->GetStoredEvents(
base::BindOnce(^(std::vector<std::string> events) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf || !strongSelf.mainBrowserState) {
if (!strongSelf || !strongSelf.appState.mainBrowserState) {
return;
}
BreadcrumbManagerKeyedServiceFactory::GetForBrowserState(
strongSelf.mainBrowserState)
strongSelf.appState.mainBrowserState)
->SetPreviousEvents(events);
breakpad::SetPreviousSessionEvents(events);
// Notify persistent breadcrumb service to clear old breadcrumbs and
// start storing breadcrumbs for this session.
BreadcrumbPersistentStorageKeyedServiceFactory::GetForBrowserState(
strongSelf.mainBrowserState)
strongSelf.appState.mainBrowserState)
->StartStoringEvents();
}));
}
......@@ -975,7 +976,8 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self schedulePrefObserverInitialization];
[self scheduleMemoryDebuggingTools];
[StartupTasks
scheduleDeferredBrowserStateInitialization:self.mainBrowserState];
scheduleDeferredBrowserStateInitialization:self.appState
.mainBrowserState];
[self sendQueuedFeedback];
[self scheduleSpotlightResync];
[self scheduleDeleteTempDownloadsDirectory];
......@@ -992,7 +994,8 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
if (GetApplicationContext()->WasLastShutdownClean()) {
// Delay the cleanup of the unreferenced files to not impact startup
// performance.
ExternalFileRemoverFactory::GetForBrowserState(self.mainBrowserState)
ExternalFileRemoverFactory::GetForBrowserState(
self.appState.mainBrowserState)
->RemoveAfterDelay(
base::TimeDelta::FromSeconds(kExternalFilesCleanupDelaySeconds),
base::OnceClosure());
......@@ -1126,7 +1129,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// TODO(crbug.com/1116496): Browsers for disconnected scenes are not in the
// BrowserList, so this may not reach all folders.
BrowserList* browser_list =
BrowserListFactory::GetForBrowserState(self.mainBrowserState);
BrowserListFactory::GetForBrowserState(self.appState.mainBrowserState);
for (Browser* browser : browser_list->AllRegularBrowsers()) {
SnapshotBrowserAgent::FromBrowser(browser)->PerformStorageMaintenance();
}
......
......@@ -26,8 +26,6 @@ class ChromeBrowserState;
// Keeps track of the restore state during startup.
@property(nonatomic, strong) CrashRestoreHelper* restoreHelper;
- (ChromeBrowserState*)mainBrowserState;
// Only for iOS 12 compat.
- (NSDictionary*)launchOptions;
......
......@@ -535,10 +535,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
DCHECK(!self.browserViewWrangler);
DCHECK(self.sceneURLLoadingService);
DCHECK(self.mainController);
DCHECK(self.mainController.mainBrowserState);
DCHECK(self.sceneState.appState.mainBrowserState);
self.browserViewWrangler = [[BrowserViewWrangler alloc]
initWithBrowserState:self.mainController.mainBrowserState
initWithBrowserState:self.sceneState.appState.mainBrowserState
sceneState:self.sceneState
applicationCommandEndpoint:self
browsingDataCommandEndpoint:self.mainController];
......@@ -599,7 +599,7 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
// Determines which UI should be shown on startup, and shows it.
- (void)createInitialUI:(ApplicationMode)launchMode {
DCHECK(self.mainController.mainBrowserState);
DCHECK(self.sceneState.appState.mainBrowserState);
// Set the Scene application URL loader on the URL loading browser interface
// for the regular and incognito interfaces. This will lazily instantiate the
......@@ -779,7 +779,7 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
// Returns YES if the promo is shown.
- (BOOL)presentSigninUpgradePromoIfPossible {
if (!SigninShouldPresentUserSigninUpgrade(
self.mainController.mainBrowserState))
self.sceneState.appState.mainBrowserState))
return NO;
// Don't show promos if first run is shown in any scene. (Note: This flag
// is only YES while the first run UI is visible. However, as this function
......@@ -2108,10 +2108,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
// Clears incognito data that is specific to iOS and won't be cleared by
// deleting the browser state.
- (void)clearIOSSpecificIncognitoData {
DCHECK(self.mainController.mainBrowserState
DCHECK(self.sceneState.appState.mainBrowserState
->HasOffTheRecordChromeBrowserState());
ChromeBrowserState* otrBrowserState =
self.mainController.mainBrowserState->GetOffTheRecordChromeBrowserState();
self.sceneState.appState.mainBrowserState
->GetOffTheRecordChromeBrowserState();
[self.mainController
removeBrowsingDataForBrowserState:otrBrowserState
timePeriod:browsing_data::TimePeriod::ALL_TIME
......@@ -2228,7 +2229,8 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
// closed (i.e. if there are other incognito tabs open in another Scene, the
// BrowserState must not be destroyed).
- (BOOL)shouldDestroyAndRebuildIncognitoBrowserState {
ChromeBrowserState* mainBrowserState = self.mainController.mainBrowserState;
ChromeBrowserState* mainBrowserState =
self.sceneState.appState.mainBrowserState;
if (!mainBrowserState->HasOffTheRecordChromeBrowserState())
return NO;
......@@ -2258,16 +2260,15 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
[self clearIOSSpecificIncognitoData];
ChromeBrowserState* mainBrowserState = self.mainController.mainBrowserState;
ChromeBrowserState* mainBrowserState =
self.sceneState.appState.mainBrowserState;
DCHECK(mainBrowserState->HasOffTheRecordChromeBrowserState());
NSMutableArray<SceneController*>* sceneControllers =
[[NSMutableArray alloc] init];
for (SceneState* sceneState in self.sceneState.appState.connectedScenes) {
SceneController* sceneController = sceneState.controller;
if (sceneController.mainController.mainBrowserState == mainBrowserState) {
[sceneControllers addObject:sceneController];
}
[sceneControllers addObject:sceneController];
}
for (SceneController* sceneController in sceneControllers) {
......
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