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

Side by Side Diff: ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.mm

Issue 2936583002: [ObjC ARC] Converts ios/chrome/browser/ui/authentication:authentication to ARC. (Closed)
Patch Set: Review feedback. 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
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/browser/ui/authentication/signed_in_accounts_view_controller .h" 5 #import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller .h"
6 6
7 #import "base/mac/foundation_util.h" 7 #import "base/mac/foundation_util.h"
8 #include "components/signin/core/browser/account_tracker_service.h" 8 #include "components/signin/core/browser/account_tracker_service.h"
9 #include "components/signin/core/browser/profile_oauth2_token_service.h" 9 #include "components/signin/core/browser/profile_oauth2_token_service.h"
10 #include "components/signin/ios/browser/oauth2_token_service_observer_bridge.h" 10 #include "components/signin/ios/browser/oauth2_token_service_observer_bridge.h"
11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
12 #include "ios/chrome/browser/signin/account_tracker_service_factory.h" 12 #include "ios/chrome/browser/signin/account_tracker_service_factory.h"
13 #include "ios/chrome/browser/signin/authentication_service.h" 13 #include "ios/chrome/browser/signin/authentication_service.h"
14 #include "ios/chrome/browser/signin/authentication_service_factory.h" 14 #include "ios/chrome/browser/signin/authentication_service_factory.h"
15 #include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" 15 #include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h"
stkhapugin 2017/06/13 11:58:03 This header needs an __unsafe_unretained annotatio
marq (ping after 24h) 2017/06/13 13:55:10 Done.
16 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" 16 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h"
17 #import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h" 17 #import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h"
18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_ite m.h" 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_account_ite m.h"
19 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 19 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
21 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 21 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
22 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 22 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
23 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 23 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
24 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 24 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
25 #import "ios/chrome/browser/ui/uikit_ui_util.h" 25 #import "ios/chrome/browser/ui/uikit_ui_util.h"
26 #include "ios/chrome/grit/ios_chromium_strings.h" 26 #include "ios/chrome/grit/ios_chromium_strings.h"
27 #include "ios/chrome/grit/ios_strings.h" 27 #include "ios/chrome/grit/ios_strings.h"
28 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 28 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
29 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" 29 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
30 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" 30 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
31 #include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" 31 #include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h"
32 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 32 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
33 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h" 33 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h"
34 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 34 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
35 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 35 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
36 #include "ui/base/l10n/l10n_util_mac.h" 36 #include "ui/base/l10n/l10n_util_mac.h"
37 37
38 #if !defined(__has_feature) || !__has_feature(objc_arc)
39 #error "This file requires ARC support."
40 #endif
41
38 namespace { 42 namespace {
39 43
40 const int kMaxShownAccounts = 3; 44 const int kMaxShownAccounts = 3;
41 const CGFloat kAccountsExtraBottomInset = 16; 45 const CGFloat kAccountsExtraBottomInset = 16;
42 const CGFloat kVerticalPadding = 24; 46 const CGFloat kVerticalPadding = 24;
43 const CGFloat kButtonVerticalPadding = 16; 47 const CGFloat kButtonVerticalPadding = 16;
44 const CGFloat kHorizontalPadding = 24; 48 const CGFloat kHorizontalPadding = 24;
45 const CGFloat kAccountsHorizontalPadding = 8; 49 const CGFloat kAccountsHorizontalPadding = 8;
46 const CGFloat kButtonHorizontalPadding = 16; 50 const CGFloat kButtonHorizontalPadding = 16;
47 const CGFloat kBetweenButtonsPadding = 8; 51 const CGFloat kBetweenButtonsPadding = 8;
(...skipping 10 matching lines...) Expand all
58 62
59 // Whether the Signed In Accounts view is currently being shown. 63 // Whether the Signed In Accounts view is currently being shown.
60 BOOL gSignedInAccountsViewControllerIsShown = NO; 64 BOOL gSignedInAccountsViewControllerIsShown = NO;
61 65
62 } // namespace 66 } // namespace
63 67
64 @interface SignedInAccountsCollectionViewController 68 @interface SignedInAccountsCollectionViewController
65 : CollectionViewController<ChromeIdentityServiceObserver> { 69 : CollectionViewController<ChromeIdentityServiceObserver> {
66 ios::ChromeBrowserState* _browserState; // Weak. 70 ios::ChromeBrowserState* _browserState; // Weak.
67 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; 71 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver;
68 base::scoped_nsobject<ResizedAvatarCache> _avatarCache; 72 ResizedAvatarCache* _avatarCache;
69 73
70 // Enable lookup of item corresponding to a given identity GAIA ID string. 74 // Enable lookup of item corresponding to a given identity GAIA ID string.
71 base::scoped_nsobject<NSDictionary<NSString*, CollectionViewItem*>> 75 NSDictionary<NSString*, CollectionViewItem*>* _identityMap;
72 _identityMap;
73 } 76 }
74 @end 77 @end
75 78
76 @implementation SignedInAccountsCollectionViewController 79 @implementation SignedInAccountsCollectionViewController
77 80
78 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { 81 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
79 self = [super initWithStyle:CollectionViewControllerStyleDefault]; 82 self = [super initWithStyle:CollectionViewControllerStyleDefault];
80 if (self) { 83 if (self) {
81 _browserState = browserState; 84 _browserState = browserState;
82 _avatarCache.reset([[ResizedAvatarCache alloc] init]); 85 _avatarCache = [[ResizedAvatarCache alloc] init];
83 _identityServiceObserver.reset( 86 _identityServiceObserver.reset(
84 new ChromeIdentityServiceObserverBridge(self)); 87 new ChromeIdentityServiceObserverBridge(self));
85 [self loadModel]; 88 [self loadModel];
86 } 89 }
87 return self; 90 return self;
88 } 91 }
89 92
90 - (void)viewDidLoad { 93 - (void)viewDidLoad {
91 [super viewDidLoad]; 94 [super viewDidLoad];
92 95
93 self.styler.shouldHideSeparators = YES; 96 self.styler.shouldHideSeparators = YES;
94 self.collectionView.backgroundColor = [UIColor clearColor]; 97 self.collectionView.backgroundColor = [UIColor clearColor];
95 98
96 // Add an inset at the bottom so the user can see whether it is possible to 99 // Add an inset at the bottom so the user can see whether it is possible to
97 // scroll to see additional accounts. 100 // scroll to see additional accounts.
98 UIEdgeInsets contentInset = self.collectionView.contentInset; 101 UIEdgeInsets contentInset = self.collectionView.contentInset;
99 contentInset.bottom += kAccountsExtraBottomInset; 102 contentInset.bottom += kAccountsExtraBottomInset;
100 self.collectionView.contentInset = contentInset; 103 self.collectionView.contentInset = contentInset;
101 } 104 }
102 105
103 #pragma mark CollectionViewController 106 #pragma mark CollectionViewController
104 107
105 - (void)loadModel { 108 - (void)loadModel {
106 [super loadModel]; 109 [super loadModel];
107 CollectionViewModel* model = self.collectionViewModel; 110 CollectionViewModel* model = self.collectionViewModel;
108 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = 111 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap =
109 [[[NSMutableDictionary alloc] init] autorelease]; 112 [[NSMutableDictionary alloc] init];
110 113
111 [model addSectionWithIdentifier:SectionIdentifierAccounts]; 114 [model addSectionWithIdentifier:SectionIdentifierAccounts];
112 ProfileOAuth2TokenService* oauth2_service = 115 ProfileOAuth2TokenService* oauth2_service =
113 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); 116 OAuth2TokenServiceFactory::GetForBrowserState(_browserState);
114 AccountTrackerService* accountTracker = 117 AccountTrackerService* accountTracker =
115 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); 118 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState);
116 for (const std::string& account_id : oauth2_service->GetAccounts()) { 119 for (const std::string& account_id : oauth2_service->GetAccounts()) {
117 AccountInfo account = accountTracker->GetAccountInfo(account_id); 120 AccountInfo account = accountTracker->GetAccountInfo(account_id);
118 ChromeIdentity* identity = ios::GetChromeBrowserProvider() 121 ChromeIdentity* identity = ios::GetChromeBrowserProvider()
119 ->GetChromeIdentityService() 122 ->GetChromeIdentityService()
120 ->GetIdentityWithGaiaID(account.gaia); 123 ->GetIdentityWithGaiaID(account.gaia);
121 CollectionViewItem* item = [self accountItem:identity]; 124 CollectionViewItem* item = [self accountItem:identity];
122 [model addItem:item toSectionWithIdentifier:SectionIdentifierAccounts]; 125 [model addItem:item toSectionWithIdentifier:SectionIdentifierAccounts];
123 [mutableIdentityMap setObject:item forKey:identity.gaiaID]; 126 [mutableIdentityMap setObject:item forKey:identity.gaiaID];
124 } 127 }
125 _identityMap.reset([mutableIdentityMap retain]); 128 _identityMap = mutableIdentityMap;
126 } 129 }
127 130
128 #pragma mark Model objects 131 #pragma mark Model objects
129 132
130 - (CollectionViewItem*)accountItem:(ChromeIdentity*)identity { 133 - (CollectionViewItem*)accountItem:(ChromeIdentity*)identity {
131 CollectionViewAccountItem* item = [[[CollectionViewAccountItem alloc] 134 CollectionViewAccountItem* item =
132 initWithType:ItemTypeAccount] autorelease]; 135 [[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount];
133 [self updateAccountItem:item withIdentity:identity]; 136 [self updateAccountItem:item withIdentity:identity];
134 return item; 137 return item;
135 } 138 }
136 139
137 - (void)updateAccountItem:(CollectionViewAccountItem*)item 140 - (void)updateAccountItem:(CollectionViewAccountItem*)item
138 withIdentity:(ChromeIdentity*)identity { 141 withIdentity:(ChromeIdentity*)identity {
139 item.image = [_avatarCache resizedAvatarForIdentity:identity]; 142 item.image = [_avatarCache resizedAvatarForIdentity:identity];
140 item.text = [identity userFullName]; 143 item.text = [identity userFullName];
141 item.detailText = [identity userEmail]; 144 item.detailText = [identity userEmail];
142 item.chromeIdentity = identity; 145 item.chromeIdentity = identity;
(...skipping 30 matching lines...) Expand all
173 - (void)onChromeIdentityServiceWillBeDestroyed { 176 - (void)onChromeIdentityServiceWillBeDestroyed {
174 _identityServiceObserver.reset(); 177 _identityServiceObserver.reset();
175 } 178 }
176 179
177 @end 180 @end
178 181
179 @interface SignedInAccountsViewController ()< 182 @interface SignedInAccountsViewController ()<
180 OAuth2TokenServiceObserverBridgeDelegate> { 183 OAuth2TokenServiceObserverBridgeDelegate> {
181 ios::ChromeBrowserState* _browserState; // Weak. 184 ios::ChromeBrowserState* _browserState; // Weak.
182 std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver; 185 std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver;
183 base::scoped_nsobject<MDCDialogTransitionController> _transitionController; 186 MDCDialogTransitionController* _transitionController;
184 187
185 base::scoped_nsobject<UILabel> _titleLabel; 188 UILabel* _titleLabel;
186 base::scoped_nsobject<SignedInAccountsCollectionViewController> 189 SignedInAccountsCollectionViewController* _accountsCollection;
187 _accountsCollection; 190 UILabel* _infoLabel;
188 base::scoped_nsobject<UILabel> _infoLabel; 191 MDCButton* _primaryButton;
189 base::scoped_nsobject<MDCButton> _primaryButton; 192 MDCButton* _secondaryButton;
190 base::scoped_nsobject<MDCButton> _secondaryButton;
191 } 193 }
192 @end 194 @end
193 195
194 @implementation SignedInAccountsViewController 196 @implementation SignedInAccountsViewController
195 197
196 + (BOOL)shouldBePresentedForBrowserState: 198 + (BOOL)shouldBePresentedForBrowserState:
197 (ios::ChromeBrowserState*)browserState { 199 (ios::ChromeBrowserState*)browserState {
198 if (!browserState || browserState->IsOffTheRecord()) { 200 if (!browserState || browserState->IsOffTheRecord()) {
199 return NO; 201 return NO;
200 } 202 }
201 AuthenticationService* authService = 203 AuthenticationService* authService =
202 AuthenticationServiceFactory::GetForBrowserState(browserState); 204 AuthenticationServiceFactory::GetForBrowserState(browserState);
203 return !gSignedInAccountsViewControllerIsShown && 205 return !gSignedInAccountsViewControllerIsShown &&
204 authService->IsAuthenticated() && authService->HaveAccountsChanged(); 206 authService->IsAuthenticated() && authService->HaveAccountsChanged();
205 } 207 }
206 208
207 #pragma mark Initialization 209 #pragma mark Initialization
208 210
209 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { 211 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
210 self = [super initWithNibName:nil bundle:nil]; 212 self = [super initWithNibName:nil bundle:nil];
211 if (self) { 213 if (self) {
212 _browserState = browserState; 214 _browserState = browserState;
213 _tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge( 215 _tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge(
214 OAuth2TokenServiceFactory::GetForBrowserState(_browserState), self)); 216 OAuth2TokenServiceFactory::GetForBrowserState(_browserState), self));
215 _transitionController.reset([[MDCDialogTransitionController alloc] init]); 217 _transitionController = [[MDCDialogTransitionController alloc] init];
216 self.modalPresentationStyle = UIModalPresentationCustom; 218 self.modalPresentationStyle = UIModalPresentationCustom;
217 self.transitioningDelegate = _transitionController; 219 self.transitioningDelegate = _transitionController;
218 } 220 }
219 return self; 221 return self;
220 } 222 }
221 223
222 - (void)dismiss { 224 - (void)dismiss {
223 [self.presentingViewController dismissViewControllerAnimated:YES 225 [self.presentingViewController dismissViewControllerAnimated:YES
224 completion:nil]; 226 completion:nil];
225 } 227 }
226 228
227 - (void)dealloc { 229 - (void)dealloc {
228 [_primaryButton removeTarget:self 230 [_primaryButton removeTarget:self
229 action:@selector(onPrimaryButtonPressed:) 231 action:@selector(onPrimaryButtonPressed:)
230 forControlEvents:UIControlEventTouchDown]; 232 forControlEvents:UIControlEventTouchDown];
231 [_secondaryButton removeTarget:self 233 [_secondaryButton removeTarget:self
232 action:@selector(onSecondaryButtonPressed:) 234 action:@selector(onSecondaryButtonPressed:)
233 forControlEvents:UIControlEventTouchDown]; 235 forControlEvents:UIControlEventTouchDown];
234 [super dealloc];
235 } 236 }
236 237
237 #pragma mark UIViewController 238 #pragma mark UIViewController
238 239
239 - (CGSize)preferredContentSize { 240 - (CGSize)preferredContentSize {
240 CGFloat width = MIN(kDialogMaxWidth, 241 CGFloat width = MIN(kDialogMaxWidth,
241 self.presentingViewController.view.bounds.size.width - 242 self.presentingViewController.view.bounds.size.width -
242 2 * kMDCMinHorizontalPadding); 243 2 * kMDCMinHorizontalPadding);
243 OAuth2TokenService* token_service = 244 OAuth2TokenService* token_service =
244 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); 245 OAuth2TokenServiceFactory::GetForBrowserState(_browserState);
245 int shownAccounts = 246 int shownAccounts =
246 MIN(kMaxShownAccounts, token_service->GetAccounts().size()); 247 MIN(kMaxShownAccounts, token_service->GetAccounts().size());
247 CGSize maxSize = CGSizeMake(width - 2 * kHorizontalPadding, CGFLOAT_MAX); 248 CGSize maxSize = CGSizeMake(width - 2 * kHorizontalPadding, CGFLOAT_MAX);
248 CGSize buttonSize = [_primaryButton sizeThatFits:maxSize]; 249 CGSize buttonSize = [_primaryButton sizeThatFits:maxSize];
249 CGSize infoSize = [_infoLabel sizeThatFits:maxSize]; 250 CGSize infoSize = [_infoLabel sizeThatFits:maxSize];
250 CGSize titleSize = [_titleLabel sizeThatFits:maxSize]; 251 CGSize titleSize = [_titleLabel sizeThatFits:maxSize];
251 CGFloat height = kVerticalPadding + titleSize.height + kVerticalPadding + 252 CGFloat height = kVerticalPadding + titleSize.height + kVerticalPadding +
252 shownAccounts * MDCCellDefaultOneLineWithAvatarHeight + 253 shownAccounts * MDCCellDefaultOneLineWithAvatarHeight +
253 kVerticalPadding + infoSize.height + kVerticalPadding + 254 kVerticalPadding + infoSize.height + kVerticalPadding +
254 buttonSize.height + kButtonVerticalPadding; 255 buttonSize.height + kButtonVerticalPadding;
255 return CGSizeMake(width, height); 256 return CGSizeMake(width, height);
256 } 257 }
257 258
258 - (void)viewDidLoad { 259 - (void)viewDidLoad {
259 [super viewDidLoad]; 260 [super viewDidLoad];
260 261
261 self.view.backgroundColor = [UIColor whiteColor]; 262 self.view.backgroundColor = [UIColor whiteColor];
262 263
263 _titleLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); 264 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
264 _titleLabel.get().text = 265 _titleLabel.text =
265 l10n_util::GetNSString(IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_TITLE); 266 l10n_util::GetNSString(IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_TITLE);
266 _titleLabel.get().textColor = [[MDCPalette greyPalette] tint900]; 267 _titleLabel.textColor = [[MDCPalette greyPalette] tint900];
267 _titleLabel.get().font = [MDCTypography headlineFont]; 268 _titleLabel.font = [MDCTypography headlineFont];
268 _titleLabel.get().translatesAutoresizingMaskIntoConstraints = NO; 269 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
269 [self.view addSubview:_titleLabel]; 270 [self.view addSubview:_titleLabel];
270 271
271 _accountsCollection.reset([[SignedInAccountsCollectionViewController alloc] 272 _accountsCollection = [[SignedInAccountsCollectionViewController alloc]
272 initWithBrowserState:_browserState]); 273 initWithBrowserState:_browserState];
273 _accountsCollection.get().view.translatesAutoresizingMaskIntoConstraints = NO; 274 _accountsCollection.view.translatesAutoresizingMaskIntoConstraints = NO;
274 [self addChildViewController:_accountsCollection]; 275 [self addChildViewController:_accountsCollection];
275 [self.view addSubview:_accountsCollection.get().view]; 276 [self.view addSubview:_accountsCollection.view];
276 [_accountsCollection didMoveToParentViewController:self]; 277 [_accountsCollection didMoveToParentViewController:self];
277 278
278 _infoLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); 279 _infoLabel = [[UILabel alloc] initWithFrame:CGRectZero];
279 _infoLabel.get().text = 280 _infoLabel.text =
280 l10n_util::GetNSString(IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_INFO); 281 l10n_util::GetNSString(IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_INFO);
281 _infoLabel.get().numberOfLines = 0; 282 _infoLabel.numberOfLines = 0;
282 _infoLabel.get().textColor = [[MDCPalette greyPalette] tint700]; 283 _infoLabel.textColor = [[MDCPalette greyPalette] tint700];
283 _infoLabel.get().font = [MDCTypography body1Font]; 284 _infoLabel.font = [MDCTypography body1Font];
284 _infoLabel.get().translatesAutoresizingMaskIntoConstraints = NO; 285 _infoLabel.translatesAutoresizingMaskIntoConstraints = NO;
285 [self.view addSubview:_infoLabel]; 286 [self.view addSubview:_infoLabel];
286 287
287 _primaryButton.reset([[MDCFlatButton alloc] init]); 288 _primaryButton = [[MDCFlatButton alloc] init];
288 [_primaryButton addTarget:self 289 [_primaryButton addTarget:self
289 action:@selector(onPrimaryButtonPressed:) 290 action:@selector(onPrimaryButtonPressed:)
290 forControlEvents:UIControlEventTouchUpInside]; 291 forControlEvents:UIControlEventTouchUpInside];
291 [_primaryButton 292 [_primaryButton
292 setTitle:l10n_util::GetNSString(IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_OK_BUTTON) 293 setTitle:l10n_util::GetNSString(IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_OK_BUTTON)
293 forState:UIControlStateNormal]; 294 forState:UIControlStateNormal];
294 [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] 295 [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]
295 forState:UIControlStateNormal]; 296 forState:UIControlStateNormal];
296 _primaryButton.get().customTitleColor = [UIColor whiteColor]; 297 _primaryButton.customTitleColor = [UIColor whiteColor];
297 _primaryButton.get().underlyingColorHint = [UIColor blackColor]; 298 _primaryButton.underlyingColorHint = [UIColor blackColor];
298 _primaryButton.get().inkColor = [UIColor colorWithWhite:1 alpha:0.2f]; 299 _primaryButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2f];
299 _primaryButton.get().translatesAutoresizingMaskIntoConstraints = NO; 300 _primaryButton.translatesAutoresizingMaskIntoConstraints = NO;
300 [self.view addSubview:_primaryButton]; 301 [self.view addSubview:_primaryButton];
301 302
302 _secondaryButton.reset([[MDCFlatButton alloc] init]); 303 _secondaryButton = [[MDCFlatButton alloc] init];
303 [_secondaryButton addTarget:self 304 [_secondaryButton addTarget:self
304 action:@selector(onSecondaryButtonPressed:) 305 action:@selector(onSecondaryButtonPressed:)
305 forControlEvents:UIControlEventTouchUpInside]; 306 forControlEvents:UIControlEventTouchUpInside];
306 [_secondaryButton 307 [_secondaryButton
307 setTitle:l10n_util::GetNSString( 308 setTitle:l10n_util::GetNSString(
308 IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_SETTINGS_BUTTON) 309 IDS_IOS_SIGNED_IN_ACCOUNTS_VIEW_SETTINGS_BUTTON)
309 forState:UIControlStateNormal]; 310 forState:UIControlStateNormal];
310 [_secondaryButton setBackgroundColor:[UIColor whiteColor] 311 [_secondaryButton setBackgroundColor:[UIColor whiteColor]
311 forState:UIControlStateNormal]; 312 forState:UIControlStateNormal];
312 _secondaryButton.get().customTitleColor = 313 _secondaryButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500];
313 [[MDCPalette cr_bluePalette] tint500]; 314 _secondaryButton.underlyingColorHint = [UIColor whiteColor];
314 _secondaryButton.get().underlyingColorHint = [UIColor whiteColor]; 315 _secondaryButton.inkColor = [UIColor colorWithWhite:0 alpha:0.06f];
315 _secondaryButton.get().inkColor = [UIColor colorWithWhite:0 alpha:0.06f]; 316 _secondaryButton.translatesAutoresizingMaskIntoConstraints = NO;
316 _secondaryButton.get().translatesAutoresizingMaskIntoConstraints = NO;
317 [self.view addSubview:_secondaryButton]; 317 [self.view addSubview:_secondaryButton];
318 318
319 NSDictionary* views = @{ 319 NSDictionary* views = @{
320 @"title" : _titleLabel, 320 @"title" : _titleLabel,
321 @"accounts" : _accountsCollection.get().view, 321 @"accounts" : _accountsCollection.view,
322 @"info" : _infoLabel, 322 @"info" : _infoLabel,
323 @"primaryButton" : _primaryButton, 323 @"primaryButton" : _primaryButton,
324 @"secondaryButton" : _secondaryButton, 324 @"secondaryButton" : _secondaryButton,
325 }; 325 };
326 NSDictionary* metrics = @{ 326 NSDictionary* metrics = @{
327 @"verticalPadding" : @(kVerticalPadding), 327 @"verticalPadding" : @(kVerticalPadding),
328 @"accountsVerticalPadding" : 328 @"accountsVerticalPadding" :
329 @(kVerticalPadding - kAccountsExtraBottomInset), 329 @(kVerticalPadding - kAccountsExtraBottomInset),
330 @"buttonVerticalPadding" : @(kButtonVerticalPadding), 330 @"buttonVerticalPadding" : @(kButtonVerticalPadding),
331 @"horizontalPadding" : @(kHorizontalPadding), 331 @"horizontalPadding" : @(kHorizontalPadding),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 364
365 #pragma mark Events 365 #pragma mark Events
366 366
367 - (void)onPrimaryButtonPressed:(id)sender { 367 - (void)onPrimaryButtonPressed:(id)sender {
368 [self dismiss]; 368 [self dismiss];
369 } 369 }
370 370
371 - (void)onSecondaryButtonPressed:(id)sender { 371 - (void)onSecondaryButtonPressed:(id)sender {
372 [self dismiss]; 372 [self dismiss];
373 base::scoped_nsobject<GenericChromeCommand> showAccountsSettingsCommand( 373 GenericChromeCommand* showAccountsSettingsCommand =
374 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]); 374 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS];
375 [self chromeExecuteCommand:showAccountsSettingsCommand]; 375 [self chromeExecuteCommand:showAccountsSettingsCommand];
376 } 376 }
377 377
378 #pragma mark OAuth2TokenServiceObserverBridgeDelegate 378 #pragma mark OAuth2TokenServiceObserverBridgeDelegate
379 379
380 - (void)onEndBatchChanges { 380 - (void)onEndBatchChanges {
381 ProfileOAuth2TokenService* tokenService = 381 ProfileOAuth2TokenService* tokenService =
382 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); 382 OAuth2TokenServiceFactory::GetForBrowserState(_browserState);
383 if (tokenService->GetAccounts().empty()) { 383 if (tokenService->GetAccounts().empty()) {
384 [self dismiss]; 384 [self dismiss];
385 return; 385 return;
386 } 386 }
387 [_accountsCollection loadModel]; 387 [_accountsCollection loadModel];
388 [_accountsCollection.get().collectionView reloadData]; 388 [_accountsCollection.collectionView reloadData];
389 } 389 }
390 390
391 @end 391 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698