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