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

[iOS] Pass Browser into SettingsNavigationController initializers.

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

This updates most of the SettingsNavigationController class inits to take
a Browser instead of a BrowserState. One of the inits (the import data
one) is called from AuthenticationFlowPerformer, which doesn't yet have
a Browser, so it's initialized with a BrowserState instead. Because of this,
SettingsNavigationController itself is initialized with a BrowserState.

There's also some cleanup of these init names. Prior to this change, none
of the class methods (for example: "newAccountsController:delegate:")
properly identified the first parameter. Some of the method signatures were
also impossible for clang-format to wrap to 80 characters. So:
 - The return type of all of these methods is now 'instancetype'.
 - The 'new' prefix is dropped from all of them, matching current style.
 - Methods that had 'WithBrowserState:' now have 'ForBrowser:', aside from
   -importDataControllerForBrowserState:delegate:importDataDelegate:
    fromEmail:toEmail:isSignedIn:.
 - Methods that didn't have a keyword for the BrowserState parameter also
   now have "ForBrowser:".
 - "syncEncryptionPassphrase" is shortened to "syncPassphrase", since
   "Encryption" doesn't add any useful information. The full method name is
   now +syncPassphraseControllerForBrowser:delegate:.
 - "autofillProfille" is corrected to "autofillProfile" (one "l" in
   "profile", The full method name is now
   +autofillProfileControllerForBrowser:delegate:
 - "settingsMainController" is reordered to "mainSettings". The full method
   name is now +mainSettingsControllerForBrowser:delegate:

BrowserInterface didn't have a 'browser' property, which it clearly needed.
This CL adds one.

Change-Id: I6b0a8c8583dc69485a0f65ac1d069de7b417d564
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862915
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706481}
parent 903f189e
...@@ -200,6 +200,7 @@ source_set("app_internal") { ...@@ -200,6 +200,7 @@ source_set("app_internal") {
"//ios/chrome/browser/geolocation:geolocation_internal", "//ios/chrome/browser/geolocation:geolocation_internal",
"//ios/chrome/browser/history", "//ios/chrome/browser/history",
"//ios/chrome/browser/mailto:feature_flags", "//ios/chrome/browser/mailto:feature_flags",
"//ios/chrome/browser/main",
"//ios/chrome/browser/memory", "//ios/chrome/browser/memory",
"//ios/chrome/browser/metrics", "//ios/chrome/browser/metrics",
"//ios/chrome/browser/metrics:metrics_internal", "//ios/chrome/browser/metrics:metrics_internal",
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#include "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" #include "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
#include "ios/chrome/browser/ios_chrome_io_thread.h" #include "ios/chrome/browser/ios_chrome_io_thread.h"
#include "ios/chrome/browser/mailto/features.h" #include "ios/chrome/browser/mailto/features.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/memory/memory_debugger_manager.h" #import "ios/chrome/browser/memory/memory_debugger_manager.h"
#include "ios/chrome/browser/metrics/first_user_action_recorder.h" #include "ios/chrome/browser/metrics/first_user_action_recorder.h"
#import "ios/chrome/browser/metrics/previous_session_info.h" #import "ios/chrome/browser/metrics/previous_session_info.h"
...@@ -1605,9 +1606,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1605,9 +1606,10 @@ enum class EnterTabSwitcherSnapshotResult {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented); DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController) if (_settingsNavigationController)
return; return;
_settingsNavigationController = [SettingsNavigationController Browser* browser = self.interfaceProvider.mainInterface.browser;
newAutofillProfilleController:_mainBrowserState _settingsNavigationController =
delegate:self]; [SettingsNavigationController autofillProfileControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1623,11 +1625,12 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1623,11 +1625,12 @@ enum class EnterTabSwitcherSnapshotResult {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented); DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController) if (_settingsNavigationController)
return; return;
_settingsNavigationController = [SettingsNavigationController Browser* browser = self.interfaceProvider.mainInterface.browser;
newUserFeedbackController:_mainBrowserState _settingsNavigationController =
delegate:self [SettingsNavigationController userFeedbackControllerForBrowser:browser
feedbackDataSource:self delegate:self
dispatcher:self]; feedbackDataSource:self
dispatcher:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1726,9 +1729,11 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1726,9 +1729,11 @@ enum class EnterTabSwitcherSnapshotResult {
showAccountsSettingsFromViewController:baseViewController]; showAccountsSettingsFromViewController:baseViewController];
return; return;
} }
_settingsNavigationController = [SettingsNavigationController
newAccountsController:self.currentBrowserState Browser* browser = self.interfaceProvider.mainInterface.browser;
delegate:self]; _settingsNavigationController =
[SettingsNavigationController accountsControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1751,11 +1756,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1751,11 +1756,10 @@ enum class EnterTabSwitcherSnapshotResult {
return; return;
} }
ios::ChromeBrowserState* originalBrowserState = Browser* browser = self.interfaceProvider.mainInterface.browser;
self.currentBrowserState->GetOriginalChromeBrowserState(); _settingsNavigationController =
_settingsNavigationController = [SettingsNavigationController [SettingsNavigationController googleServicesControllerForBrowser:browser
newGoogleServicesController:originalBrowserState delegate:self];
delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1770,9 +1774,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1770,9 +1774,10 @@ enum class EnterTabSwitcherSnapshotResult {
showSyncPassphraseSettingsFromViewController:baseViewController]; showSyncPassphraseSettingsFromViewController:baseViewController];
return; return;
} }
_settingsNavigationController = [SettingsNavigationController Browser* browser = self.interfaceProvider.mainInterface.browser;
newSyncEncryptionPassphraseController:_mainBrowserState _settingsNavigationController =
delegate:self]; [SettingsNavigationController syncPassphraseControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1787,9 +1792,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1787,9 +1792,10 @@ enum class EnterTabSwitcherSnapshotResult {
showSavedPasswordsSettingsFromViewController:baseViewController]; showSavedPasswordsSettingsFromViewController:baseViewController];
return; return;
} }
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController = _settingsNavigationController =
[SettingsNavigationController newSavePasswordsController:_mainBrowserState [SettingsNavigationController savePasswordsControllerForBrowser:browser
delegate:self]; delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1804,9 +1810,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1804,9 +1810,10 @@ enum class EnterTabSwitcherSnapshotResult {
showProfileSettingsFromViewController:baseViewController]; showProfileSettingsFromViewController:baseViewController];
return; return;
} }
_settingsNavigationController = [SettingsNavigationController Browser* browser = self.interfaceProvider.mainInterface.browser;
newAutofillProfilleController:_mainBrowserState _settingsNavigationController =
delegate:self]; [SettingsNavigationController autofillProfileControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -1821,9 +1828,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1821,9 +1828,10 @@ enum class EnterTabSwitcherSnapshotResult {
showCreditCardSettingsFromViewController:baseViewController]; showCreditCardSettingsFromViewController:baseViewController];
return; return;
} }
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController = [SettingsNavigationController _settingsNavigationController = [SettingsNavigationController
newAutofillCreditCardController:_mainBrowserState autofillCreditCardControllerForBrowser:browser
delegate:self]; delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
...@@ -2264,9 +2272,10 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -2264,9 +2272,10 @@ enum class EnterTabSwitcherSnapshotResult {
[[DeferredInitializationRunner sharedInstance] [[DeferredInitializationRunner sharedInstance]
runBlockIfNecessary:kPrefObserverInit]; runBlockIfNecessary:kPrefObserverInit];
DCHECK(_localStatePrefObserverBridge); DCHECK(_localStatePrefObserverBridge);
_settingsNavigationController = [SettingsNavigationController Browser* browser = self.interfaceProvider.mainInterface.browser;
newSettingsMainControllerWithBrowserState:_mainBrowserState _settingsNavigationController =
delegate:self]; [SettingsNavigationController mainSettingsControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController [baseViewController presentViewController:_settingsNavigationController
animated:YES animated:YES
completion:nil]; completion:nil];
......
...@@ -270,13 +270,13 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10; ...@@ -270,13 +270,13 @@ const int64_t kAuthenticationFlowTimeoutSeconds = 10;
viewController:viewController]; viewController:viewController];
return; return;
} }
_navigationController = _navigationController = [SettingsNavigationController
[SettingsNavigationController newImportDataController:browserState importDataControllerForBrowserState:browserState
delegate:self delegate:self
importDataDelegate:self importDataDelegate:self
fromEmail:lastSignedInEmail fromEmail:lastSignedInEmail
toEmail:[identity userEmail] toEmail:[identity userEmail]
isSignedIn:isSignedIn]; isSignedIn:isSignedIn];
[[_delegate presentingViewController] [[_delegate presentingViewController]
presentViewController:_navigationController presentViewController:_navigationController
animated:YES animated:YES
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/ios/block_types.h" #include "base/ios/block_types.h"
class Browser;
@class BrowserCoordinator; @class BrowserCoordinator;
@class BrowserViewController; @class BrowserViewController;
@class TabModel; @class TabModel;
...@@ -39,6 +40,8 @@ class ChromeBrowserState; ...@@ -39,6 +40,8 @@ class ChromeBrowserState;
@property(nonatomic, readonly) BrowserViewController* bvc; @property(nonatomic, readonly) BrowserViewController* bvc;
// The tab model to which the current tab belongs. // The tab model to which the current tab belongs.
@property(nonatomic, readonly) TabModel* tabModel; @property(nonatomic, readonly) TabModel* tabModel;
// The active browser.
@property(nonatomic, readonly) Browser* browser;
// The browser state for this interface. // The browser state for this interface.
@property(nonatomic, readonly) ios::ChromeBrowserState* browserState; @property(nonatomic, readonly) ios::ChromeBrowserState* browserState;
// YES if the tab view is available for user interaction. // YES if the tab view is available for user interaction.
......
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
return self.coordinator.tabModel; return self.coordinator.tabModel;
} }
- (Browser*)browser {
return self.coordinator.browser;
}
- (ios::ChromeBrowserState*)browserState { - (ios::ChromeBrowserState*)browserState {
return self.coordinator.viewController.browserState; return self.coordinator.viewController.browserState;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "ios/chrome/browser/ui/main/browser_interface_provider.h" #import "ios/chrome/browser/ui/main/browser_interface_provider.h"
class Browser;
@class BrowserViewController; @class BrowserViewController;
namespace ios { namespace ios {
class ChromeBrowserState; class ChromeBrowserState;
...@@ -21,6 +22,7 @@ class ChromeBrowserState; ...@@ -21,6 +22,7 @@ class ChromeBrowserState;
@property(nonatomic, readwrite) UIViewController* viewController; @property(nonatomic, readwrite) UIViewController* viewController;
@property(nonatomic, readwrite) BrowserViewController* bvc; @property(nonatomic, readwrite) BrowserViewController* bvc;
@property(nonatomic, readwrite) TabModel* tabModel; @property(nonatomic, readwrite) TabModel* tabModel;
@property(nonatomic, readwrite) Browser* browser;
@property(nonatomic, readwrite) ios::ChromeBrowserState* browserState; @property(nonatomic, readwrite) ios::ChromeBrowserState* browserState;
@property(nonatomic, readwrite) BOOL incognito; @property(nonatomic, readwrite) BOOL incognito;
@end @end
......
...@@ -130,6 +130,7 @@ source_set("settings") { ...@@ -130,6 +130,7 @@ source_set("settings") {
"//ios/chrome/browser/feature_engagement", "//ios/chrome/browser/feature_engagement",
"//ios/chrome/browser/history", "//ios/chrome/browser/history",
"//ios/chrome/browser/mailto:feature_flags", "//ios/chrome/browser/mailto:feature_flags",
"//ios/chrome/browser/main",
"//ios/chrome/browser/passwords", "//ios/chrome/browser/passwords",
"//ios/chrome/browser/search_engines", "//ios/chrome/browser/search_engines",
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
...@@ -221,6 +222,7 @@ source_set("test_support") { ...@@ -221,6 +222,7 @@ source_set("test_support") {
"//google_apis", "//google_apis",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/browser_state:test_support", "//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/prefs:browser_prefs", "//ios/chrome/browser/prefs:browser_prefs",
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
"//ios/chrome/browser/signin:test_support", "//ios/chrome/browser/signin:test_support",
...@@ -281,6 +283,7 @@ source_set("unit_tests") { ...@@ -281,6 +283,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/browsing_data:counters", "//ios/chrome/browser/browsing_data:counters",
"//ios/chrome/browser/content_settings", "//ios/chrome/browser/content_settings",
"//ios/chrome/browser/mailto:feature_flags", "//ios/chrome/browser/mailto:feature_flags",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/browser/passwords", "//ios/chrome/browser/passwords",
"//ios/chrome/browser/prefs:browser_prefs", "//ios/chrome/browser/prefs:browser_prefs",
"//ios/chrome/browser/search_engines", "//ios/chrome/browser/search_engines",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
class Browser;
@protocol BrowserCommands; @protocol BrowserCommands;
@protocol ImportDataControllerDelegate; @protocol ImportDataControllerDelegate;
@protocol UserFeedbackDataSource; @protocol UserFeedbackDataSource;
...@@ -54,87 +55,100 @@ extern NSString* const kSettingsDoneButtonId; ...@@ -54,87 +55,100 @@ extern NSString* const kSettingsDoneButtonId;
@interface SettingsNavigationController @interface SettingsNavigationController
: UINavigationController<ApplicationSettingsCommands> : 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. // Creates a new SettingsTableViewController and the chrome around it.
// |browserState| is used to personalize some settings aspects and should not be // |browser| is the browser where settings are being displayed and should not be
// nil nor Off-the-Record. |delegate| may be nil. // nil nor Off-the-Record. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newSettingsMainControllerWithBrowserState:(ios::ChromeBrowserState*)browserState mainSettingsControllerForBrowser:(Browser*)browser
delegate: delegate:(id<SettingsNavigationControllerDelegate>)
(id<SettingsNavigationControllerDelegate>)
delegate; delegate;
// Creates a new AccountsTableViewController and the chrome around it. // Creates a new AccountsTableViewController and the chrome around it.
// |browserState| is used to personalize some settings aspects and should not be // |browser| is the browser where settings are being displayed and should not be
// nil. |delegate| may be nil. // nil. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newAccountsController:(ios::ChromeBrowserState*)browserState accountsControllerForBrowser:(Browser*)browser
delegate:(id<SettingsNavigationControllerDelegate>)delegate; delegate:
(id<SettingsNavigationControllerDelegate>)delegate;
// Creates a new GoogleServicesSettingsCollectionViewController and the chrome // Creates a new GoogleServicesSettingsCollectionViewController and the chrome
// around it. |browserState| is used to personalize some settings aspects and // around it. |browser| is the browser where settings are being displayed and
// should not be nil. |delegate| may be nil. // should not be nil. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newGoogleServicesController:(ios::ChromeBrowserState*)browserState googleServicesControllerForBrowser:(Browser*)browser
delegate: delegate:
(id<SettingsNavigationControllerDelegate>)delegate; (id<SettingsNavigationControllerDelegate>)
delegate;
// Creates a new SyncEncryptionPassphraseCollectionViewController and the chrome // Creates a new SyncEncryptionPassphraseCollectionViewController and the chrome
// around it. |browserState| is used to personalize some settings aspects and // around it. |browser| is the browser where settings are being displayed and
// should not be nil. |delegate| may be nil. // should not be nil. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newSyncEncryptionPassphraseController:(ios::ChromeBrowserState*)browserState syncPassphraseControllerForBrowser:(Browser*)browser
delegate:(id<SettingsNavigationControllerDelegate>) delegate:
delegate; (id<SettingsNavigationControllerDelegate>)
delegate;
// Creates a new SavePasswordsCollectionViewController and the chrome around it. // Creates a new SavePasswordsCollectionViewController and the chrome around it.
// |browserState| is used to personalize some settings aspects and should not be // |browser| is the browser where settings are being displayed and should not be
// nil. |delegate| may be nil. // nil. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newSavePasswordsController:(ios::ChromeBrowserState*)browserState savePasswordsControllerForBrowser:(Browser*)browser
delegate:(id<SettingsNavigationControllerDelegate>)delegate; delegate:(id<SettingsNavigationControllerDelegate>)
delegate;
// Creates and displays a new UIViewController for user to report an issue. // Creates and displays a new UIViewController for user to report an issue.
// |browserState| is used to personalize some settings aspects and should not // |browser| is the browser where settings are being displayed and should not be
// be nil. |dataSource| is used to populate the UIViewController. |dispatcher|, // nil. |dataSource| is used to populate the UIViewController. |dispatcher|,
// which can be nil, is an object that can perform operations for the view // which can be nil, is an object that can perform operations for the view
// controller. |delegate| may be nil. // controller. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newUserFeedbackController:(ios::ChromeBrowserState*)browserState userFeedbackControllerForBrowser:(Browser*)browser
delegate:(id<SettingsNavigationControllerDelegate>)delegate delegate:(id<SettingsNavigationControllerDelegate>)
feedbackDataSource:(id<UserFeedbackDataSource>)dataSource delegate
dispatcher:(id<ApplicationCommands>)dispatcher; feedbackDataSource:(id<UserFeedbackDataSource>)dataSource
dispatcher:(id<ApplicationCommands>)dispatcher;
// Creates and displays a new ImportDataTableViewController. |browserState|
// Creates and displays a new ImportDataTableViewController. |browser|
// should not be nil. // should not be nil.
+ (SettingsNavigationController*) + (instancetype)
newImportDataController:(ios::ChromeBrowserState*)browserState importDataControllerForBrowserState:(ios::ChromeBrowserState*)browserState
delegate:(id<SettingsNavigationControllerDelegate>)delegate delegate:
importDataDelegate:(id<ImportDataControllerDelegate>)importDataDelegate (id<SettingsNavigationControllerDelegate>)
fromEmail:(NSString*)fromEmail delegate
toEmail:(NSString*)toEmail importDataDelegate:
isSignedIn:(BOOL)isSignedIn; (id<ImportDataControllerDelegate>)importDataDelegate
fromEmail:(NSString*)fromEmail
toEmail:(NSString*)toEmail
isSignedIn:(BOOL)isSignedIn;
// Creates a new AutofillProfileTableViewController and the chrome around // Creates a new AutofillProfileTableViewController and the chrome around
// it. |browserState| is used to personalize some settings aspects and should // it. |browser| is the browser where settings are being displayed and should
// not be nil. |delegate| may be nil. // not be nil. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newAutofillProfilleController:(ios::ChromeBrowserState*)browserState autofillProfileControllerForBrowser:(Browser*)browser
delegate: delegate:
(id<SettingsNavigationControllerDelegate>)delegate; (id<SettingsNavigationControllerDelegate>)
delegate;
// Creates a new AutofillCreditCardCollectionViewController and the chrome // Creates a new AutofillCreditCardCollectionViewController and the chrome
// around it. |browserState| is used to personalize some settings aspects and // around it. |browser| is the browser where settings are being displayed and
// should not be nil. |delegate| may be nil. // should not be nil. |delegate| may be nil.
+ (SettingsNavigationController*) + (instancetype)
newAutofillCreditCardController:(ios::ChromeBrowserState*)browserState autofillCreditCardControllerForBrowser:(Browser*)browser
delegate: delegate:
(id<SettingsNavigationControllerDelegate>)delegate; (id<SettingsNavigationControllerDelegate>)
delegate;
// Initializes the UINavigationController with |rootViewController|. // Initializes the UINavigationController with |rootViewController|.
- (instancetype) - (instancetype)
initWithRootViewController:(UIViewController*)rootViewController initWithRootViewController:(UIViewController*)rootViewController
browserState:(ios::ChromeBrowserState*)browserState browserState:(ios::ChromeBrowserState*)browserState
delegate:(id<SettingsNavigationControllerDelegate>)delegate delegate:
(id<SettingsNavigationControllerDelegate>)delegate
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithRootViewController:(UIViewController*)rootViewController - (instancetype)initWithRootViewController:(UIViewController*)rootViewController
...@@ -150,9 +164,6 @@ initWithRootViewController:(UIViewController*)rootViewController ...@@ -150,9 +164,6 @@ initWithRootViewController:(UIViewController*)rootViewController
// owned by SettingsNavigationController. // owned by SettingsNavigationController.
- (UIBarButtonItem*)doneButton; - (UIBarButtonItem*)doneButton;
// Returns the current main browser state.
- (ios::ChromeBrowserState*)mainBrowserState;
// Notifies this |SettingsNavigationController| of a dismissal such // Notifies this |SettingsNavigationController| of a dismissal such
// that it has a possibility to do necessary clean up. // that it has a possibility to do necessary clean up.
- (void)cleanUpSettings; - (void)cleanUpSettings;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_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/browser_state/test_chrome_browser_state_manager.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state_manager.h"
#include "ios/chrome/browser/main/test_browser.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h" #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service.h" #import "ios/chrome/browser/signin/authentication_service.h"
#include "ios/chrome/browser/signin/authentication_service_factory.h" #include "ios/chrome/browser/signin/authentication_service_factory.h"
...@@ -51,6 +52,9 @@ class SettingsNavigationControllerTest : public PlatformTest { ...@@ -51,6 +52,9 @@ class SettingsNavigationControllerTest : public PlatformTest {
ios::TemplateURLServiceFactory::GetInstance(), ios::TemplateURLServiceFactory::GetInstance(),
ios::TemplateURLServiceFactory::GetDefaultFactory()); ios::TemplateURLServiceFactory::GetDefaultFactory());
chrome_browser_state_ = test_cbs_builder.Build(); chrome_browser_state_ = test_cbs_builder.Build();
WebStateList* web_state_list = nullptr;
browser_ = std::make_unique<TestBrowser>(chrome_browser_state_.get(),
web_state_list);
mockDelegate_ = [OCMockObject mockDelegate_ = [OCMockObject
niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)]; niceMockForProtocol:@protocol(SettingsNavigationControllerDelegate)];
...@@ -80,6 +84,7 @@ class SettingsNavigationControllerTest : public PlatformTest { ...@@ -80,6 +84,7 @@ class SettingsNavigationControllerTest : public PlatformTest {
web::WebTaskEnvironment task_environment_; web::WebTaskEnvironment task_environment_;
IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
std::unique_ptr<Browser> browser_;
id mockDelegate_; id mockDelegate_;
NSString* initialValueForSpdyProxyEnabled_; NSString* initialValueForSpdyProxyEnabled_;
}; };
...@@ -90,9 +95,8 @@ TEST_F(SettingsNavigationControllerTest, PopController) { ...@@ -90,9 +95,8 @@ TEST_F(SettingsNavigationControllerTest, PopController) {
@autoreleasepool { @autoreleasepool {
SettingsNavigationController* settingsController = SettingsNavigationController* settingsController =
[SettingsNavigationController [SettingsNavigationController
newSettingsMainControllerWithBrowserState:chrome_browser_state_ mainSettingsControllerForBrowser:browser_.get()
.get() delegate:nil];
delegate:nil];
UIViewController* viewController = UIViewController* viewController =
[[UIViewController alloc] initWithNibName:nil bundle:nil]; [[UIViewController alloc] initWithNibName:nil bundle:nil];
[settingsController pushViewController:viewController animated:NO]; [settingsController pushViewController:viewController animated:NO];
...@@ -112,9 +116,8 @@ TEST_F(SettingsNavigationControllerTest, DontPopRootController) { ...@@ -112,9 +116,8 @@ TEST_F(SettingsNavigationControllerTest, DontPopRootController) {
@autoreleasepool { @autoreleasepool {
SettingsNavigationController* settingsController = SettingsNavigationController* settingsController =
[SettingsNavigationController [SettingsNavigationController
newSettingsMainControllerWithBrowserState:chrome_browser_state_ mainSettingsControllerForBrowser:browser_.get()
.get() delegate:nil];
delegate:nil];
EXPECT_EQ(1U, [[settingsController viewControllers] count]); EXPECT_EQ(1U, [[settingsController viewControllers] count]);
EXPECT_FALSE([settingsController popViewControllerAnimated:NO]); EXPECT_FALSE([settingsController popViewControllerAnimated:NO]);
...@@ -130,9 +133,8 @@ TEST_F(SettingsNavigationControllerTest, ...@@ -130,9 +133,8 @@ TEST_F(SettingsNavigationControllerTest,
@autoreleasepool { @autoreleasepool {
SettingsNavigationController* settingsController = SettingsNavigationController* settingsController =
[SettingsNavigationController [SettingsNavigationController
newSettingsMainControllerWithBrowserState:chrome_browser_state_ mainSettingsControllerForBrowser:browser_.get()
.get() delegate:mockDelegate_];
delegate:mockDelegate_];
UIViewController* viewController = UIViewController* viewController =
[[UIViewController alloc] initWithNibName:nil bundle:nil]; [[UIViewController alloc] initWithNibName:nil bundle:nil];
[settingsController pushViewController:viewController animated:NO]; [settingsController pushViewController:viewController animated:NO];
...@@ -153,9 +155,8 @@ TEST_F(SettingsNavigationControllerTest, ...@@ -153,9 +155,8 @@ TEST_F(SettingsNavigationControllerTest,
@autoreleasepool { @autoreleasepool {
SettingsNavigationController* settingsController = SettingsNavigationController* settingsController =
[SettingsNavigationController [SettingsNavigationController
newSettingsMainControllerWithBrowserState:chrome_browser_state_ mainSettingsControllerForBrowser:browser_.get()
.get() delegate:mockDelegate_];
delegate:mockDelegate_];
EXPECT_EQ(1U, [[settingsController viewControllers] count]); EXPECT_EQ(1U, [[settingsController viewControllers] count]);
[[mockDelegate_ expect] closeSettings]; [[mockDelegate_ expect] closeSettings];
[settingsController popViewControllerOrCloseSettingsAnimated:NO]; [settingsController popViewControllerOrCloseSettingsAnimated:NO];
......
...@@ -9,12 +9,10 @@ ...@@ -9,12 +9,10 @@
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h" #import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
@protocol ApplicationCommands; @protocol ApplicationCommands;
class Browser;
@protocol BrowserCommands; @protocol BrowserCommands;
@protocol SettingsMainPageCommands; @protocol SettingsMainPageCommands;
@class SigninInteractionController; @class SigninInteractionController;
namespace ios {
class ChromeBrowserState;
} // namespace ios
// The accessibility identifier of the settings TableView. // The accessibility identifier of the settings TableView.
extern NSString* const kSettingsTableViewId; extern NSString* const kSettingsTableViewId;
...@@ -40,11 +38,12 @@ extern NSString* const kSettingsVoiceSearchCellId; ...@@ -40,11 +38,12 @@ extern NSString* const kSettingsVoiceSearchCellId;
@property(weak, nonatomic) id<SettingsMainPageCommands> @property(weak, nonatomic) id<SettingsMainPageCommands>
settingsMainPageDispatcher; settingsMainPageDispatcher;
// Initializes a new SettingsTableViewController. |browserState| must not // Initializes a new SettingsTableViewController. |browser| must not
// be nil and must not be an off-the-record browser state. // be nil and must not be associated with an off the record browser state.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState - (instancetype)initWithBrowser:(Browser*)browser
dispatcher:(id<ApplicationCommands, BrowserCommands>) dispatcher:
dispatcher NS_DESIGNATED_INITIALIZER; (id<ApplicationCommands, BrowserCommands>)dispatcher
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style - (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle: appBarStyle:
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#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/main/browser.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/search_engines/search_engine_observer_bridge.h" #include "ios/chrome/browser/search_engines/search_engine_observer_bridge.h"
...@@ -170,7 +171,9 @@ NSString* kDevViewSourceKey = @"DevViewSource"; ...@@ -170,7 +171,9 @@ NSString* kDevViewSourceKey = @"DevViewSource";
SigninPresenter, SigninPresenter,
SigninPromoViewConsumer, SigninPromoViewConsumer,
SyncObserverModelBridge> { SyncObserverModelBridge> {
// The current browser state that hold the settings. Never off the record. // The browser where the settings are being displayed.
Browser* _browser;
// The browser state for |_browser|. Never off the record.
ios::ChromeBrowserState* _browserState; // weak ios::ChromeBrowserState* _browserState; // weak
// Bridge for TemplateURLServiceObserver. // Bridge for TemplateURLServiceObserver.
std::unique_ptr<SearchEngineObserverBridge> _searchEngineObserverBridge; std::unique_ptr<SearchEngineObserverBridge> _searchEngineObserverBridge;
...@@ -244,17 +247,19 @@ NSString* kDevViewSourceKey = @"DevViewSource"; ...@@ -244,17 +247,19 @@ NSString* kDevViewSourceKey = @"DevViewSource";
#pragma mark Initialization #pragma mark Initialization
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState - (instancetype)initWithBrowser:(Browser*)browser
dispatcher:(id<ApplicationCommands, BrowserCommands>) dispatcher:
dispatcher { (id<ApplicationCommands, BrowserCommands>)dispatcher {
DCHECK(!browserState->IsOffTheRecord()); DCHECK(browser);
DCHECK(!browser->GetBrowserState()->IsOffTheRecord());
UITableViewStyle style = base::FeatureList::IsEnabled(kSettingsRefresh) UITableViewStyle style = base::FeatureList::IsEnabled(kSettingsRefresh)
? UITableViewStylePlain ? UITableViewStylePlain
: UITableViewStyleGrouped; : UITableViewStyleGrouped;
self = [super initWithTableViewStyle:style self = [super initWithTableViewStyle:style
appBarStyle:ChromeTableViewControllerStyleNoAppBar]; appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) { if (self) {
_browserState = browserState; _browser = browser;
_browserState = _browser->GetBrowserState();
self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE); self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE);
_searchEngineObserverBridge.reset(new SearchEngineObserverBridge( _searchEngineObserverBridge.reset(new SearchEngineObserverBridge(
self, self,
......
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