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

Side by Side Diff: ios/chrome/app/application_delegate/app_state.mm

Issue 2621943002: [ObjC ARC] Converts ios/chrome/app/application_delegate:application_delegate_internal to ARC. (Closed)
Patch Set: add dependency on ios/chrome/common/app_group:main_app Created 3 years, 11 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
OLDNEW
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/application_delegate/app_state.h" 5 #import "ios/chrome/app/application_delegate/app_state.h"
6 6
7 #include "base/critical_closure.h" 7 #include "base/critical_closure.h"
8 #import "base/mac/bind_objc_block.h" 8 #import "base/mac/bind_objc_block.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "components/metrics/metrics_service.h" 9 #include "components/metrics/metrics_service.h"
10 #import "ios/chrome/app/main_application_delegate.h"
11 #import "ios/chrome/app/application_delegate/app_navigation.h" 11 #import "ios/chrome/app/application_delegate/app_navigation.h"
12 #import "ios/chrome/app/application_delegate/browser_launcher.h" 12 #import "ios/chrome/app/application_delegate/browser_launcher.h"
13 #import "ios/chrome/app/application_delegate/memory_warning_helper.h" 13 #import "ios/chrome/app/application_delegate/memory_warning_helper.h"
14 #import "ios/chrome/app/application_delegate/metrics_mediator.h" 14 #import "ios/chrome/app/application_delegate/metrics_mediator.h"
15 #import "ios/chrome/app/application_delegate/startup_information.h" 15 #import "ios/chrome/app/application_delegate/startup_information.h"
16 #import "ios/chrome/app/application_delegate/tab_opening.h" 16 #import "ios/chrome/app/application_delegate/tab_opening.h"
17 #import "ios/chrome/app/application_delegate/tab_switching.h" 17 #import "ios/chrome/app/application_delegate/tab_switching.h"
18 #import "ios/chrome/app/application_delegate/user_activity_handler.h" 18 #import "ios/chrome/app/application_delegate/user_activity_handler.h"
19 #import "ios/chrome/app/deferred_initialization_runner.h" 19 #import "ios/chrome/app/deferred_initialization_runner.h"
20 #import "ios/chrome/app/safe_mode/safe_mode_coordinator.h" 20 #import "ios/chrome/app/safe_mode/safe_mode_coordinator.h"
(...skipping 11 matching lines...) Expand all
32 #include "ios/chrome/browser/ui/background_generator.h" 32 #include "ios/chrome/browser/ui/background_generator.h"
33 #import "ios/chrome/browser/ui/browser_view_controller.h" 33 #import "ios/chrome/browser/ui/browser_view_controller.h"
34 #import "ios/chrome/browser/ui/main/browser_view_information.h" 34 #import "ios/chrome/browser/ui/main/browser_view_information.h"
35 #include "ios/net/cookies/cookie_store_ios.h" 35 #include "ios/net/cookies/cookie_store_ios.h"
36 #include "ios/net/cookies/system_cookie_util.h" 36 #include "ios/net/cookies/system_cookie_util.h"
37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 37 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
38 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi der.h" 38 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi der.h"
39 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider .h" 39 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider .h"
40 #include "ios/web/net/request_tracker_impl.h" 40 #include "ios/web/net/request_tracker_impl.h"
41 #include "net/url_request/url_request_context.h" 41 #include "net/url_request/url_request_context.h"
42 42
sdefresne 2017/01/17 14:48:29 Do you forgot to add ARC guards here?
stkhapugin 2017/01/17 14:53:55 Done.
43 namespace { 43 namespace {
44 // Helper method to post |closure| on the UI thread. 44 // Helper method to post |closure| on the UI thread.
45 void PostTaskOnUIThread(const base::Closure& closure) { 45 void PostTaskOnUIThread(const base::Closure& closure) {
46 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, closure); 46 web::WebThread::PostTask(web::WebThread::UI, FROM_HERE, closure);
47 } 47 }
48 NSString* const kStartupAttemptReset = @"StartupAttempReset"; 48 NSString* const kStartupAttemptReset = @"StartupAttempReset";
49 } // namespace 49 } // namespace
50 50
51 @interface AppState ()<SafeModeCoordinatorDelegate> { 51 @interface AppState ()<SafeModeCoordinatorDelegate> {
52 // Container for startup information. 52 // Container for startup information.
53 base::WeakNSProtocol<id<StartupInformation>> _startupInformation; 53 __weak id<StartupInformation> _startupInformation;
54 // Browser launcher to launch browser in different states. 54 // Browser launcher to launch browser in different states.
55 base::WeakNSProtocol<id<BrowserLauncher>> _browserLauncher; 55 __weak id<BrowserLauncher> _browserLauncher;
56 // UIApplicationDelegate for the application. 56 // UIApplicationDelegate for the application.
57 base::WeakNSObject<MainApplicationDelegate> _mainApplicationDelegate; 57 __weak MainApplicationDelegate* _mainApplicationDelegate;
58 // Window for the application. 58 // Window for the application.
59 base::WeakNSObject<UIWindow> _window; 59 __weak UIWindow* _window;
60 60
61 // Variables backing properties of same name. 61 // Variables backing properties of same name.
62 base::scoped_nsobject<SafeModeCoordinator> _safeModeCoordinator; 62 SafeModeCoordinator* _safeModeCoordinator;
63 63
64 // Start of the current session, used for UMA. 64 // Start of the current session, used for UMA.
65 base::TimeTicks _sessionStartTime; 65 base::TimeTicks _sessionStartTime;
66 // YES if the app is currently in the process of terminating. 66 // YES if the app is currently in the process of terminating.
67 BOOL _appIsTerminating; 67 BOOL _appIsTerminating;
68 // Indicates if an NTP tab should be opened once the application has become 68 // Indicates if an NTP tab should be opened once the application has become
69 // active. 69 // active.
70 BOOL _shouldOpenNTPTabOnActive; 70 BOOL _shouldOpenNTPTabOnActive;
71 // Interstitial view used to block any incognito tabs after backgrounding. 71 // Interstitial view used to block any incognito tabs after backgrounding.
72 base::scoped_nsobject<UIView> _incognitoBlocker; 72 UIView* _incognitoBlocker;
73 // Whether the application is currently in the background. 73 // Whether the application is currently in the background.
74 // This is a workaround for rdar://22392526 where 74 // This is a workaround for rdar://22392526 where
75 // -applicationDidEnterBackground: can be called twice. 75 // -applicationDidEnterBackground: can be called twice.
76 // TODO(crbug.com/546196): Remove this once rdar://22392526 is fixed. 76 // TODO(crbug.com/546196): Remove this once rdar://22392526 is fixed.
77 BOOL _applicationInBackground; 77 BOOL _applicationInBackground;
78 // YES if cookies are currently being flushed to disk. 78 // YES if cookies are currently being flushed to disk.
79 BOOL _savingCookies; 79 BOOL _savingCookies;
80 } 80 }
81 81
82 // Safe mode coordinator. If this is non-nil, the app is displaying the safe 82 // Safe mode coordinator. If this is non-nil, the app is displaying the safe
83 // mode UI. 83 // mode UI.
84 @property(nonatomic, retain) SafeModeCoordinator* safeModeCoordinator; 84 @property(nonatomic, strong) SafeModeCoordinator* safeModeCoordinator;
85 85
86 // Return value for -requiresHandlingAfterLaunchWithOptions that determines if 86 // Return value for -requiresHandlingAfterLaunchWithOptions that determines if
87 // UIKit should make followup delegate calls such as 87 // UIKit should make followup delegate calls such as
88 // -performActionForShortcutItem or -openURL. 88 // -performActionForShortcutItem or -openURL.
89 @property(nonatomic, assign) BOOL shouldPerformAdditionalDelegateHandling; 89 @property(nonatomic, assign) BOOL shouldPerformAdditionalDelegateHandling;
90 90
91 // This method is the first to be called when user launches the application. 91 // This method is the first to be called when user launches the application.
92 // Depending on the background tasks history, the state of the application is 92 // Depending on the background tasks history, the state of the application is
93 // either INITIALIZATION_STAGE_BASIC or INITIALIZATION_STAGE_BACKGROUND so this 93 // either INITIALIZATION_STAGE_BASIC or INITIALIZATION_STAGE_BACKGROUND so this
94 // step cannot be included in the |startUpBrowserToStage:| method. 94 // step cannot be included in the |startUpBrowserToStage:| method.
(...skipping 13 matching lines...) Expand all
108 NOTREACHED(); 108 NOTREACHED();
109 return nil; 109 return nil;
110 } 110 }
111 111
112 - (instancetype) 112 - (instancetype)
113 initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher 113 initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
114 startupInformation:(id<StartupInformation>)startupInformation 114 startupInformation:(id<StartupInformation>)startupInformation
115 applicationDelegate:(MainApplicationDelegate*)applicationDelegate { 115 applicationDelegate:(MainApplicationDelegate*)applicationDelegate {
116 self = [super init]; 116 self = [super init];
117 if (self) { 117 if (self) {
118 _startupInformation.reset(startupInformation); 118 _startupInformation = startupInformation;
119 _browserLauncher.reset(browserLauncher); 119 _browserLauncher = browserLauncher;
120 _mainApplicationDelegate.reset(applicationDelegate); 120 _mainApplicationDelegate = applicationDelegate;
121 } 121 }
122 return self; 122 return self;
123 } 123 }
124 124
125 #pragma mark - Properties implementation 125 #pragma mark - Properties implementation
126 126
127 - (SafeModeCoordinator*)safeModeCoordinator { 127 - (SafeModeCoordinator*)safeModeCoordinator {
128 return _safeModeCoordinator; 128 return _safeModeCoordinator;
129 } 129 }
130 130
131 - (void)setSafeModeCoordinator:(SafeModeCoordinator*)safeModeCoordinator { 131 - (void)setSafeModeCoordinator:(SafeModeCoordinator*)safeModeCoordinator {
132 _safeModeCoordinator.reset([safeModeCoordinator retain]); 132 _safeModeCoordinator = safeModeCoordinator;
133 } 133 }
134 134
135 - (void)setWindow:(UIWindow*)window { 135 - (void)setWindow:(UIWindow*)window {
136 _window.reset(window); 136 _window = window;
137 } 137 }
138 138
139 - (UIWindow*)window { 139 - (UIWindow*)window {
140 return _window; 140 return _window;
141 } 141 }
142 142
143 #pragma mark - Public methods. 143 #pragma mark - Public methods.
144 144
145 - (void)applicationDidEnterBackground:(UIApplication*)application 145 - (void)applicationDidEnterBackground:(UIApplication*)application
146 memoryHelper:(MemoryWarningHelper*)memoryHelper 146 memoryHelper:(MemoryWarningHelper*)memoryHelper
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (([[_browserLauncher browserViewInformation] currentBrowserState] && 185 if (([[_browserLauncher browserViewInformation] currentBrowserState] &&
186 [[_browserLauncher browserViewInformation] currentBrowserState] 186 [[_browserLauncher browserViewInformation] currentBrowserState]
187 ->IsOffTheRecord()) || 187 ->IsOffTheRecord()) ||
188 (tabSwitcherIsActive && 188 (tabSwitcherIsActive &&
189 ![[[_browserLauncher browserViewInformation] otrTabModel] isEmpty])) { 189 ![[[_browserLauncher browserViewInformation] otrTabModel] isEmpty])) {
190 // Cover the largest area potentially shown in the app switcher, in case the 190 // Cover the largest area potentially shown in the app switcher, in case the
191 // screenshot is reused in a different orientation or size class. 191 // screenshot is reused in a different orientation or size class.
192 CGRect screenBounds = [[UIScreen mainScreen] bounds]; 192 CGRect screenBounds = [[UIScreen mainScreen] bounds];
193 CGFloat maxDimension = 193 CGFloat maxDimension =
194 std::max(CGRectGetWidth(screenBounds), CGRectGetHeight(screenBounds)); 194 std::max(CGRectGetWidth(screenBounds), CGRectGetHeight(screenBounds));
195 _incognitoBlocker.reset([[UIView alloc] 195 _incognitoBlocker = [[UIView alloc]
196 initWithFrame:CGRectMake(0, 0, maxDimension, maxDimension)]); 196 initWithFrame:CGRectMake(0, 0, maxDimension, maxDimension)];
197 InstallBackgroundInView(_incognitoBlocker); 197 InstallBackgroundInView(_incognitoBlocker);
198 [_window addSubview:_incognitoBlocker]; 198 [_window addSubview:_incognitoBlocker];
199 } 199 }
200 200
201 // Do not save cookies if it is already in progress. 201 // Do not save cookies if it is already in progress.
202 if ([[_browserLauncher browserViewInformation] currentBVC].browserState && 202 if ([[_browserLauncher browserViewInformation] currentBVC].browserState &&
203 !_savingCookies) { 203 !_savingCookies) {
204 // Save cookies to disk. The empty critical closure guarantees that the task 204 // Save cookies to disk. The empty critical closure guarantees that the task
205 // will be run before backgrounding. 205 // will be run before backgrounding.
206 scoped_refptr<net::URLRequestContextGetter> getter = 206 scoped_refptr<net::URLRequestContextGetter> getter =
207 [[_browserLauncher browserViewInformation] currentBVC] 207 [[_browserLauncher browserViewInformation] currentBVC]
208 .browserState->GetRequestContext(); 208 .browserState->GetRequestContext();
209 _savingCookies = YES; 209 _savingCookies = YES;
210 base::Closure criticalClosure = base::MakeCriticalClosure(base::BindBlock(^{ 210 base::Closure criticalClosure =
211 DCHECK_CURRENTLY_ON(web::WebThread::UI); 211 base::MakeCriticalClosure(base::BindBlockArc(^{
212 _savingCookies = NO; 212 DCHECK_CURRENTLY_ON(web::WebThread::UI);
213 })); 213 _savingCookies = NO;
214 }));
214 web::WebThread::PostTask( 215 web::WebThread::PostTask(
215 web::WebThread::IO, FROM_HERE, base::BindBlock(^{ 216 web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{
216 net::CookieStoreIOS* store = static_cast<net::CookieStoreIOS*>( 217 net::CookieStoreIOS* store = static_cast<net::CookieStoreIOS*>(
217 getter->GetURLRequestContext()->cookie_store()); 218 getter->GetURLRequestContext()->cookie_store());
218 // FlushStore() runs its callback on any thread. Jump back to UI. 219 // FlushStore() runs its callback on any thread. Jump back to UI.
219 store->FlushStore(base::Bind(&PostTaskOnUIThread, criticalClosure)); 220 store->FlushStore(base::Bind(&PostTaskOnUIThread, criticalClosure));
220 })); 221 }));
221 } 222 }
222 223
223 // Mark the startup as clean if it hasn't already been. 224 // Mark the startup as clean if it hasn't already been.
224 [[DeferredInitializationRunner sharedInstance] 225 [[DeferredInitializationRunner sharedInstance]
225 runBlockIfNecessary:kStartupAttemptReset]; 226 runBlockIfNecessary:kStartupAttemptReset];
(...skipping 26 matching lines...) Expand all
252 // is not complete. 253 // is not complete.
253 [self initializeUI]; 254 [self initializeUI];
254 return; 255 return;
255 } 256 }
256 if ([self isInSafeMode]) 257 if ([self isInSafeMode])
257 return; 258 return;
258 259
259 _applicationInBackground = NO; 260 _applicationInBackground = NO;
260 261
261 [_incognitoBlocker removeFromSuperview]; 262 [_incognitoBlocker removeFromSuperview];
262 _incognitoBlocker.reset(); 263 _incognitoBlocker = nil;
263 264
264 breakpad_helper::SetCurrentlyInBackground(false); 265 breakpad_helper::SetCurrentlyInBackground(false);
265 266
266 // Update the state of metrics and crash reporting, as the method of 267 // Update the state of metrics and crash reporting, as the method of
267 // communication may have changed while the app was in the background. 268 // communication may have changed while the app was in the background.
268 [metricsMediator updateMetricsStateBasedOnPrefsUserTriggered:NO]; 269 [metricsMediator updateMetricsStateBasedOnPrefsUserTriggered:NO];
269 270
270 // Send any feedback that might be still on temporary storage. 271 // Send any feedback that might be still on temporary storage.
271 ios::GetChromeBrowserProvider()->GetUserFeedbackProvider()->Synchronize(); 272 ios::GetChromeBrowserProvider()->GetUserFeedbackProvider()->Synchronize();
272 273
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 UMA_HISTOGRAM_COUNTS_10000("CookieIOS.CookieCountOnForegrounding", 309 UMA_HISTOGRAM_COUNTS_10000("CookieIOS.CookieCountOnForegrounding",
309 cookie_count); 310 cookie_count);
310 net::CheckForCookieLoss(cookie_count, 311 net::CheckForCookieLoss(cookie_count,
311 net::COOKIES_APPLICATION_FOREGROUNDED); 312 net::COOKIES_APPLICATION_FOREGROUNDED);
312 } 313 }
313 } 314 }
314 315
315 - (void)resumeSessionWithTabOpener:(id<TabOpening>)tabOpener 316 - (void)resumeSessionWithTabOpener:(id<TabOpening>)tabOpener
316 tabSwitcher:(id<TabSwitching>)tabSwitcher { 317 tabSwitcher:(id<TabSwitching>)tabSwitcher {
317 [_incognitoBlocker removeFromSuperview]; 318 [_incognitoBlocker removeFromSuperview];
318 _incognitoBlocker.reset(); 319 _incognitoBlocker = nil;
319 320
320 DCHECK([_browserLauncher browserInitializationStage] == 321 DCHECK([_browserLauncher browserInitializationStage] ==
321 INITIALIZATION_STAGE_FOREGROUND); 322 INITIALIZATION_STAGE_FOREGROUND);
322 _sessionStartTime = base::TimeTicks::Now(); 323 _sessionStartTime = base::TimeTicks::Now();
323 [[[_browserLauncher browserViewInformation] mainTabModel] 324 [[[_browserLauncher browserViewInformation] mainTabModel]
324 resetSessionMetrics]; 325 resetSessionMetrics];
325 326
326 if ([_startupInformation startupParameters]) { 327 if ([_startupInformation startupParameters]) {
327 [UserActivityHandler 328 [UserActivityHandler
328 handleStartupParametersWithTabOpener:tabOpener 329 handleStartupParametersWithTabOpener:tabOpener
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 437
437 #pragma mark - Internal methods. 438 #pragma mark - Internal methods.
438 439
439 - (void)initializeUI { 440 - (void)initializeUI {
440 _userInteracted = YES; 441 _userInteracted = YES;
441 [self saveLaunchDetailsToDefaults]; 442 [self saveLaunchDetailsToDefaults];
442 443
443 DCHECK([_window rootViewController] == nil); 444 DCHECK([_window rootViewController] == nil);
444 if ([SafeModeCoordinator shouldStart]) { 445 if ([SafeModeCoordinator shouldStart]) {
445 SafeModeCoordinator* safeModeCoordinator = 446 SafeModeCoordinator* safeModeCoordinator =
446 [[[SafeModeCoordinator alloc] initWithWindow:_window] autorelease]; 447 [[SafeModeCoordinator alloc] initWithWindow:_window];
447 448
448 self.safeModeCoordinator = safeModeCoordinator; 449 self.safeModeCoordinator = safeModeCoordinator;
449 [self.safeModeCoordinator setDelegate:self]; 450 [self.safeModeCoordinator setDelegate:self];
450 451
451 // Activate the main window, which will prompt the views to load. 452 // Activate the main window, which will prompt the views to load.
452 [_window makeKeyAndVisible]; 453 [_window makeKeyAndVisible];
453 454
454 [self.safeModeCoordinator start]; 455 [self.safeModeCoordinator start];
455 return; 456 return;
456 } 457 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 self = [self initWithBrowserLauncher:browserLauncher 491 self = [self initWithBrowserLauncher:browserLauncher
491 startupInformation:startupInformation 492 startupInformation:startupInformation
492 applicationDelegate:applicationDelegate]; 493 applicationDelegate:applicationDelegate];
493 if (self) { 494 if (self) {
494 _shouldOpenNTPTabOnActive = shouldOpenNTP; 495 _shouldOpenNTPTabOnActive = shouldOpenNTP;
495 } 496 }
496 return self; 497 return self;
497 } 498 }
498 499
499 @end 500 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698