OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/app/safe_mode/safe_mode_coordinator.h" |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #import "ios/chrome/app/safe_mode/safe_mode_view_controller.h" |
| 9 #include "ios/chrome/browser/crash_loop_detection_util.h" |
| 10 |
| 11 namespace { |
| 12 const int kStartupCrashLoopThreshold = 2; |
| 13 } |
| 14 |
| 15 @interface SafeModeCoordinator ()<SafeModeViewControllerDelegate> { |
| 16 // Weak pointer to window passed on init. |
| 17 base::WeakNSObject<UIWindow> _window; |
| 18 // Weak pointer backing property of the same name. |
| 19 base::WeakNSProtocol<id<SafeModeCoordinatorDelegate>> _delegate; |
| 20 } |
| 21 |
| 22 @end |
| 23 |
| 24 @implementation SafeModeCoordinator |
| 25 |
| 26 #pragma mark - property implementation. |
| 27 |
| 28 - (id<SafeModeCoordinatorDelegate>)delegate { |
| 29 return _delegate; |
| 30 } |
| 31 |
| 32 - (void)setDelegate:(id<SafeModeCoordinatorDelegate>)delegate { |
| 33 _delegate.reset(delegate); |
| 34 } |
| 35 |
| 36 #pragma mark - Public class methods |
| 37 |
| 38 + (BOOL)shouldStart { |
| 39 // Check whether there appears to be a startup crash loop. If not, don't look |
| 40 // at anything else. |
| 41 if (crash_util::GetFailedStartupAttemptCount() < kStartupCrashLoopThreshold) |
| 42 return NO; |
| 43 |
| 44 return [SafeModeViewController hasSuggestions]; |
| 45 } |
| 46 |
| 47 #pragma mark - ChromeCoordinator implementation |
| 48 |
| 49 - (void)start { |
| 50 // Create the SafeModeViewController and make it the root view controller for |
| 51 // the window. The window has ownership of it and will dispose of it when |
| 52 // another view controller is made root. |
| 53 // |
| 54 // General note: Safe mode should be safe; it should not depend on other |
| 55 // objects being created. Be extremely conservative when adding code to this |
| 56 // method. |
| 57 base::scoped_nsobject<SafeModeViewController> viewController( |
| 58 [[SafeModeViewController alloc] initWithDelegate:self]); |
| 59 [self.window setRootViewController:viewController]; |
| 60 |
| 61 // Reset the crash count; the user may change something based on the recovery |
| 62 // UI that will fix the crash, and having the next launch start in recovery |
| 63 // mode would be strange. |
| 64 crash_util::ResetFailedStartupAttemptCount(); |
| 65 } |
| 66 |
| 67 // Override of ChildCoordinators method, which is not supported in this class. |
| 68 - (MutableCoordinatorArray*)childCoordinators { |
| 69 NOTREACHED() << "Do not add child coordinators to SafeModeCoordinator."; |
| 70 return nil; |
| 71 } |
| 72 |
| 73 #pragma mark - SafeModeViewControllerDelegate implementation |
| 74 |
| 75 - (void)startBrowserFromSafeMode { |
| 76 [self.delegate coordinatorDidExitSafeMode:self]; |
| 77 } |
| 78 |
| 79 @end |
OLD | NEW |