Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: ios/chrome/app/main_controller.mm

Issue 2933823002: [ObjC ARC] Converts ios/chrome/app:app_internal to ARC. (Closed)
Patch Set: Rebased Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/app/main_controller.h ('k') | ios/chrome/app/main_controller_private.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/app/main_controller.h" 5 #import "ios/chrome/app/main_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #import <CoreSpotlight/CoreSpotlight.h> 10 #import <CoreSpotlight/CoreSpotlight.h>
11 #import <objc/objc.h> 11 #import <objc/objc.h>
12 #import <objc/runtime.h> 12 #import <objc/runtime.h>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback_helpers.h" 15 #include "base/callback_helpers.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/ios/block_types.h" 17 #include "base/ios/block_types.h"
18 #import "base/mac/bind_objc_block.h" 18 #import "base/mac/bind_objc_block.h"
19 #include "base/mac/bundle_locations.h" 19 #include "base/mac/bundle_locations.h"
20 #include "base/mac/foundation_util.h" 20 #include "base/mac/foundation_util.h"
21 #include "base/mac/objc_property_releaser.h"
22 #import "base/mac/scoped_nsobject.h"
23 #include "base/macros.h" 21 #include "base/macros.h"
24 #include "base/path_service.h" 22 #include "base/path_service.h"
25 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
26 #include "base/task_scheduler/post_task.h" 24 #include "base/task_scheduler/post_task.h"
27 #include "base/time/time.h" 25 #include "base/time/time.h"
28 #include "components/component_updater/component_updater_service.h" 26 #include "components/component_updater/component_updater_service.h"
29 #include "components/content_settings/core/browser/host_content_settings_map.h" 27 #include "components/content_settings/core/browser/host_content_settings_map.h"
30 #include "components/metrics/metrics_pref_names.h" 28 #include "components/metrics/metrics_pref_names.h"
31 #include "components/metrics/metrics_service.h" 29 #include "components/metrics/metrics_service.h"
32 #include "components/prefs/pref_change_registrar.h" 30 #include "components/prefs/pref_change_registrar.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 #include "ios/web/net/web_http_protocol_handler_delegate.h" 139 #include "ios/web/net/web_http_protocol_handler_delegate.h"
142 #import "ios/web/public/navigation_manager.h" 140 #import "ios/web/public/navigation_manager.h"
143 #include "ios/web/public/web_capabilities.h" 141 #include "ios/web/public/web_capabilities.h"
144 #include "ios/web/public/web_state/web_state.h" 142 #include "ios/web/public/web_state/web_state.h"
145 #import "ios/web/public/web_view_creation_util.h" 143 #import "ios/web/public/web_view_creation_util.h"
146 #include "ios/web/public/webui/web_ui_ios_controller_factory.h" 144 #include "ios/web/public/webui/web_ui_ios_controller_factory.h"
147 #include "mojo/edk/embedder/embedder.h" 145 #include "mojo/edk/embedder/embedder.h"
148 #import "net/base/mac/url_conversions.h" 146 #import "net/base/mac/url_conversions.h"
149 #include "net/url_request/url_request_context.h" 147 #include "net/url_request/url_request_context.h"
150 148
149 #if !defined(__has_feature) || !__has_feature(objc_arc)
150 #error "This file requires ARC support."
151 #endif
152
151 namespace { 153 namespace {
152 154
153 // Preference key used to store which profile is current. 155 // Preference key used to store which profile is current.
154 NSString* kIncognitoCurrentKey = @"IncognitoActive"; 156 NSString* kIncognitoCurrentKey = @"IncognitoActive";
155 157
156 // Constants for deferred initialization of preferences observer. 158 // Constants for deferred initialization of preferences observer.
157 NSString* const kPrefObserverInit = @"PrefObserverInit"; 159 NSString* const kPrefObserverInit = @"PrefObserverInit";
158 160
159 // Constants for deferring notifying the AuthenticationService of a new cold 161 // Constants for deferring notifying the AuthenticationService of a new cold
160 // start. 162 // start.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 237
236 // Weak; owned by the ChromeBrowserProvider. 238 // Weak; owned by the ChromeBrowserProvider.
237 ios::ChromeBrowserStateManager* _browserStateManager; 239 ios::ChromeBrowserStateManager* _browserStateManager;
238 240
239 // The object that drives the Chrome startup/shutdown logic. 241 // The object that drives the Chrome startup/shutdown logic.
240 std::unique_ptr<IOSChromeMain> _chromeMain; 242 std::unique_ptr<IOSChromeMain> _chromeMain;
241 243
242 // The ChromeBrowserState associated with the main (non-OTR) browsing mode. 244 // The ChromeBrowserState associated with the main (non-OTR) browsing mode.
243 ios::ChromeBrowserState* _mainBrowserState; // Weak. 245 ios::ChromeBrowserState* _mainBrowserState; // Weak.
244 246
245 // Coordinators used to run the Chrome UI; there will be one of these active
246 // at any given time, usually |_mainCoordinator|.
247 // Main coordinator, backing object for the property of the same name, which
248 // lazily initializes on access.
249 base::scoped_nsobject<MainCoordinator> _mainCoordinator;
250
251 // Wrangler to handle BVC and tab model creation, access, and related logic. 247 // Wrangler to handle BVC and tab model creation, access, and related logic.
252 // Implements faetures exposed from this object through the 248 // Implements faetures exposed from this object through the
253 // BrowserViewInformation protocol. 249 // BrowserViewInformation protocol.
254 base::scoped_nsobject<BrowserViewWrangler> _browserViewWrangler; 250 BrowserViewWrangler* _browserViewWrangler;
255 251
256 // Parameters received at startup time when the app is launched from another 252 // Parameters received at startup time when the app is launched from another
257 // app. 253 // app.
258 base::scoped_nsobject<AppStartupParameters> _startupParameters; 254 AppStartupParameters* _startupParameters;
259 255
260 // Navigation View controller for the settings. 256 // Navigation View controller for the settings.
261 base::scoped_nsobject<SettingsNavigationController> 257 SettingsNavigationController* _settingsNavigationController;
262 _settingsNavigationController;
263 258
264 // View controller for switching tabs. 259 // View controller for switching tabs.
265 base::scoped_nsobject<UIViewController<TabSwitcher>> _tabSwitcherController; 260 UIViewController<TabSwitcher>* _tabSwitcherController;
266 261
267 // Controller to display the re-authentication flow. 262 // Controller to display the re-authentication flow.
268 base::scoped_nsobject<SigninInteractionController> 263 SigninInteractionController* _signinInteractionController;
269 _signinInteractionController;
270 264
271 // YES while animating the dismissal of stack view. 265 // YES while animating the dismissal of stack view.
272 BOOL _dismissingStackView; 266 BOOL _dismissingStackView;
273 267
274 // If not NONE, the current BVC should be switched to this BVC on completion 268 // If not NONE, the current BVC should be switched to this BVC on completion
275 // of stack view dismissal. 269 // of stack view dismissal.
276 StackViewDismissalMode _modeToDisplayOnStackViewDismissal; 270 StackViewDismissalMode _modeToDisplayOnStackViewDismissal;
277 271
278 // If YES, the tab switcher is currently active. 272 // If YES, the tab switcher is currently active.
279 BOOL _tabSwitcherIsActive; 273 BOOL _tabSwitcherIsActive;
280 274
281 // True if the current session began from a cold start. False if the app has 275 // True if the current session began from a cold start. False if the app has
282 // entered the background at least once since start up. 276 // entered the background at least once since start up.
283 BOOL _isColdStart; 277 BOOL _isColdStart;
284 278
285 // Keeps track of the restore state during startup. 279 // Keeps track of the restore state during startup.
286 base::scoped_nsobject<CrashRestoreHelper> _restoreHelper; 280 CrashRestoreHelper* _restoreHelper;
287 281
288 // An object to record metrics related to the user's first action. 282 // An object to record metrics related to the user's first action.
289 std::unique_ptr<FirstUserActionRecorder> _firstUserActionRecorder; 283 std::unique_ptr<FirstUserActionRecorder> _firstUserActionRecorder;
290 284
291 // RequestTrackerFactory to customize the behavior of the network stack. 285 // RequestTrackerFactory to customize the behavior of the network stack.
292 std::unique_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory; 286 std::unique_ptr<web::RequestTrackerFactoryImpl> _requestTrackerFactory;
293 287
294 // Configuration for the HTTP protocol handler. 288 // Configuration for the HTTP protocol handler.
295 std::unique_ptr<web::WebHTTPProtocolHandlerDelegate> 289 std::unique_ptr<web::WebHTTPProtocolHandlerDelegate>
296 _httpProtocolHandlerDelegate; 290 _httpProtocolHandlerDelegate;
(...skipping 14 matching lines...) Expand all
311 BOOL _isProcessingTabSwitcherCommand; 305 BOOL _isProcessingTabSwitcherCommand;
312 BOOL _isProcessingVoiceSearchCommand; 306 BOOL _isProcessingVoiceSearchCommand;
313 307
314 // Bridge to listen to pref changes. 308 // Bridge to listen to pref changes.
315 std::unique_ptr<PrefObserverBridge> _localStatePrefObserverBridge; 309 std::unique_ptr<PrefObserverBridge> _localStatePrefObserverBridge;
316 310
317 // Registrar for pref changes notifications to the local state. 311 // Registrar for pref changes notifications to the local state.
318 PrefChangeRegistrar _localStatePrefChangeRegistrar; 312 PrefChangeRegistrar _localStatePrefChangeRegistrar;
319 313
320 // Clears browsing data from ChromeBrowserStates. 314 // Clears browsing data from ChromeBrowserStates.
321 base::scoped_nsobject<BrowsingDataRemovalController> 315 BrowsingDataRemovalController* _browsingDataRemovalController;
322 _browsingDataRemovalController;
323 316
324 // The class in charge of showing/hiding the memory debugger when the 317 // The class in charge of showing/hiding the memory debugger when the
325 // appropriate pref changes. 318 // appropriate pref changes.
326 base::scoped_nsobject<MemoryDebuggerManager> _memoryDebuggerManager; 319 MemoryDebuggerManager* _memoryDebuggerManager;
327
328 base::mac::ObjCPropertyReleaser _propertyReleaser_MainController;
329 320
330 // Responsible for indexing chrome links (such as bookmarks, most likely...) 321 // Responsible for indexing chrome links (such as bookmarks, most likely...)
331 // in system Spotlight index. 322 // in system Spotlight index.
332 base::scoped_nsobject<SpotlightManager> _spotlightManager; 323 SpotlightManager* _spotlightManager;
333 324
334 // Cached launchOptions from -didFinishLaunchingWithOptions. 325 // Cached launchOptions from -didFinishLaunchingWithOptions.
335 base::scoped_nsobject<NSDictionary> _launchOptions; 326 NSDictionary* _launchOptions;
336 327
337 // View controller for displaying the history panel. 328 // View controller for displaying the history panel.
338 base::scoped_nsobject<UIViewController> _historyPanelViewController; 329 UIViewController* _historyPanelViewController;
339 330
340 // Variable backing metricsMediator property. 331 // Variable backing metricsMediator property.
341 base::WeakNSObject<MetricsMediator> _metricsMediator; 332 __weak MetricsMediator* _metricsMediator;
342 333
343 // Hander for the startup tasks, deferred or not. 334 // Hander for the startup tasks, deferred or not.
344 base::scoped_nsobject<StartupTasks> _startupTasks; 335 StartupTasks* _startupTasks;
345 } 336 }
346 337
347 // Pointer to the main view controller, always owned by the main window. 338 // Pointer to the main view controller, always owned by the main window.
348 @property(nonatomic, readonly) MainViewController* mainViewController; 339 @property(weak, nonatomic, readonly) MainViewController* mainViewController;
349 340
350 // The main coordinator, lazily created the first time it is accessed. Manages 341 // The main coordinator, lazily created the first time it is accessed. Manages
351 // the MainViewController. This property should not be accessed before the 342 // the MainViewController. This property should not be accessed before the
352 // browser has started up to the FOREGROUND stage. 343 // browser has started up to the FOREGROUND stage.
353 @property(nonatomic, readonly) MainCoordinator* mainCoordinator; 344 @property(nonatomic, readonly) MainCoordinator* mainCoordinator;
354 345
355 // A property to track whether the QR Scanner should be started upon tab 346 // A property to track whether the QR Scanner should be started upon tab
356 // switcher dismissal. It can only be YES if the QR Scanner experiment is 347 // switcher dismissal. It can only be YES if the QR Scanner experiment is
357 // enabled. 348 // enabled.
358 @property(nonatomic, readwrite) BOOL startQRScannerAfterTabSwitcherDismissal; 349 @property(nonatomic, readwrite) BOOL startQRScannerAfterTabSwitcherDismissal;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Initializes the application to INITIALIZATION_STAGE_BACKGROUND, which is 512 // Initializes the application to INITIALIZATION_STAGE_BACKGROUND, which is
522 // needed by background handlers. 513 // needed by background handlers.
523 - (void)startUpBrowserBackgroundInitialization; 514 - (void)startUpBrowserBackgroundInitialization;
524 // Initializes the application to INITIALIZATION_STAGE_FOREGROUND, which is 515 // Initializes the application to INITIALIZATION_STAGE_FOREGROUND, which is
525 // needed when application runs in foreground. 516 // needed when application runs in foreground.
526 - (void)startUpBrowserForegroundInitialization; 517 - (void)startUpBrowserForegroundInitialization;
527 @end 518 @end
528 519
529 @implementation MainController 520 @implementation MainController
530 521
522 @synthesize mainCoordinator = _mainCoordinator;
531 @synthesize appState = _appState; 523 @synthesize appState = _appState;
532 @synthesize appLaunchTime = _appLaunchTime; 524 @synthesize appLaunchTime = _appLaunchTime;
533 @synthesize browserInitializationStage = _browserInitializationStage; 525 @synthesize browserInitializationStage = _browserInitializationStage;
534 @synthesize window = _window; 526 @synthesize window = _window;
535 @synthesize isPresentingFirstRunUI = _isPresentingFirstRunUI; 527 @synthesize isPresentingFirstRunUI = _isPresentingFirstRunUI;
536 @synthesize isColdStart = _isColdStart; 528 @synthesize isColdStart = _isColdStart;
537 @synthesize startVoiceSearchAfterTabSwitcherDismissal = 529 @synthesize startVoiceSearchAfterTabSwitcherDismissal =
538 _startVoiceSearchAfterTabSwitcherDismissal; 530 _startVoiceSearchAfterTabSwitcherDismissal;
539 @synthesize startQRScannerAfterTabSwitcherDismissal = 531 @synthesize startQRScannerAfterTabSwitcherDismissal =
540 _startQRScannerAfterTabSwitcherDismissal; 532 _startQRScannerAfterTabSwitcherDismissal;
541 @synthesize startFocusOmniboxAfterTabSwitcherDismissal = 533 @synthesize startFocusOmniboxAfterTabSwitcherDismissal =
542 _startFocusOmniboxAfterTabSwitcherDismissal; 534 _startFocusOmniboxAfterTabSwitcherDismissal;
535 @synthesize launchOptions = _launchOptions;
536 @synthesize startupParameters = _startupParameters;
537 @synthesize metricsMediator = _metricsMediator;
538 @synthesize settingsNavigationController = _settingsNavigationController;
543 539
544 #pragma mark - Application lifecycle 540 #pragma mark - Application lifecycle
545 541
546 - (instancetype)init { 542 - (instancetype)init {
547 if ((self = [super init])) { 543 if ((self = [super init])) {
548 _propertyReleaser_MainController.Init(self, [MainController class]); 544 _startupTasks = [[StartupTasks alloc] init];
549 _startupTasks.reset([[StartupTasks alloc] init]);
550 } 545 }
551 return self; 546 return self;
552 } 547 }
553 548
554 - (void)dealloc { 549 - (void)dealloc {
555 [[NSNotificationCenter defaultCenter] removeObserver:self]; 550 [[NSNotificationCenter defaultCenter] removeObserver:self];
556 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); 551 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr);
557 net::RequestTracker::SetRequestTrackerFactory(nullptr); 552 net::RequestTracker::SetRequestTrackerFactory(nullptr);
558 [NSObject cancelPreviousPerformRequestsWithTarget:self]; 553 [NSObject cancelPreviousPerformRequestsWithTarget:self];
559 [super dealloc];
560 } 554 }
561 555
562 // This function starts up to only what is needed at each stage of the 556 // This function starts up to only what is needed at each stage of the
563 // initialization. It is possible to continue initialization later. 557 // initialization. It is possible to continue initialization later.
564 - (void)startUpBrowserToStage:(BrowserInitializationStageType)stage { 558 - (void)startUpBrowserToStage:(BrowserInitializationStageType)stage {
565 if (_browserInitializationStage < INITIALIZATION_STAGE_BASIC && 559 if (_browserInitializationStage < INITIALIZATION_STAGE_BASIC &&
566 stage >= INITIALIZATION_STAGE_BASIC) { 560 stage >= INITIALIZATION_STAGE_BASIC) {
567 [self startUpBrowserBasicInitialization]; 561 [self startUpBrowserBasicInitialization];
568 _browserInitializationStage = INITIALIZATION_STAGE_BASIC; 562 _browserInitializationStage = INITIALIZATION_STAGE_BASIC;
569 } 563 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 _browserStateManager = 665 _browserStateManager =
672 GetApplicationContext()->GetChromeBrowserStateManager(); 666 GetApplicationContext()->GetChromeBrowserStateManager();
673 ios::ChromeBrowserState* chromeBrowserState = 667 ios::ChromeBrowserState* chromeBrowserState =
674 _browserStateManager->GetLastUsedBrowserState(); 668 _browserStateManager->GetLastUsedBrowserState();
675 669
676 // The CrashRestoreHelper must clean up the old browser state information 670 // The CrashRestoreHelper must clean up the old browser state information
677 // before the tabModels can be created. |_restoreHelper| must be kept alive 671 // before the tabModels can be created. |_restoreHelper| must be kept alive
678 // until the BVC receives the browser state and tab model. 672 // until the BVC receives the browser state and tab model.
679 BOOL postCrashLaunch = [self mustShowRestoreInfobar]; 673 BOOL postCrashLaunch = [self mustShowRestoreInfobar];
680 if (postCrashLaunch) { 674 if (postCrashLaunch) {
681 _restoreHelper.reset( 675 _restoreHelper =
682 [[CrashRestoreHelper alloc] initWithBrowserState:chromeBrowserState]); 676 [[CrashRestoreHelper alloc] initWithBrowserState:chromeBrowserState];
683 [_restoreHelper moveAsideSessionInformation]; 677 [_restoreHelper moveAsideSessionInformation];
684 } 678 }
685 679
686 // Initialize and set the main browser state. 680 // Initialize and set the main browser state.
687 [self initializeBrowserState:chromeBrowserState]; 681 [self initializeBrowserState:chromeBrowserState];
688 _mainBrowserState = chromeBrowserState; 682 _mainBrowserState = chromeBrowserState;
689 [_browserViewWrangler shutdown]; 683 [_browserViewWrangler shutdown];
690 _browserViewWrangler.reset([[BrowserViewWrangler alloc] 684 _browserViewWrangler =
691 initWithBrowserState:_mainBrowserState 685 [[BrowserViewWrangler alloc] initWithBrowserState:_mainBrowserState
692 tabModelObserver:self]); 686 tabModelObserver:self];
693 // Ensure the main tab model is created. 687 // Ensure the main tab model is created.
694 ignore_result([_browserViewWrangler mainTabModel]); 688 ignore_result([_browserViewWrangler mainTabModel]);
695 689
696 _spotlightManager.reset([[SpotlightManager 690 _spotlightManager =
697 spotlightManagerWithBrowserState:_mainBrowserState] retain]); 691 [SpotlightManager spotlightManagerWithBrowserState:_mainBrowserState];
698 692
699 ShareExtensionService* service = 693 ShareExtensionService* service =
700 ShareExtensionServiceFactory::GetForBrowserState(_mainBrowserState); 694 ShareExtensionServiceFactory::GetForBrowserState(_mainBrowserState);
701 service->Initialize(); 695 service->Initialize();
702 696
703 // Before bringing up the UI, make sure the launch mode is correct, and 697 // Before bringing up the UI, make sure the launch mode is correct, and
704 // check for previous crashes. 698 // check for previous crashes.
705 BOOL startInIncognito = [standardDefaults boolForKey:kIncognitoCurrentKey]; 699 BOOL startInIncognito = [standardDefaults boolForKey:kIncognitoCurrentKey];
706 BOOL switchFromIncognito = startInIncognito && ![self canLaunchInIncognito]; 700 BOOL switchFromIncognito = startInIncognito && ![self canLaunchInIncognito];
707 701
(...skipping 14 matching lines...) Expand all
722 [MetricsMediator logLaunchMetricsWithStartupInformation:self 716 [MetricsMediator logLaunchMetricsWithStartupInformation:self
723 browserViewInformation:_browserViewWrangler]; 717 browserViewInformation:_browserViewWrangler];
724 718
725 [self scheduleLowPriorityStartupTasks]; 719 [self scheduleLowPriorityStartupTasks];
726 720
727 [_browserViewWrangler updateDeviceSharingManager]; 721 [_browserViewWrangler updateDeviceSharingManager];
728 722
729 [self openTabFromLaunchOptions:_launchOptions 723 [self openTabFromLaunchOptions:_launchOptions
730 startupInformation:self 724 startupInformation:self
731 appState:self.appState]; 725 appState:self.appState];
732 _launchOptions.reset(); 726 _launchOptions = nil;
733 727
734 mojo::edk::Init(); 728 mojo::edk::Init();
735 729
736 if (!_startupParameters) { 730 if (!_startupParameters) {
737 // The startup parameters may create new tabs or navigations. If the restore 731 // The startup parameters may create new tabs or navigations. If the restore
738 // infobar is displayed now, it may be dismissed immediately and the user 732 // infobar is displayed now, it may be dismissed immediately and the user
739 // will never be able to restore the session. 733 // will never be able to restore the session.
740 [_restoreHelper showRestoreIfNeeded:[self currentTabModel]]; 734 [_restoreHelper showRestoreIfNeeded:[self currentTabModel]];
741 _restoreHelper.reset(); 735 _restoreHelper = nil;
742 } 736 }
743 737
744 [self scheduleTasksRequiringBVCWithBrowserState]; 738 [self scheduleTasksRequiringBVCWithBrowserState];
745 739
746 // Now that everything is properly set up, run the tests. 740 // Now that everything is properly set up, run the tests.
747 tests_hook::RunTestsIfPresent(); 741 tests_hook::RunTestsIfPresent();
748 } 742 }
749 743
750 - (void)initializeBrowserState:(ios::ChromeBrowserState*)browserState { 744 - (void)initializeBrowserState:(ios::ChromeBrowserState*)browserState {
751 DCHECK(!browserState->IsOffTheRecord()); 745 DCHECK(!browserState->IsOffTheRecord());
752 search_engines::UpdateSearchEnginesIfNeeded( 746 search_engines::UpdateSearchEnginesIfNeeded(
753 browserState->GetPrefs(), 747 browserState->GetPrefs(),
754 ios::TemplateURLServiceFactory::GetForBrowserState(browserState)); 748 ios::TemplateURLServiceFactory::GetForBrowserState(browserState));
755 749
756 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { 750 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) {
757 base::scoped_nsobject<TouchToSearchPermissionsMediator> 751 TouchToSearchPermissionsMediator* touchToSearchPermissions =
758 touchToSearchPermissions([[TouchToSearchPermissionsMediator alloc] 752 [[TouchToSearchPermissionsMediator alloc]
759 initWithBrowserState:browserState]); 753 initWithBrowserState:browserState];
760 if (experimental_flags::IsForceResetContextualSearchEnabled()) { 754 if (experimental_flags::IsForceResetContextualSearchEnabled()) {
761 [touchToSearchPermissions setPreferenceState:TouchToSearch::UNDECIDED]; 755 [touchToSearchPermissions setPreferenceState:TouchToSearch::UNDECIDED];
762 } 756 }
763 ContextualSearch::RecordPreferenceState( 757 ContextualSearch::RecordPreferenceState(
764 [touchToSearchPermissions preferenceState]); 758 [touchToSearchPermissions preferenceState]);
765 } 759 }
766 } 760 }
767 761
768 - (void)handleFirstRunUIWillFinish { 762 - (void)handleFirstRunUIWillFinish {
769 DCHECK(_isPresentingFirstRunUI); 763 DCHECK(_isPresentingFirstRunUI);
770 _isPresentingFirstRunUI = NO; 764 _isPresentingFirstRunUI = NO;
771 [[NSNotificationCenter defaultCenter] 765 [[NSNotificationCenter defaultCenter]
772 removeObserver:self 766 removeObserver:self
773 name:kChromeFirstRunUIWillFinishNotification 767 name:kChromeFirstRunUIWillFinishNotification
774 object:nil]; 768 object:nil];
775 769
776 [self markEulaAsAccepted]; 770 [self markEulaAsAccepted];
777 771
778 if (_startupParameters.get()) { 772 if (_startupParameters) {
779 [self dismissModalsAndOpenSelectedTabInMode:ApplicationMode::NORMAL 773 [self dismissModalsAndOpenSelectedTabInMode:ApplicationMode::NORMAL
780 withURL:[_startupParameters externalURL] 774 withURL:[_startupParameters externalURL]
781 transition:ui::PAGE_TRANSITION_LINK 775 transition:ui::PAGE_TRANSITION_LINK
782 completion:nil]; 776 completion:nil];
783 _startupParameters.reset(); 777 _startupParameters = nil;
784 } 778 }
785 } 779 }
786 780
787 - (void)handleFirstRunUIDidFinish { 781 - (void)handleFirstRunUIDidFinish {
788 [[NSNotificationCenter defaultCenter] 782 [[NSNotificationCenter defaultCenter]
789 removeObserver:self 783 removeObserver:self
790 name:kChromeFirstRunUIDidFinishNotification 784 name:kChromeFirstRunUIDidFinishNotification
791 object:nil]; 785 object:nil];
792 786
793 // As soon as First Run has finished, give OmniboxGeolocationController an 787 // As soon as First Run has finished, give OmniboxGeolocationController an
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 } 824 }
831 825
832 // Always set the new otr tab model on iPad with tab switcher enabled. 826 // Always set the new otr tab model on iPad with tab switcher enabled.
833 // Notify the _tabSwitcherController with the new otrBVC. 827 // Notify the _tabSwitcherController with the new otrBVC.
834 if (IsIPadIdiom() || _tabSwitcherIsActive) 828 if (IsIPadIdiom() || _tabSwitcherIsActive)
835 [_tabSwitcherController setOtrTabModel:self.otrTabModel]; 829 [_tabSwitcherController setOtrTabModel:self.otrTabModel];
836 } 830 }
837 831
838 - (BrowsingDataRemovalController*)browsingDataRemovalController { 832 - (BrowsingDataRemovalController*)browsingDataRemovalController {
839 if (!_browsingDataRemovalController) { 833 if (!_browsingDataRemovalController) {
840 _browsingDataRemovalController.reset( 834 _browsingDataRemovalController =
841 [[BrowsingDataRemovalController alloc] initWithDelegate:self]); 835 [[BrowsingDataRemovalController alloc] initWithDelegate:self];
842 } 836 }
843 return _browsingDataRemovalController; 837 return _browsingDataRemovalController;
844 } 838 }
845 839
846 - (void)setWebUsageEnabled:(BOOL)enabled { 840 - (void)setWebUsageEnabled:(BOOL)enabled {
847 DCHECK([NSThread isMainThread]); 841 DCHECK([NSThread isMainThread]);
848 if (enabled) { 842 if (enabled) {
849 [self activateBVCAndMakeCurrentBVCPrimary]; 843 [self activateBVCAndMakeCurrentBVCPrimary];
850 } else { 844 } else {
851 [self.mainBVC setActive:NO]; 845 [self.mainBVC setActive:NO];
852 [self.otrBVC setActive:NO]; 846 [self.otrBVC setActive:NO];
853 } 847 }
854 } 848 }
855 849
856 - (void)activateBVCAndMakeCurrentBVCPrimary { 850 - (void)activateBVCAndMakeCurrentBVCPrimary {
857 // If there are pending removal operations, the activation will be deferred 851 // If there are pending removal operations, the activation will be deferred
858 // until the callback for |removeBrowsingDataFromBrowserState:| is received. 852 // until the callback for |removeBrowsingDataFromBrowserState:| is received.
859 if (![self.browsingDataRemovalController 853 if (![self.browsingDataRemovalController
860 hasPendingRemovalOperations:self.currentBrowserState]) { 854 hasPendingRemovalOperations:self.currentBrowserState]) {
861 [self.mainBVC setActive:YES]; 855 [self.mainBVC setActive:YES];
862 [self.otrBVC setActive:YES]; 856 [self.otrBVC setActive:YES];
863 857
864 [self.currentBVC setPrimary:YES]; 858 [self.currentBVC setPrimary:YES];
865 } 859 }
866 } 860 }
867 861
868 #pragma mark - BrowserLauncher implementation.
869
870 - (NSDictionary*)launchOptions {
871 return _launchOptions;
872 }
873
874 - (void)setLaunchOptions:(NSDictionary*)launchOptions {
875 _launchOptions.reset([launchOptions retain]);
876 }
877
878 #pragma mark - Property implementation. 862 #pragma mark - Property implementation.
879 863
880 - (id<BrowserViewInformation>)browserViewInformation { 864 - (id<BrowserViewInformation>)browserViewInformation {
881 return _browserViewWrangler; 865 return _browserViewWrangler;
882 } 866 }
883 867
884 - (AppStartupParameters*)startupParameters {
885 return _startupParameters;
886 }
887
888 - (void)setStartupParameters:(AppStartupParameters*)startupParameters {
889 _startupParameters.reset([startupParameters retain]);
890 }
891
892 - (MainViewController*)mainViewController { 868 - (MainViewController*)mainViewController {
893 return self.mainCoordinator.mainViewController; 869 return self.mainCoordinator.mainViewController;
894 } 870 }
895 871
896 - (MainCoordinator*)mainCoordinator { 872 - (MainCoordinator*)mainCoordinator {
897 if (_browserInitializationStage == INITIALIZATION_STAGE_BASIC) { 873 if (_browserInitializationStage == INITIALIZATION_STAGE_BASIC) {
898 NOTREACHED() << "mainCoordinator accessed too early in initialization."; 874 NOTREACHED() << "mainCoordinator accessed too early in initialization.";
899 return nil; 875 return nil;
900 } 876 }
901 if (!_mainCoordinator) { 877 if (!_mainCoordinator) {
902 // Lazily create the main coordinator. 878 // Lazily create the main coordinator.
903 _mainCoordinator.reset( 879 _mainCoordinator = [[MainCoordinator alloc] initWithWindow:self.window];
904 [[MainCoordinator alloc] initWithWindow:self.window]);
905 } 880 }
906 return _mainCoordinator; 881 return _mainCoordinator;
907 } 882 }
908 883
909 - (BOOL)isFirstLaunchAfterUpgrade { 884 - (BOOL)isFirstLaunchAfterUpgrade {
910 return [[PreviousSessionInfo sharedInstance] isFirstSessionAfterUpgrade]; 885 return [[PreviousSessionInfo sharedInstance] isFirstSessionAfterUpgrade];
911 } 886 }
912 887
913 - (MetricsMediator*)metricsMediator {
914 return _metricsMediator;
915 }
916
917 - (void)setMetricsMediator:(MetricsMediator*)metricsMediator {
918 _metricsMediator.reset(metricsMediator);
919 }
920
921 - (SettingsNavigationController*)settingsNavigationController {
922 return _settingsNavigationController;
923 }
924
925 - (void)setSettingsNavigationController:
926 (SettingsNavigationController*)settingsNavigationController {
927 _settingsNavigationController.reset([settingsNavigationController retain]);
928 }
929
930 #pragma mark - StartupInformation implementation. 888 #pragma mark - StartupInformation implementation.
931 889
932 - (FirstUserActionRecorder*)firstUserActionRecorder { 890 - (FirstUserActionRecorder*)firstUserActionRecorder {
933 return _firstUserActionRecorder.get(); 891 return _firstUserActionRecorder.get();
934 } 892 }
935 893
936 - (void)resetFirstUserActionRecorder { 894 - (void)resetFirstUserActionRecorder {
937 _firstUserActionRecorder.reset(); 895 _firstUserActionRecorder.reset();
938 } 896 }
939 897
940 - (void)expireFirstUserActionRecorderAfterDelay:(NSTimeInterval)delay { 898 - (void)expireFirstUserActionRecorderAfterDelay:(NSTimeInterval)delay {
941 [self performSelector:@selector(expireFirstUserActionRecorder) 899 [self performSelector:@selector(expireFirstUserActionRecorder)
942 withObject:nil 900 withObject:nil
943 afterDelay:delay]; 901 afterDelay:delay];
944 } 902 }
945 903
946 - (void)activateFirstUserActionRecorderWithBackgroundTime: 904 - (void)activateFirstUserActionRecorderWithBackgroundTime:
947 (NSTimeInterval)backgroundTime { 905 (NSTimeInterval)backgroundTime {
948 base::TimeDelta delta = base::TimeDelta::FromSeconds(backgroundTime); 906 base::TimeDelta delta = base::TimeDelta::FromSeconds(backgroundTime);
949 _firstUserActionRecorder.reset(new FirstUserActionRecorder(delta)); 907 _firstUserActionRecorder.reset(new FirstUserActionRecorder(delta));
950 } 908 }
951 909
952 - (void)stopChromeMain { 910 - (void)stopChromeMain {
953 [_spotlightManager shutdown]; 911 [_spotlightManager shutdown];
954 _spotlightManager.reset(); 912 _spotlightManager = nil;
955 913
956 [_browserViewWrangler shutdown]; 914 [_browserViewWrangler shutdown];
957 _browserViewWrangler.reset(); 915 _browserViewWrangler = nil;
958 916
959 _chromeMain.reset(); 917 _chromeMain.reset();
960 } 918 }
961 919
962 - (BOOL)isTabSwitcherActive { 920 - (BOOL)isTabSwitcherActive {
963 return _tabSwitcherIsActive; 921 return _tabSwitcherIsActive;
964 } 922 }
965 923
966 #pragma mark - BrowserViewInformation implementation. 924 #pragma mark - BrowserViewInformation implementation.
967 925
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 if (![self mustShowRestoreInfobar]) { 1105 if (![self mustShowRestoreInfobar]) {
1148 [self scheduleSnapshotPurge]; 1106 [self scheduleSnapshotPurge];
1149 } 1107 }
1150 } 1108 }
1151 1109
1152 - (void)scheduleMemoryDebuggingTools { 1110 - (void)scheduleMemoryDebuggingTools {
1153 if (experimental_flags::IsMemoryDebuggingEnabled()) { 1111 if (experimental_flags::IsMemoryDebuggingEnabled()) {
1154 [[DeferredInitializationRunner sharedInstance] 1112 [[DeferredInitializationRunner sharedInstance]
1155 enqueueBlockNamed:kMemoryDebuggingToolsStartup 1113 enqueueBlockNamed:kMemoryDebuggingToolsStartup
1156 block:^{ 1114 block:^{
1157 _memoryDebuggerManager.reset( 1115 _memoryDebuggerManager = [[MemoryDebuggerManager alloc]
1158 [[MemoryDebuggerManager alloc] 1116 initWithView:self.window
1159 initWithView:self.window 1117 prefs:GetApplicationContext()
1160 prefs:GetApplicationContext() 1118 ->GetLocalState()];
1161 ->GetLocalState()]);
1162 }]; 1119 }];
1163 } 1120 }
1164 } 1121 }
1165 1122
1166 - (void)startFreeMemoryMonitoring { 1123 - (void)startFreeMemoryMonitoring {
1167 base::PostTaskWithTraits( 1124 base::PostTaskWithTraits(
1168 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, 1125 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND},
1169 base::BindOnce(&ios_internal::AsynchronousFreeMemoryMonitor)); 1126 base::BindOnce(&ios_internal::AsynchronousFreeMemoryMonitor));
1170 } 1127 }
1171 1128
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 } 1243 }
1287 if (_tabSwitcherIsActive) 1244 if (_tabSwitcherIsActive)
1288 [self dismissTabSwitcherWithoutAnimationInModel:self.mainTabModel]; 1245 [self dismissTabSwitcherWithoutAnimationInModel:self.mainTabModel];
1289 if (firstRun || [self shouldOpenNTPTabOnActivationOfTabModel:tabModel]) { 1246 if (firstRun || [self shouldOpenNTPTabOnActivationOfTabModel:tabModel]) {
1290 [self.currentBVC newTab:nil]; 1247 [self.currentBVC newTab:nil];
1291 } 1248 }
1292 1249
1293 if (firstRun) { 1250 if (firstRun) {
1294 [self showFirstRunUI]; 1251 [self showFirstRunUI];
1295 // Do not ever show the 'restore' infobar during first run. 1252 // Do not ever show the 'restore' infobar during first run.
1296 _restoreHelper.reset(); 1253 _restoreHelper = nil;
1297 } 1254 }
1298 } 1255 }
1299 1256
1300 - (void)showFirstRunUI { 1257 - (void)showFirstRunUI {
1301 // Register for notification when First Run is completed. 1258 // Register for notification when First Run is completed.
1302 // Some initializations are held back until First Run modal dialog 1259 // Some initializations are held back until First Run modal dialog
1303 // is dismissed. 1260 // is dismissed.
1304 [[NSNotificationCenter defaultCenter] 1261 [[NSNotificationCenter defaultCenter]
1305 addObserver:self 1262 addObserver:self
1306 selector:@selector(handleFirstRunUIWillFinish) 1263 selector:@selector(handleFirstRunUIWillFinish)
1307 name:kChromeFirstRunUIWillFinishNotification 1264 name:kChromeFirstRunUIWillFinishNotification
1308 object:nil]; 1265 object:nil];
1309 [[NSNotificationCenter defaultCenter] 1266 [[NSNotificationCenter defaultCenter]
1310 addObserver:self 1267 addObserver:self
1311 selector:@selector(handleFirstRunUIDidFinish) 1268 selector:@selector(handleFirstRunUIDidFinish)
1312 name:kChromeFirstRunUIDidFinishNotification 1269 name:kChromeFirstRunUIDidFinishNotification
1313 object:nil]; 1270 object:nil];
1314 1271
1315 base::scoped_nsobject<WelcomeToChromeViewController> welcomeToChrome( 1272 WelcomeToChromeViewController* welcomeToChrome =
1316 [[WelcomeToChromeViewController alloc] 1273 [[WelcomeToChromeViewController alloc]
1317 initWithBrowserState:_mainBrowserState 1274 initWithBrowserState:_mainBrowserState
1318 tabModel:self.mainTabModel]); 1275 tabModel:self.mainTabModel];
1319 base::scoped_nsobject<UINavigationController> navController( 1276 UINavigationController* navController =
1320 [[OrientationLimitingNavigationController alloc] 1277 [[OrientationLimitingNavigationController alloc]
1321 initWithRootViewController:welcomeToChrome]); 1278 initWithRootViewController:welcomeToChrome];
1322 [navController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 1279 [navController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
1323 CGRect appFrame = [[UIScreen mainScreen] bounds]; 1280 CGRect appFrame = [[UIScreen mainScreen] bounds];
1324 [[navController view] setFrame:appFrame]; 1281 [[navController view] setFrame:appFrame];
1325 _isPresentingFirstRunUI = YES; 1282 _isPresentingFirstRunUI = YES;
1326 [self.mainBVC presentViewController:navController animated:NO completion:nil]; 1283 [self.mainBVC presentViewController:navController animated:NO completion:nil];
1327 } 1284 }
1328 1285
1329 - (void)crashIfRequested { 1286 - (void)crashIfRequested {
1330 if (experimental_flags::IsStartupCrashEnabled()) { 1287 if (experimental_flags::IsStartupCrashEnabled()) {
1331 // Flush out the value cached for 1288 // Flush out the value cached for
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1334
1378 break; 1335 break;
1379 } 1336 }
1380 } 1337 }
1381 } 1338 }
1382 1339
1383 - (void)showPromo:(UIViewController*)promo { 1340 - (void)showPromo:(UIViewController*)promo {
1384 // Make sure we have the BVC here with a valid profile. 1341 // Make sure we have the BVC here with a valid profile.
1385 DCHECK([self.currentBVC browserState]); 1342 DCHECK([self.currentBVC browserState]);
1386 1343
1387 base::scoped_nsobject<OrientationLimitingNavigationController> navController( 1344 OrientationLimitingNavigationController* navController =
1388 [[OrientationLimitingNavigationController alloc] 1345 [[OrientationLimitingNavigationController alloc]
1389 initWithRootViewController:promo]); 1346 initWithRootViewController:promo];
1390 1347
1391 // Avoid presenting the promo if the current device orientation is not 1348 // Avoid presenting the promo if the current device orientation is not
1392 // supported. The promo will be presented at a later moment, when the device 1349 // supported. The promo will be presented at a later moment, when the device
1393 // orientation is supported. 1350 // orientation is supported.
1394 UIInterfaceOrientation orientation = 1351 UIInterfaceOrientation orientation =
1395 [UIApplication sharedApplication].statusBarOrientation; 1352 [UIApplication sharedApplication].statusBarOrientation;
1396 NSUInteger supportedOrientationsMask = 1353 NSUInteger supportedOrientationsMask =
1397 [navController supportedInterfaceOrientations]; 1354 [navController supportedInterfaceOrientations];
1398 if (!((1 << orientation) & supportedOrientationsMask)) 1355 if (!((1 << orientation) & supportedOrientationsMask))
1399 return; 1356 return;
(...skipping 18 matching lines...) Expand all
1418 break; 1375 break;
1419 case IDC_NEW_INCOGNITO_TAB: 1376 case IDC_NEW_INCOGNITO_TAB:
1420 [self createNewTabInBVC:self.otrBVC sender:sender]; 1377 [self createNewTabInBVC:self.otrBVC sender:sender];
1421 break; 1378 break;
1422 case IDC_OPEN_URL: 1379 case IDC_OPEN_URL:
1423 [self openUrl:base::mac::ObjCCast<OpenUrlCommand>(sender)]; 1380 [self openUrl:base::mac::ObjCCast<OpenUrlCommand>(sender)];
1424 break; 1381 break;
1425 case IDC_OPTIONS: 1382 case IDC_OPTIONS:
1426 [self showSettings]; 1383 [self showSettings];
1427 break; 1384 break;
1428 case IDC_REPORT_AN_ISSUE: 1385 case IDC_REPORT_AN_ISSUE: {
1429 dispatch_async(dispatch_get_main_queue(), ^{ 1386 dispatch_async(dispatch_get_main_queue(), ^{
1430 [self showReportAnIssue]; 1387 [self showReportAnIssue];
1431 }); 1388 });
1432 break; 1389 } break;
1433 case IDC_SHOW_SIGNIN_IOS: { 1390 case IDC_SHOW_SIGNIN_IOS: {
1434 ShowSigninCommand* command = 1391 ShowSigninCommand* command =
1435 base::mac::ObjCCastStrict<ShowSigninCommand>(sender); 1392 base::mac::ObjCCastStrict<ShowSigninCommand>(sender);
1436 if (command.operation == AUTHENTICATION_OPERATION_DISMISS) { 1393 if (command.operation == AUTHENTICATION_OPERATION_DISMISS) {
1437 [self dismissSigninInteractionController]; 1394 [self dismissSigninInteractionController];
1438 } else { 1395 } else {
1439 [self showSigninWithOperation:command.operation 1396 [self showSigninWithOperation:command.operation
1440 identity:command.identity 1397 identity:command.identity
1441 accessPoint:command.accessPoint 1398 accessPoint:command.accessPoint
1442 promoAction:command.promoAction 1399 promoAction:command.promoAction
(...skipping 10 matching lines...) Expand all
1453 break; 1410 break;
1454 case IDC_SHOW_SYNC_PASSPHRASE_SETTINGS: 1411 case IDC_SHOW_SYNC_PASSPHRASE_SETTINGS:
1455 [self showSyncEncryptionPassphrase]; 1412 [self showSyncEncryptionPassphrase];
1456 break; 1413 break;
1457 case IDC_SHOW_SAVE_PASSWORDS_SETTINGS: 1414 case IDC_SHOW_SAVE_PASSWORDS_SETTINGS:
1458 [self showSavePasswordsSettings]; 1415 [self showSavePasswordsSettings];
1459 break; 1416 break;
1460 case IDC_SHOW_HISTORY: 1417 case IDC_SHOW_HISTORY:
1461 [self showHistory]; 1418 [self showHistory];
1462 break; 1419 break;
1463 case IDC_TOGGLE_TAB_SWITCHER: 1420 case IDC_TOGGLE_TAB_SWITCHER: {
1464 DCHECK(!_tabSwitcherIsActive); 1421 DCHECK(!_tabSwitcherIsActive);
1465 if (!_isProcessingVoiceSearchCommand) { 1422 if (!_isProcessingVoiceSearchCommand) {
1466 [self showTabSwitcher]; 1423 [self showTabSwitcher];
1467 _isProcessingTabSwitcherCommand = YES; 1424 _isProcessingTabSwitcherCommand = YES;
1468 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1425 dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
1469 kExpectedTransitionDurationInNanoSeconds), 1426 kExpectedTransitionDurationInNanoSeconds),
1470 dispatch_get_main_queue(), ^{ 1427 dispatch_get_main_queue(), ^{
1471 _isProcessingTabSwitcherCommand = NO; 1428 _isProcessingTabSwitcherCommand = NO;
1472 }); 1429 });
1473 } 1430 }
1474 break; 1431 } break;
1432
1475 case IDC_PRELOAD_VOICE_SEARCH: 1433 case IDC_PRELOAD_VOICE_SEARCH:
1476 [self.currentBVC chromeExecuteCommand:sender]; 1434 [self.currentBVC chromeExecuteCommand:sender];
1477 break; 1435 break;
1478 case IDC_VOICE_SEARCH: 1436 case IDC_VOICE_SEARCH: {
1479 if (!_isProcessingTabSwitcherCommand) { 1437 if (!_isProcessingTabSwitcherCommand) {
1480 [self startVoiceSearch]; 1438 [self startVoiceSearch];
1481 _isProcessingVoiceSearchCommand = YES; 1439 _isProcessingVoiceSearchCommand = YES;
1482 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1440 dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
1483 kExpectedTransitionDurationInNanoSeconds), 1441 kExpectedTransitionDurationInNanoSeconds),
1484 dispatch_get_main_queue(), ^{ 1442 dispatch_get_main_queue(), ^{
1485 _isProcessingVoiceSearchCommand = NO; 1443 _isProcessingVoiceSearchCommand = NO;
1486 }); 1444 });
1487 } 1445 }
1488 break; 1446 } break;
1447
1489 case IDC_CLEAR_BROWSING_DATA_IOS: { 1448 case IDC_CLEAR_BROWSING_DATA_IOS: {
1490 // Clear both the main browser state and the associated incognito 1449 // Clear both the main browser state and the associated incognito
1491 // browser state. 1450 // browser state.
1492 ClearBrowsingDataCommand* command = 1451 ClearBrowsingDataCommand* command =
1493 base::mac::ObjCCastStrict<ClearBrowsingDataCommand>(sender); 1452 base::mac::ObjCCastStrict<ClearBrowsingDataCommand>(sender);
1494 ios::ChromeBrowserState* browserState = 1453 ios::ChromeBrowserState* browserState =
1495 [command browserState]->GetOriginalChromeBrowserState(); 1454 [command browserState]->GetOriginalChromeBrowserState();
1496 int mask = [command mask]; 1455 int mask = [command mask];
1497 browsing_data::TimePeriod timePeriod = [command timePeriod]; 1456 browsing_data::TimePeriod timePeriod = [command timePeriod];
1498 [self removeBrowsingDataFromBrowserState:browserState 1457 [self removeBrowsingDataFromBrowserState:browserState
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 #pragma mark - Tab closure handlers 1617 #pragma mark - Tab closure handlers
1659 1618
1660 - (void)lastIncognitoTabClosed { 1619 - (void)lastIncognitoTabClosed {
1661 DCHECK(_mainBrowserState->HasOffTheRecordChromeBrowserState()); 1620 DCHECK(_mainBrowserState->HasOffTheRecordChromeBrowserState());
1662 [self clearIOSSpecificIncognitoData]; 1621 [self clearIOSSpecificIncognitoData];
1663 1622
1664 // OffTheRecordProfileIOData cannot be deleted before all the requests are 1623 // OffTheRecordProfileIOData cannot be deleted before all the requests are
1665 // deleted. All of the request trackers associated with the closed OTR tabs 1624 // deleted. All of the request trackers associated with the closed OTR tabs
1666 // will have posted CancelRequest calls to the IO thread by now; this just 1625 // will have posted CancelRequest calls to the IO thread by now; this just
1667 // waits for those calls to run before calling |deleteIncognitoBrowserState|. 1626 // waits for those calls to run before calling |deleteIncognitoBrowserState|.
1668 web::RequestTrackerImpl::RunAfterRequestsCancel(base::BindBlock(^{ 1627 web::RequestTrackerImpl::RunAfterRequestsCancel(base::BindBlockArc(^{
1669 [self deleteIncognitoBrowserState]; 1628 [self deleteIncognitoBrowserState];
1670 })); 1629 }));
1671 1630
1672 // a) The first condition can happen when the last incognito tab is closed 1631 // a) The first condition can happen when the last incognito tab is closed
1673 // from the tab switcher. 1632 // from the tab switcher.
1674 // b) The second condition can happen if some other code (like JS) triggers 1633 // b) The second condition can happen if some other code (like JS) triggers
1675 // closure of tabs from the otr tab model when it's not current. 1634 // closure of tabs from the otr tab model when it's not current.
1676 // Nothing to do here. The next user action (like clicking on an existing 1635 // Nothing to do here. The next user action (like clicking on an existing
1677 // regular tab or creating a new incognito tab from the settings menu) will 1636 // regular tab or creating a new incognito tab from the settings menu) will
1678 // take care of the logic to mode switch. 1637 // take care of the logic to mode switch.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 BrowserViewController* currentBVC = self.currentBVC; 1709 BrowserViewController* currentBVC = self.currentBVC;
1751 Tab* currentTab = [[currentBVC tabModel] currentTab]; 1710 Tab* currentTab = [[currentBVC tabModel] currentTab];
1752 1711
1753 // In order to generate the transition between the current browser view 1712 // In order to generate the transition between the current browser view
1754 // controller and the tab switcher controller it's possible that multiple 1713 // controller and the tab switcher controller it's possible that multiple
1755 // screenshots of the same tab are taken. Since taking a screenshot is 1714 // screenshots of the same tab are taken. Since taking a screenshot is
1756 // expensive we activate snapshot coalescing in the scope of this function 1715 // expensive we activate snapshot coalescing in the scope of this function
1757 // which will cache the first snapshot for the tab and reuse it instead of 1716 // which will cache the first snapshot for the tab and reuse it instead of
1758 // regenerating a new one each time. 1717 // regenerating a new one each time.
1759 [currentTab setSnapshotCoalescingEnabled:YES]; 1718 [currentTab setSnapshotCoalescingEnabled:YES];
1760 base::ScopedClosureRunner runner(base::BindBlock(^{ 1719 base::ScopedClosureRunner runner(base::BindBlockArc(^{
1761 [currentTab setSnapshotCoalescingEnabled:NO]; 1720 [currentTab setSnapshotCoalescingEnabled:NO];
1762 })); 1721 }));
1763 1722
1764 [currentBVC prepareToEnterTabSwitcher:nil]; 1723 [currentBVC prepareToEnterTabSwitcher:nil];
1765 1724
1766 if (!_tabSwitcherController.get()) { 1725 if (!_tabSwitcherController) {
1767 if (IsIPadIdiom()) { 1726 if (IsIPadIdiom()) {
1768 _tabSwitcherController.reset([[TabSwitcherController alloc] 1727 _tabSwitcherController = [[TabSwitcherController alloc]
1769 initWithBrowserState:_mainBrowserState 1728 initWithBrowserState:_mainBrowserState
1770 mainTabModel:self.mainTabModel 1729 mainTabModel:self.mainTabModel
1771 otrTabModel:self.otrTabModel 1730 otrTabModel:self.otrTabModel
1772 activeTabModel:self.currentTabModel]); 1731 activeTabModel:self.currentTabModel];
1773 } else { 1732 } else {
1774 _tabSwitcherController.reset([[StackViewController alloc] 1733 _tabSwitcherController = [[StackViewController alloc]
1775 initWithMainTabModel:self.mainTabModel 1734 initWithMainTabModel:self.mainTabModel
1776 otrTabModel:self.otrTabModel 1735 otrTabModel:self.otrTabModel
1777 activeTabModel:self.currentTabModel]); 1736 activeTabModel:self.currentTabModel];
1778 } 1737 }
1779 } else { 1738 } else {
1780 // The StackViewController is kept in memory to avoid the performance hit of 1739 // The StackViewController is kept in memory to avoid the performance hit of
1781 // loading from the nib on next showing, but clears out its card models to 1740 // loading from the nib on next showing, but clears out its card models to
1782 // release memory. The tab models are required to rebuild the card stacks. 1741 // release memory. The tab models are required to rebuild the card stacks.
1783 [_tabSwitcherController 1742 [_tabSwitcherController
1784 restoreInternalStateWithMainTabModel:self.mainTabModel 1743 restoreInternalStateWithMainTabModel:self.mainTabModel
1785 otrTabModel:self.otrTabModel 1744 otrTabModel:self.otrTabModel
1786 activeTabModel:self.currentTabModel]; 1745 activeTabModel:self.currentTabModel];
1787 } 1746 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 // Prevent wayward touches from wreaking havoc while the stack view is being 1835 // Prevent wayward touches from wreaking havoc while the stack view is being
1877 // dismissed. 1836 // dismissed.
1878 [[_tabSwitcherController view] setUserInteractionEnabled:NO]; 1837 [[_tabSwitcherController view] setUserInteractionEnabled:NO];
1879 BrowserViewController* targetBVC = 1838 BrowserViewController* targetBVC =
1880 (tabModel == self.mainTabModel) ? self.mainBVC : self.otrBVC; 1839 (tabModel == self.mainTabModel) ? self.mainBVC : self.otrBVC;
1881 self.currentBVC = targetBVC; 1840 self.currentBVC = targetBVC;
1882 } 1841 }
1883 1842
1884 - (void)finishDismissingStackView { 1843 - (void)finishDismissingStackView {
1885 DCHECK_EQ(self.mainViewController.activeViewController, 1844 DCHECK_EQ(self.mainViewController.activeViewController,
1886 _tabSwitcherController.get()); 1845 _tabSwitcherController);
1887 1846
1888 if (_modeToDisplayOnStackViewDismissal == StackViewDismissalMode::NORMAL) { 1847 if (_modeToDisplayOnStackViewDismissal == StackViewDismissalMode::NORMAL) {
1889 self.currentBVC = self.mainBVC; 1848 self.currentBVC = self.mainBVC;
1890 } else if (_modeToDisplayOnStackViewDismissal == 1849 } else if (_modeToDisplayOnStackViewDismissal ==
1891 StackViewDismissalMode::INCOGNITO) { 1850 StackViewDismissalMode::INCOGNITO) {
1892 self.currentBVC = self.otrBVC; 1851 self.currentBVC = self.otrBVC;
1893 } 1852 }
1894 1853
1895 _modeToDisplayOnStackViewDismissal = StackViewDismissalMode::NONE; 1854 _modeToDisplayOnStackViewDismissal = StackViewDismissalMode::NONE;
1896 1855
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 removeBrowsingDataFromBrowserState:browserState 1908 removeBrowsingDataFromBrowserState:browserState
1950 mask:mask 1909 mask:mask
1951 timePeriod:timePeriod 1910 timePeriod:timePeriod
1952 completionHandler:browsingDataRemoved]; 1911 completionHandler:browsingDataRemoved];
1953 } 1912 }
1954 1913
1955 #pragma mark - Navigation Controllers 1914 #pragma mark - Navigation Controllers
1956 1915
1957 - (void)presentSignedInAccountsViewControllerForBrowserState: 1916 - (void)presentSignedInAccountsViewControllerForBrowserState:
1958 (ios::ChromeBrowserState*)browserState { 1917 (ios::ChromeBrowserState*)browserState {
1959 base::scoped_nsobject<UIViewController> accountsViewController( 1918 UIViewController* accountsViewController = [
1960 [[SignedInAccountsViewController alloc] 1919 [SignedInAccountsViewController alloc] initWithBrowserState:browserState];
1961 initWithBrowserState:browserState]);
1962 [[self topPresentedViewController] 1920 [[self topPresentedViewController]
1963 presentViewController:accountsViewController 1921 presentViewController:accountsViewController
1964 animated:YES 1922 animated:YES
1965 completion:nil]; 1923 completion:nil];
1966 } 1924 }
1967 1925
1968 - (void)showSettings { 1926 - (void)showSettings {
1969 if (_settingsNavigationController) 1927 if (_settingsNavigationController)
1970 return; 1928 return;
1971 [[DeferredInitializationRunner sharedInstance] 1929 [[DeferredInitializationRunner sharedInstance]
1972 runBlockIfNecessary:kPrefObserverInit]; 1930 runBlockIfNecessary:kPrefObserverInit];
1973 DCHECK(_localStatePrefObserverBridge); 1931 DCHECK(_localStatePrefObserverBridge);
1974 _settingsNavigationController.reset([SettingsNavigationController 1932 _settingsNavigationController = [SettingsNavigationController
1975 newSettingsMainControllerWithMainBrowserState:_mainBrowserState 1933 newSettingsMainControllerWithMainBrowserState:_mainBrowserState
1976 currentBrowserState:self.currentBrowserState 1934 currentBrowserState:self.currentBrowserState
1977 delegate:self]); 1935 delegate:self];
1978 [[self topPresentedViewController] 1936 [[self topPresentedViewController]
1979 presentViewController:_settingsNavigationController 1937 presentViewController:_settingsNavigationController
1980 animated:YES 1938 animated:YES
1981 completion:nil]; 1939 completion:nil];
1982 } 1940 }
1983 1941
1984 - (void)showAccountsSettings { 1942 - (void)showAccountsSettings {
1985 if (_settingsNavigationController) 1943 if (_settingsNavigationController)
1986 return; 1944 return;
1987 if ([self currentBrowserState]->IsOffTheRecord()) { 1945 if ([self currentBrowserState]->IsOffTheRecord()) {
1988 NOTREACHED(); 1946 NOTREACHED();
1989 return; 1947 return;
1990 } 1948 }
1991 _settingsNavigationController.reset([SettingsNavigationController 1949 _settingsNavigationController = [SettingsNavigationController
1992 newAccountsController:self.currentBrowserState 1950 newAccountsController:self.currentBrowserState
1993 delegate:self]); 1951 delegate:self];
1994 [[self topPresentedViewController] 1952 [[self topPresentedViewController]
1995 presentViewController:_settingsNavigationController 1953 presentViewController:_settingsNavigationController
1996 animated:YES 1954 animated:YES
1997 completion:nil]; 1955 completion:nil];
1998 } 1956 }
1999 1957
2000 - (void)showSyncSettings { 1958 - (void)showSyncSettings {
2001 if (_settingsNavigationController) 1959 if (_settingsNavigationController)
2002 return; 1960 return;
2003 _settingsNavigationController.reset([SettingsNavigationController 1961 _settingsNavigationController =
2004 newSyncController:_mainBrowserState 1962 [SettingsNavigationController newSyncController:_mainBrowserState
2005 allowSwitchSyncAccount:YES 1963 allowSwitchSyncAccount:YES
2006 delegate:self]); 1964 delegate:self];
2007 [[self topPresentedViewController] 1965 [[self topPresentedViewController]
2008 presentViewController:_settingsNavigationController 1966 presentViewController:_settingsNavigationController
2009 animated:YES 1967 animated:YES
2010 completion:nil]; 1968 completion:nil];
2011 } 1969 }
2012 1970
2013 - (void)showSavePasswordsSettings { 1971 - (void)showSavePasswordsSettings {
2014 if (_settingsNavigationController) 1972 if (_settingsNavigationController)
2015 return; 1973 return;
2016 _settingsNavigationController.reset([SettingsNavigationController 1974 _settingsNavigationController =
2017 newSavePasswordsController:_mainBrowserState 1975 [SettingsNavigationController newSavePasswordsController:_mainBrowserState
2018 delegate:self]); 1976 delegate:self];
2019 [[self topPresentedViewController] 1977 [[self topPresentedViewController]
2020 presentViewController:_settingsNavigationController 1978 presentViewController:_settingsNavigationController
2021 animated:YES 1979 animated:YES
2022 completion:nil]; 1980 completion:nil];
2023 } 1981 }
2024 1982
2025 - (void)showAutofillSettings { 1983 - (void)showAutofillSettings {
2026 if (_settingsNavigationController) 1984 if (_settingsNavigationController)
2027 return; 1985 return;
2028 _settingsNavigationController.reset([SettingsNavigationController 1986 _settingsNavigationController =
2029 newAutofillController:_mainBrowserState 1987 [SettingsNavigationController newAutofillController:_mainBrowserState
2030 delegate:self]); 1988 delegate:self];
2031 [[self topPresentedViewController] 1989 [[self topPresentedViewController]
2032 presentViewController:_settingsNavigationController 1990 presentViewController:_settingsNavigationController
2033 animated:YES 1991 animated:YES
2034 completion:nil]; 1992 completion:nil];
2035 } 1993 }
2036 1994
2037 - (void)showReportAnIssue { 1995 - (void)showReportAnIssue {
2038 if (_settingsNavigationController) 1996 if (_settingsNavigationController)
2039 return; 1997 return;
2040 _settingsNavigationController.reset([SettingsNavigationController 1998 _settingsNavigationController =
2041 newUserFeedbackController:_mainBrowserState 1999 [SettingsNavigationController newUserFeedbackController:_mainBrowserState
2042 delegate:self 2000 delegate:self
2043 feedbackDataSource:self]); 2001 feedbackDataSource:self];
2044 [[self topPresentedViewController] 2002 [[self topPresentedViewController]
2045 presentViewController:_settingsNavigationController 2003 presentViewController:_settingsNavigationController
2046 animated:YES 2004 animated:YES
2047 completion:nil]; 2005 completion:nil];
2048 } 2006 }
2049 2007
2050 - (void)showSyncEncryptionPassphrase { 2008 - (void)showSyncEncryptionPassphrase {
2051 if (_settingsNavigationController) 2009 if (_settingsNavigationController)
2052 return; 2010 return;
2053 _settingsNavigationController.reset([SettingsNavigationController 2011 _settingsNavigationController = [SettingsNavigationController
2054 newSyncEncryptionPassphraseController:_mainBrowserState 2012 newSyncEncryptionPassphraseController:_mainBrowserState
2055 delegate:self]); 2013 delegate:self];
2056 [[self topPresentedViewController] 2014 [[self topPresentedViewController]
2057 presentViewController:_settingsNavigationController 2015 presentViewController:_settingsNavigationController
2058 animated:YES 2016 animated:YES
2059 completion:nil]; 2017 completion:nil];
2060 } 2018 }
2061 2019
2062 - (void)showClearBrowsingDataSettingsController { 2020 - (void)showClearBrowsingDataSettingsController {
2063 if (_settingsNavigationController) 2021 if (_settingsNavigationController)
2064 return; 2022 return;
2065 _settingsNavigationController.reset([SettingsNavigationController 2023 _settingsNavigationController = [SettingsNavigationController
2066 newClearBrowsingDataController:_mainBrowserState 2024 newClearBrowsingDataController:_mainBrowserState
2067 delegate:self]); 2025 delegate:self];
2068 [[self topPresentedViewController] 2026 [[self topPresentedViewController]
2069 presentViewController:_settingsNavigationController 2027 presentViewController:_settingsNavigationController
2070 animated:YES 2028 animated:YES
2071 completion:nil]; 2029 completion:nil];
2072 } 2030 }
2073 2031
2074 - (void)showContextualSearchSettingsController { 2032 - (void)showContextualSearchSettingsController {
2075 if (_settingsNavigationController) 2033 if (_settingsNavigationController)
2076 return; 2034 return;
2077 _settingsNavigationController.reset([SettingsNavigationController 2035 _settingsNavigationController = [SettingsNavigationController
2078 newContextualSearchController:_mainBrowserState 2036 newContextualSearchController:_mainBrowserState
2079 delegate:self]); 2037 delegate:self];
2080 [[self topPresentedViewController] 2038 [[self topPresentedViewController]
2081 presentViewController:_settingsNavigationController 2039 presentViewController:_settingsNavigationController
2082 animated:YES 2040 animated:YES
2083 completion:nil]; 2041 completion:nil];
2084 } 2042 }
2085 2043
2086 - (void)showSigninWithOperation:(AuthenticationOperation)operation 2044 - (void)showSigninWithOperation:(AuthenticationOperation)operation
2087 identity:(ChromeIdentity*)identity 2045 identity:(ChromeIdentity*)identity
2088 accessPoint:(signin_metrics::AccessPoint)accessPoint 2046 accessPoint:(signin_metrics::AccessPoint)accessPoint
2089 promoAction:(signin_metrics::PromoAction)promoAction 2047 promoAction:(signin_metrics::PromoAction)promoAction
2090 callback:(ShowSigninCommandCompletionCallback)callback { 2048 callback:(ShowSigninCommandCompletionCallback)callback {
2091 DCHECK_NE(AUTHENTICATION_OPERATION_DISMISS, operation); 2049 DCHECK_NE(AUTHENTICATION_OPERATION_DISMISS, operation);
2092 2050
2093 if (_signinInteractionController) { 2051 if (_signinInteractionController) {
2094 // Avoid showing the sign in screen if there is already a sign-in operation 2052 // Avoid showing the sign in screen if there is already a sign-in operation
2095 // in progress. 2053 // in progress.
2096 return; 2054 return;
2097 } 2055 }
2098 2056
2099 BOOL areSettingsPresented = _settingsNavigationController != NULL; 2057 BOOL areSettingsPresented = _settingsNavigationController != NULL;
2100 _signinInteractionController.reset([[SigninInteractionController alloc] 2058 _signinInteractionController = [[SigninInteractionController alloc]
2101 initWithBrowserState:_mainBrowserState 2059 initWithBrowserState:_mainBrowserState
2102 presentingViewController:[self topPresentedViewController] 2060 presentingViewController:[self topPresentedViewController]
2103 isPresentedOnSettings:areSettingsPresented 2061 isPresentedOnSettings:areSettingsPresented
2104 accessPoint:accessPoint 2062 accessPoint:accessPoint
2105 promoAction:promoAction]); 2063 promoAction:promoAction];
2106 2064
2107 signin_ui::CompletionCallback completion = ^(BOOL success) { 2065 signin_ui::CompletionCallback completion = ^(BOOL success) {
2108 _signinInteractionController.reset(); 2066 _signinInteractionController = nil;
2109 if (callback) 2067 if (callback)
2110 callback(success); 2068 callback(success);
2111 }; 2069 };
2112 2070
2113 switch (operation) { 2071 switch (operation) {
2114 case AUTHENTICATION_OPERATION_DISMISS: 2072 case AUTHENTICATION_OPERATION_DISMISS:
2115 // Special case handled above. 2073 // Special case handled above.
2116 NOTREACHED(); 2074 NOTREACHED();
2117 break; 2075 break;
2118 case AUTHENTICATION_OPERATION_REAUTHENTICATE: 2076 case AUTHENTICATION_OPERATION_REAUTHENTICATE:
(...skipping 11 matching lines...) Expand all
2130 } 2088 }
2131 2089
2132 - (void)showAddAccount { 2090 - (void)showAddAccount {
2133 if (_signinInteractionController) { 2091 if (_signinInteractionController) {
2134 // Avoid showing the sign in screen if there is already a sign-in operation 2092 // Avoid showing the sign in screen if there is already a sign-in operation
2135 // in progress. 2093 // in progress.
2136 return; 2094 return;
2137 } 2095 }
2138 2096
2139 BOOL areSettingsPresented = _settingsNavigationController != NULL; 2097 BOOL areSettingsPresented = _settingsNavigationController != NULL;
2140 _signinInteractionController.reset([[SigninInteractionController alloc] 2098 _signinInteractionController = [[SigninInteractionController alloc]
2141 initWithBrowserState:_mainBrowserState 2099 initWithBrowserState:_mainBrowserState
2142 presentingViewController:[self topPresentedViewController] 2100 presentingViewController:[self topPresentedViewController]
2143 isPresentedOnSettings:areSettingsPresented 2101 isPresentedOnSettings:areSettingsPresented
2144 accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_UNKNOWN 2102 accessPoint:signin_metrics::AccessPoint::ACCESS_POINT_UNKNOWN
2145 promoAction:signin_metrics::PromoAction:: 2103 promoAction:signin_metrics::PromoAction::
2146 PROMO_ACTION_NO_SIGNIN_PROMO]); 2104 PROMO_ACTION_NO_SIGNIN_PROMO];
2147 2105
2148 [_signinInteractionController 2106 [_signinInteractionController
2149 addAccountWithCompletion:^(BOOL success) { 2107 addAccountWithCompletion:^(BOOL success) {
2150 _signinInteractionController.reset(); 2108 _signinInteractionController = nil;
2151 } 2109 }
2152 viewController:self.mainViewController]; 2110 viewController:self.mainViewController];
2153 } 2111 }
2154 2112
2155 - (void)showHistory { 2113 - (void)showHistory {
2156 _historyPanelViewController.reset([[HistoryPanelViewController 2114 _historyPanelViewController = [HistoryPanelViewController
2157 controllerToPresentForBrowserState:_mainBrowserState 2115 controllerToPresentForBrowserState:_mainBrowserState
2158 loader:self.currentBVC] retain]); 2116 loader:self.currentBVC];
2159 [self.currentBVC presentViewController:_historyPanelViewController 2117 [self.currentBVC presentViewController:_historyPanelViewController
2160 animated:YES 2118 animated:YES
2161 completion:nil]; 2119 completion:nil];
2162 } 2120 }
2163 2121
2164 - (void)dismissSigninInteractionController { 2122 - (void)dismissSigninInteractionController {
2165 // The sign-in interaction controller is destroyed as a result of calling 2123 // The sign-in interaction controller is destroyed as a result of calling
2166 // |cancelAndDismiss|. Destroying it here may lead to a missing call of the 2124 // |cancelAndDismiss|. Destroying it here may lead to a missing call of the
2167 // |ShowSigninCommandCompletionCallback| passed when starting a show sign-in 2125 // |ShowSigninCommandCompletionCallback| passed when starting a show sign-in
2168 // operation. 2126 // operation.
2169 [_signinInteractionController cancelAndDismiss]; 2127 [_signinInteractionController cancelAndDismiss];
2170 } 2128 }
2171 2129
2172 - (ShowSigninCommandCompletionCallback)successfulSigninCompletion: 2130 - (ShowSigninCommandCompletionCallback)successfulSigninCompletion:
2173 (ProceduralBlock)callback { 2131 (ProceduralBlock)callback {
2174 return [[^(BOOL successful) { 2132 return [^(BOOL successful) {
2175 ios::ChromeBrowserState* browserState = [self currentBrowserState]; 2133 ios::ChromeBrowserState* browserState = [self currentBrowserState];
2176 if (browserState->IsOffTheRecord()) { 2134 if (browserState->IsOffTheRecord()) {
2177 NOTREACHED() 2135 NOTREACHED()
2178 << "Ignore call to |handleSignInFinished| when in incognito."; 2136 << "Ignore call to |handleSignInFinished| when in incognito.";
2179 return; 2137 return;
2180 } 2138 }
2181 DCHECK_EQ(self.mainBVC, self.currentBVC); 2139 DCHECK_EQ(self.mainBVC, self.currentBVC);
2182 SigninManager* signinManager = 2140 SigninManager* signinManager =
2183 ios::SigninManagerFactory::GetForBrowserState(browserState); 2141 ios::SigninManagerFactory::GetForBrowserState(browserState);
2184 if (signinManager->IsAuthenticated()) 2142 if (signinManager->IsAuthenticated())
2185 callback(); 2143 callback();
2186 } copy] autorelease]; 2144 } copy];
2187 } 2145 }
2188 2146
2189 - (void)showNativeAppsSettings { 2147 - (void)showNativeAppsSettings {
2190 if (_settingsNavigationController) 2148 if (_settingsNavigationController)
2191 return; 2149 return;
2192 _settingsNavigationController.reset([SettingsNavigationController 2150 _settingsNavigationController =
2193 newNativeAppsController:_mainBrowserState 2151 [SettingsNavigationController newNativeAppsController:_mainBrowserState
2194 delegate:self]); 2152 delegate:self];
2195 [[self topPresentedViewController] 2153 [[self topPresentedViewController]
2196 presentViewController:_settingsNavigationController 2154 presentViewController:_settingsNavigationController
2197 animated:YES 2155 animated:YES
2198 completion:nil]; 2156 completion:nil];
2199 } 2157 }
2200 2158
2201 - (void)closeSettingsAnimated:(BOOL)animated 2159 - (void)closeSettingsAnimated:(BOOL)animated
2202 completion:(ProceduralBlock)completion { 2160 completion:(ProceduralBlock)completion {
2203 DCHECK(_settingsNavigationController); 2161 DCHECK(_settingsNavigationController);
2204 [_settingsNavigationController settingsWillBeDismissed]; 2162 [_settingsNavigationController settingsWillBeDismissed];
2205 UIViewController* presentingViewController = 2163 UIViewController* presentingViewController =
2206 [_settingsNavigationController presentingViewController]; 2164 [_settingsNavigationController presentingViewController];
2207 DCHECK(presentingViewController); 2165 DCHECK(presentingViewController);
2208 [presentingViewController dismissViewControllerAnimated:animated 2166 [presentingViewController dismissViewControllerAnimated:animated
2209 completion:^{ 2167 completion:^{
2210 if (completion) 2168 if (completion)
2211 completion(); 2169 completion();
2212 }]; 2170 }];
2213 _settingsNavigationController.reset(); 2171 _settingsNavigationController = nil;
2214 } 2172 }
2215 2173
2216 #pragma mark - TabModelObserver 2174 #pragma mark - TabModelObserver
2217 2175
2218 // Called when the number of tabs changes. Triggers the switcher view when 2176 // Called when the number of tabs changes. Triggers the switcher view when
2219 // the last tab is closed on a device that uses the switcher. 2177 // the last tab is closed on a device that uses the switcher.
2220 - (void)tabModelDidChangeTabCount:(TabModel*)notifiedTabModel { 2178 - (void)tabModelDidChangeTabCount:(TabModel*)notifiedTabModel {
2221 TabModel* currentTabModel = [self currentTabModel]; 2179 TabModel* currentTabModel = [self currentTabModel];
2222 // Do nothing on initialization. 2180 // Do nothing on initialization.
2223 if (!currentTabModel) 2181 if (!currentTabModel)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 [self.currentBVC focusOmnibox]; 2287 [self.currentBVC focusOmnibox];
2330 }); 2288 });
2331 } 2289 }
2332 } 2290 }
2333 2291
2334 if (_restoreHelper) { 2292 if (_restoreHelper) {
2335 // Now that all the operations on the tabs have been done, display the 2293 // Now that all the operations on the tabs have been done, display the
2336 // restore infobar if needed. 2294 // restore infobar if needed.
2337 dispatch_async(dispatch_get_main_queue(), ^{ 2295 dispatch_async(dispatch_get_main_queue(), ^{
2338 [_restoreHelper showRestoreIfNeeded:[self currentTabModel]]; 2296 [_restoreHelper showRestoreIfNeeded:[self currentTabModel]];
2339 _restoreHelper.reset(); 2297 _restoreHelper = nil;
2340 }); 2298 });
2341 } 2299 }
2342 2300
2343 return tab; 2301 return tab;
2344 } 2302 }
2345 2303
2346 - (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion { 2304 - (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion {
2347 // Immediately hide modals from the provider (alert views, action sheets, 2305 // Immediately hide modals from the provider (alert views, action sheets,
2348 // popovers). They will be ultimately dismissed by their owners, but at least, 2306 // popovers). They will be ultimately dismissed by their owners, but at least,
2349 // they are not visible. 2307 // they are not visible.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 2509
2552 #pragma mark - TestingOnly 2510 #pragma mark - TestingOnly
2553 2511
2554 @implementation MainController (TestingOnly) 2512 @implementation MainController (TestingOnly)
2555 2513
2556 - (DeviceSharingManager*)deviceSharingManager { 2514 - (DeviceSharingManager*)deviceSharingManager {
2557 return [_browserViewWrangler deviceSharingManager]; 2515 return [_browserViewWrangler deviceSharingManager];
2558 } 2516 }
2559 2517
2560 - (UIViewController<TabSwitcher>*)tabSwitcherController { 2518 - (UIViewController<TabSwitcher>*)tabSwitcherController {
2561 return _tabSwitcherController.get(); 2519 return _tabSwitcherController;
2562 } 2520 }
2563 2521
2564 - (void)setTabSwitcherController:(UIViewController<TabSwitcher>*)controller { 2522 - (void)setTabSwitcherController:(UIViewController<TabSwitcher>*)controller {
2565 _tabSwitcherController.reset([controller retain]); 2523 _tabSwitcherController = controller;
2566 } 2524 }
2567 2525
2568 - (SigninInteractionController*)signinInteractionController { 2526 - (SigninInteractionController*)signinInteractionController {
2569 return _signinInteractionController.get(); 2527 return _signinInteractionController;
2570 } 2528 }
2571 2529
2572 - (UIViewController*)topPresentedViewController { 2530 - (UIViewController*)topPresentedViewController {
2573 return top_view_controller::TopPresentedViewControllerFrom( 2531 return top_view_controller::TopPresentedViewControllerFrom(
2574 self.mainViewController); 2532 self.mainViewController);
2575 } 2533 }
2576 2534
2577 - (void)setTabSwitcherActive:(BOOL)active { 2535 - (void)setTabSwitcherActive:(BOOL)active {
2578 _tabSwitcherIsActive = active; 2536 _tabSwitcherIsActive = active;
2579 } 2537 }
2580 2538
2581 - (BOOL)dismissingTabSwitcher { 2539 - (BOOL)dismissingTabSwitcher {
2582 return _dismissingStackView; 2540 return _dismissingStackView;
2583 } 2541 }
2584 2542
2585 - (void)setStartupParametersWithURL:(const GURL&)launchURL { 2543 - (void)setStartupParametersWithURL:(const GURL&)launchURL {
2586 NSString* sourceApplication = @"Fake App"; 2544 NSString* sourceApplication = @"Fake App";
2587 _startupParameters.reset([[ChromeAppStartupParameters 2545 _startupParameters = [ChromeAppStartupParameters
2588 newChromeAppStartupParametersWithURL:net::NSURLWithGURL(launchURL) 2546 newChromeAppStartupParametersWithURL:net::NSURLWithGURL(launchURL)
2589 fromSourceApplication:sourceApplication] retain]); 2547 fromSourceApplication:sourceApplication];
2590 } 2548 }
2591 2549
2592 - (void)setUpAsForegrounded { 2550 - (void)setUpAsForegrounded {
2593 _isColdStart = NO; 2551 _isColdStart = NO;
2594 _browserInitializationStage = INITIALIZATION_STAGE_FOREGROUND; 2552 _browserInitializationStage = INITIALIZATION_STAGE_FOREGROUND;
2595 // Create a BrowserViewWrangler with a null browser state. This will trigger 2553 // Create a BrowserViewWrangler with a null browser state. This will trigger
2596 // assertions if the BrowserViewWrangler is asked to create any BVC or 2554 // assertions if the BrowserViewWrangler is asked to create any BVC or
2597 // tabModel objects, but it will accept assignments to them. 2555 // tabModel objects, but it will accept assignments to them.
2598 [_browserViewWrangler shutdown]; 2556 [_browserViewWrangler shutdown];
2599 _browserViewWrangler.reset([[BrowserViewWrangler alloc] 2557 _browserViewWrangler =
2600 initWithBrowserState:nullptr 2558 [[BrowserViewWrangler alloc] initWithBrowserState:nullptr
2601 tabModelObserver:self]); 2559 tabModelObserver:self];
2602 // This is a test utility method that bypasses the ususal setup steps, so 2560 // This is a test utility method that bypasses the ususal setup steps, so
2603 // verify that the main coordinator hasn't been created yet, then start it 2561 // verify that the main coordinator hasn't been created yet, then start it
2604 // via lazy initialization. 2562 // via lazy initialization.
2605 DCHECK(!_mainCoordinator); 2563 DCHECK(!_mainCoordinator);
2606 [self.mainCoordinator start]; 2564 [self.mainCoordinator start];
2607 } 2565 }
2608 2566
2609 - (void)setUpForTestingWithCompletionHandler: 2567 - (void)setUpForTestingWithCompletionHandler:
2610 (ProceduralBlock)completionHandler { 2568 (ProceduralBlock)completionHandler {
2611 self.currentBVC = self.mainBVC; 2569 self.currentBVC = self.mainBVC;
2612 2570
2613 int removeAllMask = ~0; 2571 int removeAllMask = ~0;
2614 scoped_refptr<CallbackCounter> callbackCounter = 2572 scoped_refptr<CallbackCounter> callbackCounter =
2615 new CallbackCounter(base::BindBlock(^{ 2573 new CallbackCounter(base::BindBlockArc(^{
2616 [self setUpCurrentBVCForTesting]; 2574 [self setUpCurrentBVCForTesting];
2617 if (completionHandler) { 2575 if (completionHandler) {
2618 completionHandler(); 2576 completionHandler();
2619 } 2577 }
2620 })); 2578 }));
2621 id decrementCallbackCounterCount = ^{ 2579 id decrementCallbackCounterCount = ^{
2622 callbackCounter->DecrementCount(); 2580 callbackCounter->DecrementCount();
2623 }; 2581 };
2624 2582
2625 callbackCounter->IncrementCount(); 2583 callbackCounter->IncrementCount();
2626 [self removeBrowsingDataFromBrowserState:_mainBrowserState 2584 [self removeBrowsingDataFromBrowserState:_mainBrowserState
2627 mask:removeAllMask 2585 mask:removeAllMask
2628 timePeriod:browsing_data::TimePeriod::ALL_TIME 2586 timePeriod:browsing_data::TimePeriod::ALL_TIME
2629 completionHandler:decrementCallbackCounterCount]; 2587 completionHandler:decrementCallbackCounterCount];
2630 } 2588 }
2631 2589
2632 @end 2590 @end
OLDNEW
« no previous file with comments | « ios/chrome/app/main_controller.h ('k') | ios/chrome/app/main_controller_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698