Commit b5662383 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Pass Browser instead of BrowserState into First Run classes.

This is the second CL of several breaking crrev.com/c/1860025 into smaller
chunks.

Change the various classes and tests in ui/first_run/ to accept a Browser
where before they accepted a BrowserState. Spurious use of, and dependency
on, TabModel is also removed.

Change-Id: I961a684231d78036881084be0222d56787a55e9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863017
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709840}
parent 31f8a2cc
...@@ -1393,10 +1393,9 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -1393,10 +1393,9 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
WelcomeToChromeViewController* welcomeToChrome = WelcomeToChromeViewController* welcomeToChrome =
[[WelcomeToChromeViewController alloc] [[WelcomeToChromeViewController alloc]
initWithBrowserState:self.mainBrowserState initWithBrowser:self.interfaceProvider.mainInterface.browser
tabModel:self.mainTabModel presenter:self.mainBVC
presenter:self.mainBVC dispatcher:self.mainBVC.dispatcher];
dispatcher:self.mainBVC.dispatcher];
UINavigationController* navController = UINavigationController* navController =
[[OrientationLimitingNavigationController alloc] [[OrientationLimitingNavigationController alloc]
initWithRootViewController:welcomeToChrome]; initWithRootViewController:welcomeToChrome];
......
...@@ -32,8 +32,8 @@ source_set("first_run") { ...@@ -32,8 +32,8 @@ source_set("first_run") {
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/crash_report", "//ios/chrome/browser/crash_report",
"//ios/chrome/browser/first_run", "//ios/chrome/browser/first_run",
"//ios/chrome/browser/main",
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/authentication", "//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/fancy_ui", "//ios/chrome/browser/ui/fancy_ui",
...@@ -74,7 +74,7 @@ source_set("unit_tests") { ...@@ -74,7 +74,7 @@ source_set("unit_tests") {
"//components/prefs", "//components/prefs",
"//components/prefs:test_support", "//components/prefs:test_support",
"//ios/chrome/browser/browser_state:test_support", "//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/ui/fancy_ui", "//ios/chrome/browser/ui/fancy_ui",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/test:test_support", "//ios/chrome/test:test_support",
......
...@@ -11,23 +11,19 @@ extern NSString* const kSignInButtonAccessibilityIdentifier; ...@@ -11,23 +11,19 @@ extern NSString* const kSignInButtonAccessibilityIdentifier;
extern NSString* const kSignInSkipButtonAccessibilityIdentifier; extern NSString* const kSignInSkipButtonAccessibilityIdentifier;
@protocol ApplicationCommands; @protocol ApplicationCommands;
class Browser;
@class FirstRunConfiguration; @class FirstRunConfiguration;
namespace ios {
class ChromeBrowserState;
}
@protocol SyncPresenter; @protocol SyncPresenter;
@class TabModel;
// A ChromeSigninViewController that is used during the run. // A ChromeSigninViewController that is used during the run.
@interface FirstRunChromeSigninViewController : ChromeSigninViewController @interface FirstRunChromeSigninViewController : ChromeSigninViewController
// Designated initialzer. // Designated initialzer.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState - (instancetype)initWithBrowser:(Browser*)browser
tabModel:(TabModel*)tabModel firstRunConfig:(FirstRunConfiguration*)firstRunConfig
firstRunConfig:(FirstRunConfiguration*)firstRunConfig signInIdentity:(ChromeIdentity*)identity
signInIdentity:(ChromeIdentity*)identity presenter:(id<SyncPresenter>)presenter
presenter:(id<SyncPresenter>)presenter dispatcher:(id<ApplicationCommands>)dispatcher;
dispatcher:(id<ApplicationCommands>)dispatcher;
@end @end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "components/signin/public/base/signin_metrics.h" #include "components/signin/public/base/signin_metrics.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/first_run/first_run_configuration.h" #import "ios/chrome/browser/first_run/first_run_configuration.h"
#import "ios/chrome/browser/tabs/tab_model.h" #include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/show_signin_command.h" #import "ios/chrome/browser/ui/commands/show_signin_command.h"
#import "ios/chrome/browser/ui/first_run/first_run_util.h" #import "ios/chrome/browser/ui/first_run/first_run_util.h"
...@@ -34,7 +34,6 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier = ...@@ -34,7 +34,6 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier =
@interface FirstRunChromeSigninViewController ()< @interface FirstRunChromeSigninViewController ()<
ChromeSigninViewControllerDelegate> { ChromeSigninViewControllerDelegate> {
__weak TabModel* _tabModel;
FirstRunConfiguration* _firstRunConfig; FirstRunConfiguration* _firstRunConfig;
__weak ChromeIdentity* _identity; __weak ChromeIdentity* _identity;
BOOL _hasRecordedSigninStarted; BOOL _hasRecordedSigninStarted;
...@@ -43,26 +42,28 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier = ...@@ -43,26 +42,28 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier =
// Presenter for showing sync-related UI. // Presenter for showing sync-related UI.
@property(nonatomic, readonly, weak) id<SyncPresenter> presenter; @property(nonatomic, readonly, weak) id<SyncPresenter> presenter;
// The Browser this object was initialized with.
@property(nonatomic, readonly) Browser* browser;
@end @end
@implementation FirstRunChromeSigninViewController @implementation FirstRunChromeSigninViewController
@synthesize presenter = _presenter;
- (instancetype)initWithBrowser:(Browser*)browser
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState firstRunConfig:(FirstRunConfiguration*)firstRunConfig
tabModel:(TabModel*)tabModel signInIdentity:(ChromeIdentity*)identity
firstRunConfig:(FirstRunConfiguration*)firstRunConfig presenter:(id<SyncPresenter>)presenter
signInIdentity:(ChromeIdentity*)identity dispatcher:(id<ApplicationCommands>)dispatcher {
presenter:(id<SyncPresenter>)presenter DCHECK(browser);
dispatcher:(id<ApplicationCommands>)dispatcher {
self = [super self = [super
initWithBrowserState:browserState initWithBrowserState:browser->GetBrowserState()
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE
promoAction:signin_metrics::PromoAction:: promoAction:signin_metrics::PromoAction::
PROMO_ACTION_NO_SIGNIN_PROMO PROMO_ACTION_NO_SIGNIN_PROMO
signInIdentity:identity signInIdentity:identity
dispatcher:dispatcher]; dispatcher:dispatcher];
if (self) { if (self) {
_tabModel = tabModel; _browser = browser;
_firstRunConfig = firstRunConfig; _firstRunConfig = firstRunConfig;
_identity = identity; _identity = identity;
_presenter = presenter; _presenter = presenter;
...@@ -71,11 +72,6 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier = ...@@ -71,11 +72,6 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier =
return self; return self;
} }
- (void)dealloc {
self.delegate = nil;
_tabModel = nil;
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES]; [self.navigationController setNavigationBarHidden:YES];
...@@ -109,7 +105,8 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier = ...@@ -109,7 +105,8 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier =
- (void)finishFirstRunAndDismissWithCompletion:(ProceduralBlock)completion { - (void)finishFirstRunAndDismissWithCompletion:(ProceduralBlock)completion {
DCHECK(self.presentingViewController); DCHECK(self.presentingViewController);
web::WebState* currentWebState = _tabModel.webStateList->GetActiveWebState(); web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
FinishFirstRun(self.browserState, currentWebState, _firstRunConfig, FinishFirstRun(self.browserState, currentWebState, _firstRunConfig,
self.presenter); self.presenter);
[self.presentingViewController dismissViewControllerAnimated:YES [self.presentingViewController dismissViewControllerAnimated:YES
......
...@@ -10,12 +10,8 @@ ...@@ -10,12 +10,8 @@
extern NSString* const kUMAMetricsButtonAccessibilityIdentifier; extern NSString* const kUMAMetricsButtonAccessibilityIdentifier;
@protocol ApplicationCommands; @protocol ApplicationCommands;
class Browser;
@protocol SyncPresenter; @protocol SyncPresenter;
@class TabModel;
namespace ios {
class ChromeBrowserState;
}
// The first screen displayed to the user on First Run. User must agree to the // The first screen displayed to the user on First Run. User must agree to the
// Chrome Terms of Service before proceeding to use Chrome. // Chrome Terms of Service before proceeding to use Chrome.
...@@ -29,10 +25,9 @@ class ChromeBrowserState; ...@@ -29,10 +25,9 @@ class ChromeBrowserState;
// Initializes with the given browser state object and tab model, neither of // Initializes with the given browser state object and tab model, neither of
// which can be nil. // which can be nil.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState - (instancetype)initWithBrowser:(Browser*)browser
tabModel:(TabModel*)tabModel presenter:(id<SyncPresenter>)presenter
presenter:(id<SyncPresenter>)presenter dispatcher:(id<ApplicationCommands>)dispatcher
dispatcher:(id<ApplicationCommands>)dispatcher
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNibName:(NSString*)nibNameOrNil - (instancetype)initWithNibName:(NSString*)nibNameOrNil
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/first_run/first_run_configuration.h" #include "ios/chrome/browser/first_run/first_run_configuration.h"
#include "ios/chrome/browser/tabs/tab_model.h" #include "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h"
#import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller.h" #import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller.h"
#include "ios/chrome/browser/ui/first_run/first_run_util.h" #include "ios/chrome/browser/ui/first_run/first_run_util.h"
...@@ -51,8 +51,7 @@ const BOOL kDefaultStatsCheckboxValue = YES; ...@@ -51,8 +51,7 @@ const BOOL kDefaultStatsCheckboxValue = YES;
@interface WelcomeToChromeViewController ()<WelcomeToChromeViewDelegate, @interface WelcomeToChromeViewController ()<WelcomeToChromeViewDelegate,
UINavigationControllerDelegate> { UINavigationControllerDelegate> {
ios::ChromeBrowserState* browserState_; // weak Browser* _browser;
__weak TabModel* tabModel_;
} }
// The animation which occurs at launch has run. // The animation which occurs at launch has run.
...@@ -103,33 +102,19 @@ const BOOL kDefaultStatsCheckboxValue = YES; ...@@ -103,33 +102,19 @@ const BOOL kDefaultStatsCheckboxValue = YES;
return kDefaultStatsCheckboxValue; return kDefaultStatsCheckboxValue;
} }
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState - (instancetype)initWithBrowser:(Browser*)browser
tabModel:(TabModel*)tabModel presenter:(id<SyncPresenter>)presenter
presenter:(id<SyncPresenter>)presenter dispatcher:(id<ApplicationCommands>)dispatcher {
dispatcher:(id<ApplicationCommands>)dispatcher { DCHECK(browser);
DCHECK(browserState);
DCHECK(tabModel);
self = [super initWithNibName:nil bundle:nil]; self = [super initWithNibName:nil bundle:nil];
if (self) { if (self) {
browserState_ = browserState; _browser = browser;
tabModel_ = tabModel;
_presenter = presenter; _presenter = presenter;
_dispatcher = dispatcher; _dispatcher = dispatcher;
} }
return self; return self;
} }
- (instancetype)initWithNibName:(nullable NSString*)nibNameOrNil
bundle:(nullable NSBundle*)nibBundleOrNil {
NOTREACHED();
return nil;
}
- (instancetype)initWithCoder:(nonnull NSCoder*)aDecoder {
NOTREACHED();
return nil;
}
- (void)loadView { - (void)loadView {
WelcomeToChromeView* welcomeToChromeView = WelcomeToChromeView* welcomeToChromeView =
[[WelcomeToChromeView alloc] initWithFrame:CGRectZero]; [[WelcomeToChromeView alloc] initWithFrame:CGRectZero];
...@@ -172,8 +157,9 @@ const BOOL kDefaultStatsCheckboxValue = YES; ...@@ -172,8 +157,9 @@ const BOOL kDefaultStatsCheckboxValue = YES;
// Displays the file at the given URL in a StaticFileViewController. // Displays the file at the given URL in a StaticFileViewController.
- (void)openStaticFileWithURL:(NSURL*)url title:(NSString*)title { - (void)openStaticFileWithURL:(NSURL*)url title:(NSString*)title {
StaticFileViewController* staticViewController = StaticFileViewController* staticViewController =
[[StaticFileViewController alloc] initWithBrowserState:browserState_ [[StaticFileViewController alloc]
URL:url]; initWithBrowserState:_browser->GetBrowserState()
URL:url];
[staticViewController setTitle:title]; [staticViewController setTitle:title];
[self.navigationController pushViewController:staticViewController [self.navigationController pushViewController:staticViewController
animated:YES]; animated:YES];
...@@ -218,12 +204,11 @@ const BOOL kDefaultStatsCheckboxValue = YES; ...@@ -218,12 +204,11 @@ const BOOL kDefaultStatsCheckboxValue = YES;
[firstRunConfig setHasSSOAccount:hasSSOAccounts]; [firstRunConfig setHasSSOAccount:hasSSOAccounts];
FirstRunChromeSigninViewController* signInController = FirstRunChromeSigninViewController* signInController =
[[FirstRunChromeSigninViewController alloc] [[FirstRunChromeSigninViewController alloc]
initWithBrowserState:browserState_ initWithBrowser:_browser
tabModel:tabModel_ firstRunConfig:firstRunConfig
firstRunConfig:firstRunConfig signInIdentity:nil
signInIdentity:nil presenter:self.presenter
presenter:self.presenter dispatcher:self.dispatcher];
dispatcher:self.dispatcher];
CATransition* transition = [CATransition animation]; CATransition* transition = [CATransition animation];
transition.duration = kFadeOutAnimationDuration; transition.duration = kFadeOutAnimationDuration;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/tabs/tab_model.h" #include "ios/chrome/browser/main/test_browser.h"
#include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h"
#import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view.h" #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view.h"
#import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h"
...@@ -40,12 +40,13 @@ class WelcomeToChromeViewControllerTest : public PlatformTest { ...@@ -40,12 +40,13 @@ class WelcomeToChromeViewControllerTest : public PlatformTest {
PlatformTest::SetUp(); PlatformTest::SetUp();
TestChromeBrowserState::Builder test_cbs_builder; TestChromeBrowserState::Builder test_cbs_builder;
chrome_browser_state_ = test_cbs_builder.Build(); chrome_browser_state_ = test_cbs_builder.Build();
id tabModel = [OCMockObject mockForClass:[TabModel class]]; WebStateList* web_state_list = nullptr;
controller_ = [[WelcomeToChromeViewController alloc] browser_ = std::make_unique<TestBrowser>(chrome_browser_state_.get(),
initWithBrowserState:chrome_browser_state_.get() web_state_list);
tabModel:tabModel controller_ =
presenter:nil [[WelcomeToChromeViewController alloc] initWithBrowser:browser_.get()
dispatcher:nil]; presenter:nil
dispatcher:nil];
[controller_ loadView]; [controller_ loadView];
} }
...@@ -57,6 +58,7 @@ class WelcomeToChromeViewControllerTest : public PlatformTest { ...@@ -57,6 +58,7 @@ class WelcomeToChromeViewControllerTest : public PlatformTest {
web::WebTaskEnvironment task_environment_; web::WebTaskEnvironment task_environment_;
IOSChromeScopedTestingLocalState local_state_; IOSChromeScopedTestingLocalState local_state_;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
std::unique_ptr<Browser> browser_;
WelcomeToChromeViewController* controller_; WelcomeToChromeViewController* controller_;
}; };
......
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