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

Side by Side Diff: ios/clean/chrome/app/steps/root_coordinator+application_step.mm

Issue 2800313002: [ios] RootCoordinator and view controller. (Closed)
Patch Set: Unittests, showcase, and clean up. Created 3 years, 8 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 2017 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/clean/chrome/app/steps/tab_grid_coordinator+application_step.h" 5 #import "ios/clean/chrome/app/steps/root_coordinator+application_step.h"
6 6
7 #import "base/supports_user_data.h" 7 #import "base/supports_user_data.h"
8 #import "ios/clean/chrome/app/application_state.h" 8 #import "ios/clean/chrome/app/application_state.h"
9 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" 9 #import "ios/shared/chrome/browser/ui/browser_list/browser.h"
10 #import "ios/shared/chrome/browser/ui/browser_list/browser_list.h" 10 #import "ios/shared/chrome/browser/ui/browser_list/browser_list.h"
11 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal. h" 11 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal. h"
12 12
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 14 #error "This file requires ARC support."
15 #endif 15 #endif
16 16
17 namespace { 17 namespace {
18 // SupportsUserData storage container for a BrowserCoordinator object, which 18 // SupportsUserData storage container for a BrowserCoordinator object, which
19 // keeps a strong reference to the object it is initialized with. 19 // keeps a strong reference to the object it is initialized with.
20 class RootCoordinatorContainer : public base::SupportsUserData::Data { 20 class RootCoordinatorContainer : public base::SupportsUserData::Data {
21 public: 21 public:
22 explicit RootCoordinatorContainer(BrowserCoordinator* coordinator) 22 explicit RootCoordinatorContainer(BrowserCoordinator* coordinator)
23 : coordinator_(coordinator) {} 23 : coordinator_(coordinator) {}
24 24
25 private: 25 private:
26 // Mark this variable unused to avoid a compiler warning; the compiler 26 // Mark this variable unused to avoid a compiler warning; the compiler
27 // doesn't have visibility into the ARC-injected retain/release. 27 // doesn't have visibility into the ARC-injected retain/release.
28 BrowserCoordinator* __attribute__((unused)) coordinator_; 28 BrowserCoordinator* __attribute__((unused)) coordinator_;
29 }; 29 };
30 30
31 const char kRootCoordinatorContainerKey[] = "root_coordinator"; 31 const char kRootCoordinatorContainerKey[] = "root_coordinator";
32 } // namespace 32 } // namespace
33 33
34 @interface StopTabGridCoordinator : NSObject<ApplicationStep> 34 @interface StopRootCoordinator : NSObject<ApplicationStep>
35 @end 35 @end
36 36
37 @implementation TabGridCoordinator (ApplicationStep) 37 @implementation RootCoordinator (ApplicationStep)
38 38
39 - (BOOL)canRunInState:(ApplicationState*)state { 39 - (BOOL)canRunInState:(ApplicationState*)state {
40 return [state.window isKeyWindow] && state.phase == APPLICATION_FOREGROUNDED; 40 return [state.window isKeyWindow] && state.phase == APPLICATION_FOREGROUNDED;
41 } 41 }
42 42
43 - (void)runInState:(ApplicationState*)state { 43 - (void)runInState:(ApplicationState*)state {
44 self.browser = 44 self.browser =
45 BrowserList::FromBrowserState(state.browserState)->CreateNewBrowser(); 45 BrowserList::FromBrowserState(state.browserState)->CreateNewBrowser();
46 [self start]; 46 [self start];
47 47
48 state.window.rootViewController = self.viewController; 48 state.window.rootViewController = self.viewController;
49 49
50 // Size the main view controller to fit the whole screen. 50 // Size the main view controller to fit the whole screen.
51 [self.viewController.view setFrame:state.window.bounds]; 51 [self.viewController.view setFrame:state.window.bounds];
52 52
53 // Tell the application state to use this object to open URLs. 53 // Tell the application state to use this object to open URLs.
54 state.URLOpener = self; 54 state.URLOpener = self;
55 55
56 // Show the window. 56 // Show the window.
57 state.window.hidden = NO; 57 state.window.hidden = NO;
58 58
59 // Make sure this object stays alive. 59 // Make sure this object stays alive.
60 state.persistentState->SetUserData(kRootCoordinatorContainerKey, 60 state.persistentState->SetUserData(kRootCoordinatorContainerKey,
61 new RootCoordinatorContainer(self)); 61 new RootCoordinatorContainer(self));
62 62
63 // Add a termination step to remove this object. 63 // Add a termination step to remove this object.
64 [[state terminationSteps] addObject:[[StopTabGridCoordinator alloc] init]]; 64 [[state terminationSteps] addObject:[[StopRootCoordinator alloc] init]];
65 } 65 }
66 66
67 @end 67 @end
68 68
69 @implementation StopTabGridCoordinator 69 @implementation StopRootCoordinator
70 70
71 - (BOOL)canRunInState:(ApplicationState*)state { 71 - (BOOL)canRunInState:(ApplicationState*)state {
72 return state.phase = APPLICATION_TERMINATING; 72 return state.phase = APPLICATION_TERMINATING;
73 } 73 }
74 74
75 - (void)runInState:(ApplicationState*)state { 75 - (void)runInState:(ApplicationState*)state {
76 state.persistentState->RemoveUserData(kRootCoordinatorContainerKey); 76 state.persistentState->RemoveUserData(kRootCoordinatorContainerKey);
77 } 77 }
78 78
79 @end 79 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698