Commit 67bcad56 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Plumb Browser through remainder of auth flow.

This is the final of five CLs breaking crrev.com/c/1860025 into smaller
chunks.

This CL updates the classes in ui/authentication to accept a Browser
instead of a BrowserState, and updates their callers, who at this point
all are created with Browsers to pass in.

The workarounds in the parent CL are removed, and now all of the inits
for SettingsNavigationController use Browser.

Bug: 1018746
Change-Id: Iaa6b20279daa64d377730c74c29b14f25c9d1404
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1883724
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710332}
parent 2e58816b
......@@ -46,6 +46,7 @@ source_set("authentication") {
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/main",
"//ios/chrome/browser/metrics",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/sync",
......@@ -123,6 +124,7 @@ source_set("unit_tests") {
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/metrics",
"//ios/chrome/browser/prefs:browser_prefs",
"//ios/chrome/browser/signin",
......
......@@ -11,14 +11,11 @@
#import "ios/chrome/browser/ui/authentication/authentication_flow_performer_delegate.h"
@class AuthenticationFlowPerformer;
class Browser;
@protocol BrowsingDataCommands;
@class ChromeIdentity;
@class UIViewController;
namespace ios {
class ChromeBrowserState;
} // namespace ios
// |AuthenticationFlow| manages the authentication flow for a given identity.
//
// A new instance of |AuthenticationFlow| should be used each time an identity
......@@ -26,7 +23,8 @@ class ChromeBrowserState;
@interface AuthenticationFlow : NSObject<AuthenticationFlowPerformerDelegate>
// Designated initializer.
// * |browserState| is the current browser state
// * |browser| is the current browser where the authentication flow is being
// presented.
// * |shouldClearData| indicates how to handle existing data when the signed in
// account is being switched. Possible values:
// * User choice: present an alert view asking the user whether the data
......@@ -36,11 +34,11 @@ class ChromeBrowserState;
// * |postSignInAction| represents the action to be taken once |identity| is
// signed in.
// * |presentingViewController| is the top presented view controller.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
identity:(ChromeIdentity*)identity
shouldClearData:(ShouldClearData)shouldClearData
postSignInAction:(PostSignInAction)postSignInAction
presentingViewController:(UIViewController*)presentingViewController
- (instancetype)initWithBrowser:(Browser*)browser
identity:(ChromeIdentity*)identity
shouldClearData:(ShouldClearData)shouldClearData
postSignInAction:(PostSignInAction)postSignInAction
presentingViewController:(UIViewController*)presentingViewController
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
......
......@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/mac/scoped_block.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/constants.h"
......@@ -93,7 +94,7 @@ NSError* IdentityMissingError() {
BOOL _shouldSignOut;
BOOL _shouldShowManagedConfirmation;
BOOL _shouldStartSync;
ios::ChromeBrowserState* _browserState;
Browser* _browser;
ChromeIdentity* _browserStateIdentity;
ChromeIdentity* _identityToSignIn;
NSString* _identityToSignInHostedDomain;
......@@ -109,16 +110,15 @@ NSError* IdentityMissingError() {
#pragma mark - Public methods
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
identity:(ChromeIdentity*)identity
shouldClearData:(ShouldClearData)shouldClearData
postSignInAction:(PostSignInAction)postSignInAction
presentingViewController:
(UIViewController*)presentingViewController {
- (instancetype)initWithBrowser:(Browser*)browser
identity:(ChromeIdentity*)identity
shouldClearData:(ShouldClearData)shouldClearData
postSignInAction:(PostSignInAction)postSignInAction
presentingViewController:(UIViewController*)presentingViewController {
if ((self = [super init])) {
DCHECK(browserState);
DCHECK(browser);
DCHECK(presentingViewController);
_browserState = browserState;
_browser = browser;
_identityToSignIn = identity;
_shouldClearData = shouldClearData;
_postSignInAction = postSignInAction;
......@@ -243,6 +243,7 @@ NSError* IdentityMissingError() {
}
- (void)continueSignin {
ios::ChromeBrowserState* browserState = _browser->GetBrowserState();
if (self.handlingError) {
// The flow should not continue while the error is being handled, e.g. while
// the user is being informed of an issue.
......@@ -260,16 +261,16 @@ NSError* IdentityMissingError() {
return;
case FETCH_MANAGED_STATUS:
[_performer fetchManagedStatus:_browserState
[_performer fetchManagedStatus:browserState
forIdentity:_identityToSignIn];
return;
case CHECK_MERGE_CASE:
if ([_performer shouldHandleMergeCaseForIdentity:_identityToSignIn
browserState:_browserState]) {
browserState:browserState]) {
if (_shouldClearData == SHOULD_CLEAR_DATA_USER_CHOICE) {
[_performer promptMergeCaseForIdentity:_identityToSignIn
browserState:_browserState
browser:_browser
viewController:_presentingViewController];
return;
}
......@@ -284,11 +285,11 @@ NSError* IdentityMissingError() {
return;
case SIGN_OUT_IF_NEEDED:
[_performer signOutBrowserState:_browserState];
[_performer signOutBrowserState:browserState];
return;
case CLEAR_DATA:
[_performer clearData:_browserState dispatcher:_dispatcher];
[_performer clearDataFromBrowser:_browser commandHandler:_dispatcher];
return;
case SIGN_IN:
......@@ -296,7 +297,7 @@ NSError* IdentityMissingError() {
return;
case START_SYNC:
[_performer commitSyncForBrowserState:_browserState];
[_performer commitSyncForBrowserState:browserState];
[self continueSignin];
return;
......@@ -306,10 +307,10 @@ NSError* IdentityMissingError() {
case COMPLETE_WITH_FAILURE:
if (_didSignIn) {
[_performer signOutImmediatelyFromBrowserState:_browserState];
[_performer signOutImmediatelyFromBrowserState:browserState];
// Enabling/disabling sync does not take effect in the sync backend
// until committing changes.
[_performer commitSyncForBrowserState:_browserState];
[_performer commitSyncForBrowserState:browserState];
}
[self completeSignInWithSuccess:NO];
return;
......@@ -330,9 +331,9 @@ NSError* IdentityMissingError() {
}
- (void)checkSigninSteps {
_browserStateIdentity =
AuthenticationServiceFactory::GetForBrowserState(_browserState)
->GetAuthenticatedIdentity();
_browserStateIdentity = AuthenticationServiceFactory::GetForBrowserState(
_browser->GetBrowserState())
->GetAuthenticatedIdentity();
if (_browserStateIdentity)
_shouldSignOut = YES;
......@@ -346,7 +347,7 @@ NSError* IdentityMissingError() {
->IsValidIdentity(identity)) {
[_performer signInIdentity:identity
withHostedDomain:_identityToSignInHostedDomain
toBrowserState:_browserState];
toBrowserState:_browser->GetBrowserState()];
_didSignIn = YES;
[self continueSignin];
} else {
......
......@@ -12,6 +12,7 @@
#import "base/ios/block_types.h"
#import "ios/chrome/browser/ui/authentication/authentication_flow_performer_delegate.h"
class Browser;
@protocol BrowsingDataCommands;
@class ChromeIdentity;
......@@ -57,13 +58,14 @@ class ChromeBrowserState;
// or |didChooseCancel| to the delegate when complete according to the user
// action.
- (void)promptMergeCaseForIdentity:(ChromeIdentity*)identity
browserState:(ios::ChromeBrowserState*)browserState
browser:(Browser*)browser
viewController:(UIViewController*)viewController;
// Clears browsing data from |browserState| and sends |didClearData| to the
// delegate when complete.
- (void)clearData:(ios::ChromeBrowserState*)browserState
dispatcher:(id<BrowsingDataCommands>)dispatcher;
// Clears browsing data from the bowser state assoiciated with |browser|, using
// |handler| to perform the removal. When removal is comeplete, the delegate is
// informed (via -didClearData).
- (void)clearDataFromBrowser:(Browser*)browser
commandHandler:(id<BrowsingDataCommands>)handler;
// Determines whether the user must decide what to do with |identity|'s browsing
// data before signing into |browserState|.
......
......@@ -20,6 +20,7 @@
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_urls.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/constants.h"
......@@ -27,8 +28,6 @@
#include "ios/chrome/browser/sync/sync_setup_service.h"
#include "ios/chrome/browser/sync/sync_setup_service_factory.h"
#include "ios/chrome/browser/system_flags.h"
#include "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/tabs/tab_model_list.h"
#include "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/authentication/authentication_ui_util.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
......@@ -241,8 +240,10 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
}
- (void)promptMergeCaseForIdentity:(ChromeIdentity*)identity
browserState:(ios::ChromeBrowserState*)browserState
browser:(Browser*)browser
viewController:(UIViewController*)viewController {
DCHECK(browser);
ios::ChromeBrowserState* browserState = browser->GetBrowserState();
BOOL isSignedIn = YES;
NSString* lastSignedInEmail =
[AuthenticationServiceFactory::GetForBrowserState(browserState)
......@@ -271,20 +272,23 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
return;
}
_navigationController = [SettingsNavigationController
importDataControllerForBrowserState:browserState
delegate:self
importDataDelegate:self
fromEmail:lastSignedInEmail
toEmail:[identity userEmail]
isSignedIn:isSignedIn];
importDataControllerForBrowser:browser
delegate:self
importDataDelegate:self
fromEmail:lastSignedInEmail
toEmail:[identity userEmail]
isSignedIn:isSignedIn];
[[_delegate presentingViewController]
presentViewController:_navigationController
animated:YES
completion:nil];
}
- (void)clearData:(ios::ChromeBrowserState*)browserState
dispatcher:(id<BrowsingDataCommands>)dispatcher {
- (void)clearDataFromBrowser:(Browser*)browser
commandHandler:(id<BrowsingDataCommands>)handler {
DCHECK(browser);
ios::ChromeBrowserState* browserState = browser->GetBrowserState();
DCHECK(!AuthenticationServiceFactory::GetForBrowserState(browserState)
->IsAuthenticated());
......@@ -308,16 +312,14 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
// This CL works around this issue by waiting for 1 second between steps 1
// and 2 above to allow the WKWebView to initiate the reload after the
// cookies are cleared.
WebStateList* webStateList =
TabModelList::GetLastActiveTabModelForChromeBrowserState(browserState)
.webStateList;
WebStateList* webStateList = browser->GetWebStateList();
web::WebState* activeWebState = webStateList->GetActiveWebState();
bool activeWebStateHasGaiaOrigin =
activeWebState && (activeWebState->GetVisibleURL().GetOrigin() ==
GaiaUrls::GetInstance()->gaia_url());
int64_t dispatchDelaySecs = activeWebStateHasGaiaOrigin ? 1 : 0;
[dispatcher
[handler
removeBrowsingDataForBrowserState:browserState
timePeriod:browsing_data::TimePeriod::ALL_TIME
removeMask:BrowsingDataRemoveMask::REMOVE_ALL
......
......@@ -14,6 +14,7 @@
#include "components/sync_preferences/pref_service_mock_factory.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/main/test_browser.h"
#include "ios/chrome/browser/prefs/browser_prefs.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_fake.h"
......@@ -44,6 +45,10 @@ class AuthenticationFlowTest : public PlatformTest {
&AuthenticationServiceFake::CreateAuthenticationService));
builder.SetPrefService(CreatePrefService());
browser_state_ = builder.Build();
WebStateList* web_state_list = nullptr;
browser_ =
std::make_unique<TestBrowser>(browser_state_.get(), web_state_list);
ios::FakeChromeIdentityService* identityService =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
identityService->AddIdentities(@[ @"identity1", @"identity2" ]);
......@@ -80,11 +85,11 @@ class AuthenticationFlowTest : public PlatformTest {
ChromeIdentity* identity = identity1_;
view_controller_ = [OCMockObject niceMockForClass:[UIViewController class]];
authentication_flow_ =
[[AuthenticationFlow alloc] initWithBrowserState:browser_state_.get()
identity:identity
shouldClearData:shouldClearData
postSignInAction:postSignInAction
presentingViewController:view_controller_];
[[AuthenticationFlow alloc] initWithBrowser:browser_.get()
identity:identity
shouldClearData:shouldClearData
postSignInAction:postSignInAction
presentingViewController:view_controller_];
performer_ =
[OCMockObject mockForClass:[AuthenticationFlowPerformer class]];
[authentication_flow_
......@@ -105,6 +110,7 @@ class AuthenticationFlowTest : public PlatformTest {
web::WebTaskEnvironment task_environment_;
AuthenticationFlow* authentication_flow_;
std::unique_ptr<TestChromeBrowserState> browser_state_;
std::unique_ptr<Browser> browser_;
ChromeIdentity* identity1_;
ChromeIdentity* identity2_;
OCMockObject* performer_;
......@@ -192,8 +198,8 @@ TEST_F(AuthenticationFlowTest, TestSignOutUserChoice) {
[authentication_flow_
didChooseClearDataPolicy:SHOULD_CLEAR_DATA_CLEAR_DATA];
}] promptMergeCaseForIdentity:identity1_
browserState:browser_state_.get()
viewController:view_controller_];
browser:browser_.get()
viewController:view_controller_];
[[[performer_ expect] andDo:^(NSInvocation*) {
[authentication_flow_ didSignOut];
......@@ -201,8 +207,7 @@ TEST_F(AuthenticationFlowTest, TestSignOutUserChoice) {
[[[performer_ expect] andDo:^(NSInvocation*) {
[authentication_flow_ didClearData];
}] clearData:browser_state_.get()
dispatcher:nil];
}] clearDataFromBrowser:browser_.get() commandHandler:nil];
[[performer_ expect] signInIdentity:identity1_
withHostedDomain:nil
......@@ -234,8 +239,8 @@ TEST_F(AuthenticationFlowTest, TestCancel) {
[[[performer_ expect] andDo:^(NSInvocation*) {
[authentication_flow_ cancelAndDismiss];
}] promptMergeCaseForIdentity:identity1_
browserState:browser_state_.get()
viewController:view_controller_];
browser:browser_.get()
viewController:view_controller_];
[[performer_ expect] cancelAndDismiss];
......@@ -290,8 +295,7 @@ TEST_F(AuthenticationFlowTest, TestShowManagedConfirmation) {
[[[performer_ expect] andDo:^(NSInvocation*) {
[authentication_flow_ didClearData];
}] clearData:browser_state_.get()
dispatcher:nil];
}] clearDataFromBrowser:browser_.get() commandHandler:nil];
[[performer_ expect] signInIdentity:identity1_
withHostedDomain:@"foo.com"
......
......@@ -14,6 +14,7 @@
#import "ios/chrome/browser/signin/constants.h"
@protocol ApplicationCommands;
class Browser;
@class ChromeIdentity;
@class ChromeSigninViewController;
......@@ -83,16 +84,16 @@ using TimerGeneratorBlock = std::unique_ptr<base::OneShotTimer> (^)();
@property(nonatomic, weak, readonly) id<ApplicationCommands> dispatcher;
// Designated initializer.
// * |browserState| is the current browser state.
// * |browser| is the browser where sign-in is being presented.
// * |accessPoint| represents the access point that initiated the sign-in.
// * |identity| will be signed in without requiring user input if not nil.
// * |dispatcher| is the dispatcher that can accept commands for displaying
// settings views.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
accessPoint:(signin_metrics::AccessPoint)accessPoint
promoAction:(signin_metrics::PromoAction)promoAction
signInIdentity:(ChromeIdentity*)identity
dispatcher:(id<ApplicationCommands>)dispatcher;
- (instancetype)initWithBrowser:(Browser*)browser
accessPoint:(signin_metrics::AccessPoint)accessPoint
promoAction:(signin_metrics::PromoAction)promoAction
signInIdentity:(ChromeIdentity*)identity
dispatcher:(id<ApplicationCommands>)dispatcher;
// Cancels the on-going authentication operation (if any). |delegate| will be
// called with |didFailSignIn|.
......@@ -102,6 +103,7 @@ using TimerGeneratorBlock = std::unique_ptr<base::OneShotTimer> (^)();
@interface ChromeSigninViewController (Subclassing)
@property(nonatomic, readonly) Browser* browser;
@property(nonatomic, readonly) ios::ChromeBrowserState* browserState;
// Vertical padding used underneath buttons. Default value is 18.
......
......@@ -23,6 +23,7 @@
#include "components/unified_consent/unified_consent_service.h"
#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/signin/authentication_service.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h"
......@@ -139,7 +140,7 @@ enum AuthenticationState {
@end
@implementation ChromeSigninViewController {
ios::ChromeBrowserState* _browserState; // weak
Browser* _browser;
__weak id<ChromeSigninViewControllerDelegate> _delegate;
std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver;
ChromeIdentity* _selectedIdentity;
......@@ -179,14 +180,14 @@ enum AuthenticationState {
BOOL _hasConfirmationScreenReachedBottom;
}
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
accessPoint:(signin_metrics::AccessPoint)accessPoint
promoAction:(signin_metrics::PromoAction)promoAction
signInIdentity:(ChromeIdentity*)identity
dispatcher:(id<ApplicationCommands>)dispatcher {
- (instancetype)initWithBrowser:(Browser*)browser
accessPoint:(signin_metrics::AccessPoint)accessPoint
promoAction:(signin_metrics::PromoAction)promoAction
signInIdentity:(ChromeIdentity*)identity
dispatcher:(id<ApplicationCommands>)dispatcher {
self = [super init];
if (self) {
_browserState = browserState;
_browser = browser;
_accessPoint = accessPoint;
_promoAction = promoAction;
_dispatcher = dispatcher;
......@@ -231,7 +232,7 @@ enum AuthenticationState {
[_authenticationFlow cancelAndDismiss];
}
if (!_didAcceptSignIn && _didSignIn) {
AuthenticationServiceFactory::GetForBrowserState(_browserState)
AuthenticationServiceFactory::GetForBrowserState(self.browserState)
->SignOut(signin_metrics::ABORT_SIGNIN, nil);
_didSignIn = NO;
}
......@@ -259,7 +260,7 @@ enum AuthenticationState {
? openSettingsStringId
: [self acceptSigninButtonStringId];
std::string account_id =
IdentityManagerFactory::GetForBrowserState(_browserState)
IdentityManagerFactory::GetForBrowserState(self.browserState)
->PickAccountIdForAccount(
base::SysNSStringToUTF8([_selectedIdentity gaiaID]),
base::SysNSStringToUTF8([_selectedIdentity userEmail]));
......@@ -271,7 +272,7 @@ enum AuthenticationState {
for (int id : consent_text_ids) {
sync_consent.add_description_grd_ids(id);
}
ConsentAuditorFactory::GetForBrowserState(_browserState)
ConsentAuditorFactory::GetForBrowserState(self.browserState)
->RecordSyncConsent(account_id, sync_consent);
_didAcceptSignIn = YES;
if (!_didFinishSignIn) {
......@@ -289,7 +290,7 @@ enum AuthenticationState {
// The consent has to be given as soon as the user is signed in. Even when
// they open the settings through the link.
unified_consent::UnifiedConsentService* unifiedConsentService =
UnifiedConsentServiceFactory::GetForBrowserState(_browserState);
UnifiedConsentServiceFactory::GetForBrowserState(self.browserState);
// |unifiedConsentService| may be null in unit tests.
if (unifiedConsentService)
unifiedConsentService->SetUrlKeyedAnonymizedDataCollectionEnabled(true);
......@@ -297,7 +298,7 @@ enum AuthenticationState {
// FirstSetupComplete flag should be only turned on when the user agrees
// to start Sync.
SyncSetupService* syncSetupService =
SyncSetupServiceFactory::GetForBrowserState(_browserState);
SyncSetupServiceFactory::GetForBrowserState(self.browserState);
syncSetupService->SetFirstSetupComplete(
syncer::SyncFirstSetupCompleteSource::BASIC_FLOW);
syncSetupService->CommitSyncChanges();
......@@ -481,8 +482,12 @@ enum AuthenticationState {
#pragma mark - Properties
- (Browser*)browser {
return _browser;
}
- (ios::ChromeBrowserState*)browserState {
return _browserState;
return self.browser->GetBrowserState();
}
- (id<ChromeSigninViewControllerDelegate>)delegate {
......@@ -542,11 +547,11 @@ enum AuthenticationState {
[_delegate willStartSignIn:self];
DCHECK(!_authenticationFlow);
_authenticationFlow =
[[AuthenticationFlow alloc] initWithBrowserState:_browserState
identity:identity
shouldClearData:_shouldClearData
postSignInAction:POST_SIGNIN_ACTION_NONE
presentingViewController:self];
[[AuthenticationFlow alloc] initWithBrowser:self.browser
identity:identity
shouldClearData:_shouldClearData
postSignInAction:POST_SIGNIN_ACTION_NONE
presentingViewController:self];
_authenticationFlow.dispatcher = self.dispatcher;
__weak ChromeSigninViewController* weakSelf = self;
[_authenticationFlow startSignInWithCompletion:^(BOOL success) {
......@@ -559,7 +564,7 @@ enum AuthenticationState {
_interactionManager =
ios::GetChromeBrowserProvider()
->GetChromeIdentityService()
->CreateChromeIdentityInteractionManager(_browserState, self);
->CreateChromeIdentityInteractionManager(self.browserState, self);
__weak ChromeSigninViewController* weakSelf = self;
SigninCompletionCallback completion =
^(ChromeIdentity* identity, NSError* error) {
......@@ -599,7 +604,7 @@ enum AuthenticationState {
- (void)undoSignIn {
if (_didSignIn) {
AuthenticationServiceFactory::GetForBrowserState(_browserState)
AuthenticationServiceFactory::GetForBrowserState(self.browserState)
->SignOut(signin_metrics::ABORT_SIGNIN, nil);
[_delegate didUndoSignIn:self identity:self.selectedIdentity];
_didSignIn = NO;
......
......@@ -16,6 +16,7 @@
#include "components/version_info/version_info.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/main/test_browser.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_fake.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
......@@ -142,23 +143,26 @@ class ChromeSigninViewControllerTest
builder.AddTestingFactory(
UnifiedConsentServiceFactory::GetInstance(),
base::BindRepeating(&CreateFakeUnifiedConsentService));
context_ = builder.Build();
browser_state_ = builder.Build();
WebStateList* web_state_list = nullptr;
browser_ =
std::make_unique<TestBrowser>(browser_state_.get(), web_state_list);
ios::FakeChromeIdentityService* identity_service =
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider();
identity_service->AddIdentity(identity_);
identity_manager_ =
IdentityManagerFactory::GetForBrowserState(context_.get());
IdentityManagerFactory::GetForBrowserState(browser_state_.get());
fake_consent_auditor_ = static_cast<consent_auditor::FakeConsentAuditor*>(
ConsentAuditorFactory::GetForBrowserState(context_.get()));
ConsentAuditorFactory::GetForBrowserState(browser_state_.get()));
// Setup view controller.
vc_ = [[ChromeSigninViewController alloc]
initWithBrowserState:context_.get()
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_WITH_DEFAULT
signInIdentity:identity_
dispatcher:nil];
initWithBrowser:browser_.get()
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS
promoAction:signin_metrics::PromoAction::PROMO_ACTION_WITH_DEFAULT
signInIdentity:identity_
dispatcher:nil];
vc_delegate_ = [[FakeChromeSigninViewControllerDelegate alloc] init];
vc_.delegate = vc_delegate_;
UIScreen* screen = [UIScreen mainScreen];
......@@ -341,7 +345,8 @@ class ChromeSigninViewControllerTest
}
web::WebTaskEnvironment task_environment_;
std::unique_ptr<TestChromeBrowserState> context_;
std::unique_ptr<TestChromeBrowserState> browser_state_;
std::unique_ptr<Browser> browser_;
FakeChromeIdentity* identity_;
UIWindow* window_;
ChromeSigninViewController* vc_;
......
......@@ -56,12 +56,11 @@ NSString* const kSignInSkipButtonAccessibilityIdentifier =
dispatcher:(id<ApplicationCommands>)dispatcher {
DCHECK(browser);
self = [super
initWithBrowserState:browser->GetBrowserState()
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_NO_SIGNIN_PROMO
signInIdentity:identity
dispatcher:dispatcher];
initWithBrowser:browser
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE
promoAction:signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO
signInIdentity:identity
dispatcher:dispatcher];
if (self) {
_browser = browser;
_firstRunConfig = firstRunConfig;
......
......@@ -82,13 +82,12 @@ NSSet* GaiaIdSetWithIdentities(NSArray* identities) {
- (instancetype)initWithBrowser:(Browser*)browser
dispatcher:(id<ApplicationCommands>)dispatcher {
self = [super initWithBrowserState:browser->GetBrowserState()
accessPoint:signin_metrics::AccessPoint::
ACCESS_POINT_SIGNIN_PROMO
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_NO_SIGNIN_PROMO
signInIdentity:nil
dispatcher:dispatcher];
self = [super
initWithBrowser:browser
accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_SIGNIN_PROMO
promoAction:signin_metrics::PromoAction::PROMO_ACTION_NO_SIGNIN_PROMO
signInIdentity:nil
dispatcher:dispatcher];
if (self) {
super.delegate = self;
}
......
......@@ -167,12 +167,12 @@
->GetAuthenticatedIdentity();
[self.googleServicesSettingsViewController preventUserInteraction];
DCHECK(!self.authenticationFlow);
self.authenticationFlow = [[AuthenticationFlow alloc]
initWithBrowserState:self.browserState
identity:authenticatedIdentity
shouldClearData:SHOULD_CLEAR_DATA_USER_CHOICE
postSignInAction:POST_SIGNIN_ACTION_START_SYNC
presentingViewController:self.viewController];
self.authenticationFlow =
[[AuthenticationFlow alloc] initWithBrowser:self.browser
identity:authenticatedIdentity
shouldClearData:SHOULD_CLEAR_DATA_USER_CHOICE
postSignInAction:POST_SIGNIN_ACTION_START_SYNC
presentingViewController:self.viewController];
self.authenticationFlow.dispatcher = self.dispatcher;
__weak GoogleServicesSettingsCoordinator* weakSelf = self;
[self.authenticationFlow startSignInWithCompletion:^(BOOL success) {
......
......@@ -14,10 +14,6 @@ class Browser;
@protocol ImportDataControllerDelegate;
@protocol UserFeedbackDataSource;
namespace ios {
class ChromeBrowserState;
} // namespace ios
// The accessibility identifier for the settings' "Done" button.
extern NSString* const kSettingsDoneButtonId;
......@@ -55,9 +51,6 @@ extern NSString* const kSettingsDoneButtonId;
@interface SettingsNavigationController
: UINavigationController<ApplicationSettingsCommands>
// Returns the browser state associated with this view controller;
@property(nonatomic, readonly) ios::ChromeBrowserState* mainBrowserState;
// Creates a new SettingsTableViewController and the chrome around it.
// |browser| is the browser where settings are being displayed and should not be
// nil nor Off-the-Record. |delegate| may be nil.
......@@ -116,15 +109,14 @@ extern NSString* const kSettingsDoneButtonId;
// should not be nil.
// TODO(crbug.com/1018746) pass Browser instead of BrowserState
+ (instancetype)
importDataControllerForBrowserState:(ios::ChromeBrowserState*)browserState
delegate:
(id<SettingsNavigationControllerDelegate>)
delegate
importDataDelegate:
(id<ImportDataControllerDelegate>)importDataDelegate
fromEmail:(NSString*)fromEmail
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn;
importDataControllerForBrowser:(Browser*)browser
delegate:
(id<SettingsNavigationControllerDelegate>)delegate
importDataDelegate:
(id<ImportDataControllerDelegate>)importDataDelegate
fromEmail:(NSString*)fromEmail
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn;
// Creates a new AutofillProfileTableViewController and the chrome around
// it. |browser| is the browser where settings are being displayed and should
......
......@@ -60,18 +60,9 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
@property(nonatomic, weak) id<SettingsNavigationControllerDelegate>
settingsNavigationDelegate;
// The Browser instance this controller is configured with.
@property(nonatomic, assign) Browser* browser;
// Temporary private init while Browser plumbing refactor is in progress.
// This creates an instance with a null browser, which could potentially DCHECK
// in some circumstances.
// TODO(crbug.com/1018746) remove this init.
- (instancetype)
initWithRootViewController:(UIViewController*)rootViewController
browserState:(ios::ChromeBrowserState*)browserState
delegate:
(id<SettingsNavigationControllerDelegate>)delegate;
@end
@implementation SettingsNavigationController
......@@ -198,15 +189,14 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
}
+ (instancetype)
importDataControllerForBrowserState:(ios::ChromeBrowserState*)browserState
delegate:
(id<SettingsNavigationControllerDelegate>)
delegate
importDataDelegate:
(id<ImportDataControllerDelegate>)importDataDelegate
fromEmail:(NSString*)fromEmail
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn {
importDataControllerForBrowser:(Browser*)browser
delegate:
(id<SettingsNavigationControllerDelegate>)delegate
importDataDelegate:
(id<ImportDataControllerDelegate>)importDataDelegate
fromEmail:(NSString*)fromEmail
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn {
UIViewController* controller =
[[ImportDataTableViewController alloc] initWithDelegate:importDataDelegate
fromEmail:fromEmail
......@@ -215,7 +205,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
SettingsNavigationController* nc = [[SettingsNavigationController alloc]
initWithRootViewController:controller
browserState:browserState
browser:browser
delegate:delegate];
// Make sure the cancel button is always present, as the Save Passwords screen
......@@ -275,11 +265,11 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
delegate:
(id<SettingsNavigationControllerDelegate>)
delegate {
DCHECK(browser);
DCHECK(!browser->GetBrowserState()->IsOffTheRecord());
self = [super initWithRootViewController:rootViewController];
if (self) {
_browser = browser;
if (_browser)
_mainBrowserState = browser->GetBrowserState();
_settingsNavigationDelegate = delegate;
self.modalPresentationStyle = UIModalPresentationFormSheet;
// Set the presentationController delegate. This is used for swipe down to
......@@ -291,22 +281,6 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
return self;
}
// Backwards compatibility init while Browser refactor is in progress.
// TODO(crbug.com/1018746) remove this init.
- (instancetype)
initWithRootViewController:(UIViewController*)rootViewController
browserState:(ios::ChromeBrowserState*)browserState
delegate:
(id<SettingsNavigationControllerDelegate>)delegate {
self = [self initWithRootViewController:rootViewController
browser:nullptr
delegate:delegate];
if (self) {
_mainBrowserState = browserState;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
if (base::FeatureList::IsEnabled(kSettingsRefresh)) {
......@@ -537,7 +511,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
(UIViewController*)baseViewController {
SyncEncryptionPassphraseTableViewController* controller =
[[SyncEncryptionPassphraseTableViewController alloc]
initWithBrowserState:self.mainBrowserState];
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES];
......@@ -548,7 +522,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
(UIViewController*)baseViewController {
PasswordsTableViewController* controller =
[[PasswordsTableViewController alloc]
initWithBrowserState:self.mainBrowserState];
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES];
......@@ -559,7 +533,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
(UIViewController*)baseViewController {
AutofillProfileTableViewController* controller =
[[AutofillProfileTableViewController alloc]
initWithBrowserState:self.mainBrowserState];
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES];
......@@ -570,7 +544,7 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
(UIViewController*)baseViewController {
AutofillCreditCardTableViewController* controller =
[[AutofillCreditCardTableViewController alloc]
initWithBrowserState:self.mainBrowserState];
initWithBrowserState:self.browser->GetBrowserState()];
controller.dispatcher =
[self.settingsNavigationDelegate dispatcherForSettings];
[self pushViewController:controller animated:YES];
......
......@@ -233,12 +233,12 @@
- (void)showSigninViewControllerWithIdentity:(ChromeIdentity*)signInIdentity
identityAdded:(BOOL)identityAdded {
signinViewController_ = [[ChromeSigninViewController alloc]
initWithBrowserState:browser_->GetBrowserState()
accessPoint:accessPoint_
promoAction:promoAction_
signInIdentity:signInIdentity
dispatcher:self.dispatcher];
signinViewController_ =
[[ChromeSigninViewController alloc] initWithBrowser:browser_
accessPoint:accessPoint_
promoAction:promoAction_
signInIdentity:signInIdentity
dispatcher:self.dispatcher];
signinViewController_.delegate = self;
signInIdentity_ = signInIdentity;
identityAdded_ = identityAdded;
......
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