| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_application_delegate.h" | 5 #import "ios/chrome/app/main_application_delegate.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #import "ios/chrome/app/application_delegate/app_navigation.h" | 8 #import "ios/chrome/app/application_delegate/app_navigation.h" |
| 10 #import "ios/chrome/app/application_delegate/app_state.h" | 9 #import "ios/chrome/app/application_delegate/app_state.h" |
| 11 #import "ios/chrome/app/application_delegate/background_activity.h" | 10 #import "ios/chrome/app/application_delegate/background_activity.h" |
| 12 #import "ios/chrome/app/application_delegate/browser_launcher.h" | 11 #import "ios/chrome/app/application_delegate/browser_launcher.h" |
| 13 #import "ios/chrome/app/application_delegate/memory_warning_helper.h" | 12 #import "ios/chrome/app/application_delegate/memory_warning_helper.h" |
| 14 #import "ios/chrome/app/application_delegate/metrics_mediator.h" | 13 #import "ios/chrome/app/application_delegate/metrics_mediator.h" |
| 15 #import "ios/chrome/app/application_delegate/startup_information.h" | 14 #import "ios/chrome/app/application_delegate/startup_information.h" |
| 16 #import "ios/chrome/app/application_delegate/tab_opening.h" | 15 #import "ios/chrome/app/application_delegate/tab_opening.h" |
| 17 #import "ios/chrome/app/application_delegate/tab_switching.h" | 16 #import "ios/chrome/app/application_delegate/tab_switching.h" |
| 18 #import "ios/chrome/app/application_delegate/url_opener.h" | 17 #import "ios/chrome/app/application_delegate/url_opener.h" |
| 19 #import "ios/chrome/app/application_delegate/user_activity_handler.h" | 18 #import "ios/chrome/app/application_delegate/user_activity_handler.h" |
| 20 #import "ios/chrome/app/chrome_overlay_window.h" | 19 #import "ios/chrome/app/chrome_overlay_window.h" |
| 21 #import "ios/chrome/app/main_application_delegate_testing.h" | 20 #import "ios/chrome/app/main_application_delegate_testing.h" |
| 22 #import "ios/chrome/app/main_controller.h" | 21 #import "ios/chrome/app/main_controller.h" |
| 23 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 22 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 24 #include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 23 #include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 25 | 24 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." |
| 27 #endif |
| 28 |
| 26 @interface MainApplicationDelegate () { | 29 @interface MainApplicationDelegate () { |
| 27 base::scoped_nsobject<MainController> _mainController; | 30 MainController* _mainController; |
| 28 // Memory helper used to log the number of memory warnings received. | 31 // Memory helper used to log the number of memory warnings received. |
| 29 base::scoped_nsobject<MemoryWarningHelper> _memoryHelper; | 32 MemoryWarningHelper* _memoryHelper; |
| 30 // Metrics mediator used to check and update the metrics accordingly to | 33 // Metrics mediator used to check and update the metrics accordingly to |
| 31 // to the user preferences. | 34 // to the user preferences. |
| 32 base::scoped_nsobject<MetricsMediator> _metricsMediator; | 35 MetricsMediator* _metricsMediator; |
| 33 // Browser launcher to have a global launcher. | 36 // Browser launcher to have a global launcher. |
| 34 base::scoped_nsprotocol<id<BrowserLauncher>> _browserLauncher; | 37 id<BrowserLauncher> _browserLauncher; |
| 35 // Container for startup information. | 38 // Container for startup information. |
| 36 base::scoped_nsprotocol<id<StartupInformation>> _startupInformation; | 39 id<StartupInformation> _startupInformation; |
| 37 // Helper to open new tabs. | 40 // Helper to open new tabs. |
| 38 base::scoped_nsprotocol<id<TabOpening>> _tabOpener; | 41 id<TabOpening> _tabOpener; |
| 39 // Handles the application stage changes. | 42 // Handles the application stage changes. |
| 40 base::scoped_nsobject<AppState> _appState; | 43 AppState* _appState; |
| 41 // Handles tab switcher. | 44 // Handles tab switcher. |
| 42 base::scoped_nsprotocol<id<AppNavigation>> _appNavigation; | 45 id<AppNavigation> _appNavigation; |
| 43 // Handles tab switcher. | 46 // Handles tab switcher. |
| 44 base::scoped_nsprotocol<id<TabSwitching>> _tabSwitcherProtocol; | 47 id<TabSwitching> _tabSwitcherProtocol; |
| 45 } | 48 } |
| 46 | 49 |
| 47 @end | 50 @end |
| 48 | 51 |
| 49 @implementation MainApplicationDelegate | 52 @implementation MainApplicationDelegate |
| 50 | 53 |
| 51 - (instancetype)init { | 54 - (instancetype)init { |
| 52 if (self = [super init]) { | 55 if (self = [super init]) { |
| 53 _memoryHelper.reset([[MemoryWarningHelper alloc] init]); | 56 _memoryHelper = [[MemoryWarningHelper alloc] init]; |
| 54 _mainController.reset([[MainController alloc] init]); | 57 _mainController = [[MainController alloc] init]; |
| 55 _metricsMediator.reset([[MetricsMediator alloc] init]); | 58 _metricsMediator = [[MetricsMediator alloc] init]; |
| 56 [_mainController setMetricsMediator:_metricsMediator]; | 59 [_mainController setMetricsMediator:_metricsMediator]; |
| 57 _browserLauncher.reset([_mainController retain]); | 60 _browserLauncher = _mainController; |
| 58 _startupInformation.reset([_mainController retain]); | 61 _startupInformation = _mainController; |
| 59 _tabOpener.reset([_mainController retain]); | 62 _tabOpener = _mainController; |
| 60 _appState.reset([[AppState alloc] | 63 _appState = [[AppState alloc] initWithBrowserLauncher:_browserLauncher |
| 61 initWithBrowserLauncher:_browserLauncher | 64 startupInformation:_startupInformation |
| 62 startupInformation:_startupInformation | 65 applicationDelegate:self]; |
| 63 applicationDelegate:self]); | 66 _tabSwitcherProtocol = _mainController; |
| 64 _tabSwitcherProtocol.reset([_mainController retain]); | 67 _appNavigation = _mainController; |
| 65 _appNavigation.reset([_mainController retain]); | |
| 66 [_mainController setAppState:_appState]; | 68 [_mainController setAppState:_appState]; |
| 67 } | 69 } |
| 68 return self; | 70 return self; |
| 69 } | 71 } |
| 70 | 72 |
| 71 - (UIWindow*)window { | 73 - (UIWindow*)window { |
| 72 return [_mainController window]; | 74 return [_mainController window]; |
| 73 } | 75 } |
| 74 | 76 |
| 75 - (void)setWindow:(UIWindow*)newWindow { | 77 - (void)setWindow:(UIWindow*)newWindow { |
| 76 DCHECK(newWindow); | 78 DCHECK(newWindow); |
| 77 [_mainController setWindow:newWindow]; | 79 [_mainController setWindow:newWindow]; |
| 78 // self.window has been set by this time. _appState window can now be set. | 80 // self.window has been set by this time. _appState window can now be set. |
| 79 [_appState setWindow:newWindow]; | 81 [_appState setWindow:newWindow]; |
| 80 } | 82 } |
| 81 | 83 |
| 82 #pragma mark - UIApplicationDelegate methods - | 84 #pragma mark - UIApplicationDelegate methods - |
| 83 | 85 |
| 84 #pragma mark Responding to App State Changes and System Events | 86 #pragma mark Responding to App State Changes and System Events |
| 85 | 87 |
| 86 // Called by the OS to create the UI for display. The UI will not be displayed, | 88 // Called by the OS to create the UI for display. The UI will not be displayed, |
| 87 // even if it is ready, until this function returns. | 89 // even if it is ready, until this function returns. |
| 88 // The absolute minimum work should be done here, to ensure that the application | 90 // The absolute minimum work should be done here, to ensure that the application |
| 89 // startup is fast, and the UI appears as soon as possible. | 91 // startup is fast, and the UI appears as soon as possible. |
| 90 - (BOOL)application:(UIApplication*)application | 92 - (BOOL)application:(UIApplication*)application |
| 91 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | 93 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { |
| 92 // Main window must be ChromeOverlayWindow or a subclass of it. | 94 // Main window must be ChromeOverlayWindow or a subclass of it. |
| 93 self.window = [[[ChromeOverlayWindow alloc] | 95 self.window = [[ChromeOverlayWindow alloc] |
| 94 initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; | 96 initWithFrame:[[UIScreen mainScreen] bounds]]; |
| 95 | 97 |
| 96 BOOL inBackground = | 98 BOOL inBackground = |
| 97 [application applicationState] == UIApplicationStateBackground; | 99 [application applicationState] == UIApplicationStateBackground; |
| 98 return [_appState requiresHandlingAfterLaunchWithOptions:launchOptions | 100 return [_appState requiresHandlingAfterLaunchWithOptions:launchOptions |
| 99 stateBackground:inBackground]; | 101 stateBackground:inBackground]; |
| 100 } | 102 } |
| 101 | 103 |
| 102 - (void)applicationDidBecomeActive:(UIApplication*)application { | 104 - (void)applicationDidBecomeActive:(UIApplication*)application { |
| 103 if ([_appState isInSafeMode]) | 105 if ([_appState isInSafeMode]) |
| 104 return; | 106 return; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return _appState; | 267 return _appState; |
| 266 } | 268 } |
| 267 | 269 |
| 268 + (MainController*)sharedMainController { | 270 + (MainController*)sharedMainController { |
| 269 return base::mac::ObjCCast<MainApplicationDelegate>( | 271 return base::mac::ObjCCast<MainApplicationDelegate>( |
| 270 [[UIApplication sharedApplication] delegate]) | 272 [[UIApplication sharedApplication] delegate]) |
| 271 .mainController; | 273 .mainController; |
| 272 } | 274 } |
| 273 | 275 |
| 274 @end | 276 @end |
| OLD | NEW |