| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/settings/accounts_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" |
| 6 | 6 |
| 7 #import "base/ios/weak_nsobject.h" | |
| 8 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | |
| 10 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/browser_sync/profile_sync_service.h" | 11 #include "components/browser_sync/profile_sync_service.h" |
| 14 #include "components/signin/core/browser/account_tracker_service.h" | 12 #include "components/signin/core/browser/account_tracker_service.h" |
| 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 13 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 16 #include "components/signin/core/browser/signin_manager.h" | 14 #include "components/signin/core/browser/signin_manager.h" |
| 17 #import "components/signin/ios/browser/oauth2_token_service_observer_bridge.h" | 15 #import "components/signin/ios/browser/oauth2_token_service_observer_bridge.h" |
| 18 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 47 #include "ios/chrome/grit/ios_chromium_strings.h" | 45 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 48 #include "ios/chrome/grit/ios_strings.h" | 46 #include "ios/chrome/grit/ios_strings.h" |
| 49 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 47 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 50 #import "ios/public/provider/chrome/browser/images/branded_image_provider.h" | 48 #import "ios/public/provider/chrome/browser/images/branded_image_provider.h" |
| 51 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 49 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
| 52 #import "ios/public/provider/chrome/browser/signin/chrome_identity_browser_opene
r.h" | 50 #import "ios/public/provider/chrome/browser/signin/chrome_identity_browser_opene
r.h" |
| 53 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 51 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 54 #import "net/base/mac/url_conversions.h" | 52 #import "net/base/mac/url_conversions.h" |
| 55 #include "ui/base/l10n/l10n_util_mac.h" | 53 #include "ui/base/l10n/l10n_util_mac.h" |
| 56 | 54 |
| 55 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 56 #error "This file requires ARC support." |
| 57 #endif |
| 58 |
| 57 NSString* const kSettingsAccountsId = @"kSettingsAccountsId"; | 59 NSString* const kSettingsAccountsId = @"kSettingsAccountsId"; |
| 58 NSString* const kSettingsHeaderId = @"kSettingsHeaderId"; | 60 NSString* const kSettingsHeaderId = @"kSettingsHeaderId"; |
| 59 NSString* const kSettingsAccountsSignoutCellId = | 61 NSString* const kSettingsAccountsSignoutCellId = |
| 60 @"kSettingsAccountsSignoutCellId"; | 62 @"kSettingsAccountsSignoutCellId"; |
| 61 NSString* const kSettingsAccountsSyncCellId = @"kSettingsAccountsSyncCellId"; | 63 NSString* const kSettingsAccountsSyncCellId = @"kSettingsAccountsSyncCellId"; |
| 62 | 64 |
| 63 namespace { | 65 namespace { |
| 64 | 66 |
| 65 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 67 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 66 SectionIdentifierAccounts = kSectionIdentifierEnumZero, | 68 SectionIdentifierAccounts = kSectionIdentifierEnumZero, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 | 83 |
| 82 @interface AccountsCollectionViewController ()< | 84 @interface AccountsCollectionViewController ()< |
| 83 ChromeIdentityServiceObserver, | 85 ChromeIdentityServiceObserver, |
| 84 ChromeIdentityBrowserOpener, | 86 ChromeIdentityBrowserOpener, |
| 85 OAuth2TokenServiceObserverBridgeDelegate, | 87 OAuth2TokenServiceObserverBridgeDelegate, |
| 86 SyncObserverModelBridge> { | 88 SyncObserverModelBridge> { |
| 87 ios::ChromeBrowserState* _browserState; // weak | 89 ios::ChromeBrowserState* _browserState; // weak |
| 88 BOOL _closeSettingsOnAddAccount; | 90 BOOL _closeSettingsOnAddAccount; |
| 89 std::unique_ptr<SyncObserverBridge> _syncObserver; | 91 std::unique_ptr<SyncObserverBridge> _syncObserver; |
| 90 std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver; | 92 std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver; |
| 91 base::scoped_nsobject<SigninInteractionController> | 93 SigninInteractionController* _signinInteractionController; |
| 92 _signinInteractionController; | |
| 93 // Modal alert for sign out. | 94 // Modal alert for sign out. |
| 94 base::scoped_nsobject<AlertCoordinator> _alertCoordinator; | 95 AlertCoordinator* _alertCoordinator; |
| 95 // Whether an authentication operation is in progress (e.g switch accounts, | 96 // Whether an authentication operation is in progress (e.g switch accounts, |
| 96 // sign out). | 97 // sign out). |
| 97 BOOL _authenticationOperationInProgress; | 98 BOOL _authenticationOperationInProgress; |
| 98 // Whether the view controller is currently being dismissed and new dismiss | 99 // Whether the view controller is currently being dismissed and new dismiss |
| 99 // requests should be ignored. | 100 // requests should be ignored. |
| 100 BOOL _isBeingDismissed; | 101 BOOL _isBeingDismissed; |
| 101 base::WeakNSObject<UIViewController> _settingsDetails; | 102 __weak UIViewController* _settingsDetails; |
| 102 base::scoped_nsobject<ResizedAvatarCache> _avatarCache; | 103 ResizedAvatarCache* _avatarCache; |
| 103 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; | 104 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; |
| 104 | 105 |
| 105 // Enable lookup of item corresponding to a given identity GAIA ID string. | 106 // Enable lookup of item corresponding to a given identity GAIA ID string. |
| 106 base::scoped_nsobject<NSDictionary<NSString*, CollectionViewItem*>> | 107 NSDictionary<NSString*, CollectionViewItem*>* _identityMap; |
| 107 _identityMap; | |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Stops observing browser state services. This is required during the shutdown | 110 // Stops observing browser state services. This is required during the shutdown |
| 111 // phase to avoid observing services for a browser state that is being killed. | 111 // phase to avoid observing services for a browser state that is being killed. |
| 112 - (void)stopBrowserStateServiceObservers; | 112 - (void)stopBrowserStateServiceObservers; |
| 113 | 113 |
| 114 @end | 114 @end |
| 115 | 115 |
| 116 @implementation AccountsCollectionViewController | 116 @implementation AccountsCollectionViewController |
| 117 | 117 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 132 addObserver:self | 132 addObserver:self |
| 133 selector:@selector(willStartSwitchAccount) | 133 selector:@selector(willStartSwitchAccount) |
| 134 name:kSwitchAccountWillStartNotification | 134 name:kSwitchAccountWillStartNotification |
| 135 object:nil]; | 135 object:nil]; |
| 136 [[NSNotificationCenter defaultCenter] | 136 [[NSNotificationCenter defaultCenter] |
| 137 addObserver:self | 137 addObserver:self |
| 138 selector:@selector(didFinishSwitchAccount) | 138 selector:@selector(didFinishSwitchAccount) |
| 139 name:kSwitchAccountDidFinishNotification | 139 name:kSwitchAccountDidFinishNotification |
| 140 object:nil]; | 140 object:nil]; |
| 141 self.collectionViewAccessibilityIdentifier = kSettingsAccountsId; | 141 self.collectionViewAccessibilityIdentifier = kSettingsAccountsId; |
| 142 _avatarCache.reset([[ResizedAvatarCache alloc] init]); | 142 _avatarCache = [[ResizedAvatarCache alloc] init]; |
| 143 _identityServiceObserver.reset( | 143 _identityServiceObserver.reset( |
| 144 new ChromeIdentityServiceObserverBridge(self)); | 144 new ChromeIdentityServiceObserverBridge(self)); |
| 145 [self loadModel]; | 145 [self loadModel]; |
| 146 } | 146 } |
| 147 | 147 |
| 148 return self; | 148 return self; |
| 149 } | 149 } |
| 150 | 150 |
| 151 - (void)dealloc { | 151 - (void)dealloc { |
| 152 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 152 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 153 [super dealloc]; | |
| 154 } | 153 } |
| 155 | 154 |
| 156 - (void)stopBrowserStateServiceObservers { | 155 - (void)stopBrowserStateServiceObservers { |
| 157 _tokenServiceObserver.reset(); | 156 _tokenServiceObserver.reset(); |
| 158 _syncObserver.reset(); | 157 _syncObserver.reset(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 #pragma mark - SettingsControllerProtocol | 160 #pragma mark - SettingsControllerProtocol |
| 162 | 161 |
| 163 - (void)settingsWillBeDismissed { | 162 - (void)settingsWillBeDismissed { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 192 self.title = title; | 191 self.title = title; |
| 193 | 192 |
| 194 [super loadModel]; | 193 [super loadModel]; |
| 195 | 194 |
| 196 if (![self authService]->IsAuthenticated()) | 195 if (![self authService]->IsAuthenticated()) |
| 197 return; | 196 return; |
| 198 | 197 |
| 199 CollectionViewModel* model = self.collectionViewModel; | 198 CollectionViewModel* model = self.collectionViewModel; |
| 200 | 199 |
| 201 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = | 200 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = |
| 202 [[[NSMutableDictionary alloc] init] autorelease]; | 201 [[NSMutableDictionary alloc] init]; |
| 203 | 202 |
| 204 // Account cells. | 203 // Account cells. |
| 205 ProfileOAuth2TokenService* oauth2_service = | 204 ProfileOAuth2TokenService* oauth2_service = |
| 206 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); | 205 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); |
| 207 AccountTrackerService* accountTracker = | 206 AccountTrackerService* accountTracker = |
| 208 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); | 207 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); |
| 209 [model addSectionWithIdentifier:SectionIdentifierAccounts]; | 208 [model addSectionWithIdentifier:SectionIdentifierAccounts]; |
| 210 [model setHeader:[self header] | 209 [model setHeader:[self header] |
| 211 forSectionWithIdentifier:SectionIdentifierAccounts]; | 210 forSectionWithIdentifier:SectionIdentifierAccounts]; |
| 212 for (const std::string& account_id : oauth2_service->GetAccounts()) { | 211 for (const std::string& account_id : oauth2_service->GetAccounts()) { |
| 213 AccountInfo account = accountTracker->GetAccountInfo(account_id); | 212 AccountInfo account = accountTracker->GetAccountInfo(account_id); |
| 214 ChromeIdentity* identity = ios::GetChromeBrowserProvider() | 213 ChromeIdentity* identity = ios::GetChromeBrowserProvider() |
| 215 ->GetChromeIdentityService() | 214 ->GetChromeIdentityService() |
| 216 ->GetIdentityWithGaiaID(account.gaia); | 215 ->GetIdentityWithGaiaID(account.gaia); |
| 217 CollectionViewItem* item = [self accountItem:identity]; | 216 CollectionViewItem* item = [self accountItem:identity]; |
| 218 [model addItem:item toSectionWithIdentifier:SectionIdentifierAccounts]; | 217 [model addItem:item toSectionWithIdentifier:SectionIdentifierAccounts]; |
| 219 | 218 |
| 220 [mutableIdentityMap setObject:item forKey:identity.gaiaID]; | 219 [mutableIdentityMap setObject:item forKey:identity.gaiaID]; |
| 221 } | 220 } |
| 222 _identityMap.reset([mutableIdentityMap retain]); | 221 _identityMap = mutableIdentityMap; |
| 223 | 222 |
| 224 [model addItem:[self addAccountItem] | 223 [model addItem:[self addAccountItem] |
| 225 toSectionWithIdentifier:SectionIdentifierAccounts]; | 224 toSectionWithIdentifier:SectionIdentifierAccounts]; |
| 226 | 225 |
| 227 // Sync and Google Activity section. | 226 // Sync and Google Activity section. |
| 228 [model addSectionWithIdentifier:SectionIdentifierSync]; | 227 [model addSectionWithIdentifier:SectionIdentifierSync]; |
| 229 [model addItem:[self syncItem] toSectionWithIdentifier:SectionIdentifierSync]; | 228 [model addItem:[self syncItem] toSectionWithIdentifier:SectionIdentifierSync]; |
| 230 [model addItem:[self googleActivityControlsItem] | 229 [model addItem:[self googleActivityControlsItem] |
| 231 toSectionWithIdentifier:SectionIdentifierSync]; | 230 toSectionWithIdentifier:SectionIdentifierSync]; |
| 232 | 231 |
| 233 // Sign out section. | 232 // Sign out section. |
| 234 [model addSectionWithIdentifier:SectionIdentifierSignOut]; | 233 [model addSectionWithIdentifier:SectionIdentifierSignOut]; |
| 235 [model addItem:[self signOutItem] | 234 [model addItem:[self signOutItem] |
| 236 toSectionWithIdentifier:SectionIdentifierSignOut]; | 235 toSectionWithIdentifier:SectionIdentifierSignOut]; |
| 237 } | 236 } |
| 238 | 237 |
| 239 #pragma mark - Model objects | 238 #pragma mark - Model objects |
| 240 | 239 |
| 241 - (CollectionViewItem*)header { | 240 - (CollectionViewItem*)header { |
| 242 CollectionViewTextItem* header = [ | 241 CollectionViewTextItem* header = |
| 243 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 242 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 244 header.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_DESCRIPTION); | 243 header.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_DESCRIPTION); |
| 245 header.accessibilityIdentifier = kSettingsHeaderId; | 244 header.accessibilityIdentifier = kSettingsHeaderId; |
| 246 header.textColor = [[MDCPalette greyPalette] tint500]; | 245 header.textColor = [[MDCPalette greyPalette] tint500]; |
| 247 return header; | 246 return header; |
| 248 } | 247 } |
| 249 | 248 |
| 250 - (CollectionViewItem*)accountItem:(ChromeIdentity*)identity { | 249 - (CollectionViewItem*)accountItem:(ChromeIdentity*)identity { |
| 251 CollectionViewAccountItem* item = [[[CollectionViewAccountItem alloc] | 250 CollectionViewAccountItem* item = |
| 252 initWithType:ItemTypeAccount] autorelease]; | 251 [[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount]; |
| 253 [self updateAccountItem:item withIdentity:identity]; | 252 [self updateAccountItem:item withIdentity:identity]; |
| 254 return item; | 253 return item; |
| 255 } | 254 } |
| 256 | 255 |
| 257 - (void)updateAccountItem:(CollectionViewAccountItem*)item | 256 - (void)updateAccountItem:(CollectionViewAccountItem*)item |
| 258 withIdentity:(ChromeIdentity*)identity { | 257 withIdentity:(ChromeIdentity*)identity { |
| 259 item.image = [_avatarCache resizedAvatarForIdentity:identity]; | 258 item.image = [_avatarCache resizedAvatarForIdentity:identity]; |
| 260 item.text = identity.userEmail; | 259 item.text = identity.userEmail; |
| 261 item.chromeIdentity = identity; | 260 item.chromeIdentity = identity; |
| 262 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; | 261 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 263 } | 262 } |
| 264 | 263 |
| 265 - (CollectionViewItem*)addAccountItem { | 264 - (CollectionViewItem*)addAccountItem { |
| 266 CollectionViewAccountItem* item = [[[CollectionViewAccountItem alloc] | 265 CollectionViewAccountItem* item = |
| 267 initWithType:ItemTypeAddAccount] autorelease]; | 266 [[CollectionViewAccountItem alloc] initWithType:ItemTypeAddAccount]; |
| 268 item.text = | 267 item.text = |
| 269 l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_ADD_ACCOUNT_BUTTON); | 268 l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_ADD_ACCOUNT_BUTTON); |
| 270 item.image = [UIImage imageNamed:@"settings_accounts_add_account"]; | 269 item.image = [UIImage imageNamed:@"settings_accounts_add_account"]; |
| 271 return item; | 270 return item; |
| 272 } | 271 } |
| 273 | 272 |
| 274 - (CollectionViewItem*)syncItem { | 273 - (CollectionViewItem*)syncItem { |
| 275 AccountControlItem* item = | 274 AccountControlItem* item = |
| 276 [[[AccountControlItem alloc] initWithType:ItemTypeSync] autorelease]; | 275 [[AccountControlItem alloc] initWithType:ItemTypeSync]; |
| 277 item.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_SYNC_TITLE); | 276 item.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_SYNC_TITLE); |
| 278 item.accessibilityIdentifier = kSettingsAccountsSyncCellId; | 277 item.accessibilityIdentifier = kSettingsAccountsSyncCellId; |
| 279 [self updateSyncItem:item]; | 278 [self updateSyncItem:item]; |
| 280 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; | 279 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 281 return item; | 280 return item; |
| 282 } | 281 } |
| 283 | 282 |
| 284 - (void)updateSyncItem:(AccountControlItem*)syncItem { | 283 - (void)updateSyncItem:(AccountControlItem*)syncItem { |
| 285 SyncSetupService* syncSetupService = | 284 SyncSetupService* syncSetupService = |
| 286 SyncSetupServiceFactory::GetForBrowserState(_browserState); | 285 SyncSetupServiceFactory::GetForBrowserState(_browserState); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 308 syncSetupService->IsSyncEnabled() | 307 syncSetupService->IsSyncEnabled() |
| 309 ? l10n_util::GetNSStringF( | 308 ? l10n_util::GetNSStringF( |
| 310 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNCING, | 309 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNCING, |
| 311 base::SysNSStringToUTF16([identity userEmail])) | 310 base::SysNSStringToUTF16([identity userEmail])) |
| 312 : l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_SYNC_IS_OFF); | 311 : l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_SYNC_IS_OFF); |
| 313 syncItem.shouldDisplayError = NO; | 312 syncItem.shouldDisplayError = NO; |
| 314 } | 313 } |
| 315 } | 314 } |
| 316 | 315 |
| 317 - (CollectionViewItem*)googleActivityControlsItem { | 316 - (CollectionViewItem*)googleActivityControlsItem { |
| 318 AccountControlItem* item = [[[AccountControlItem alloc] | 317 AccountControlItem* item = |
| 319 initWithType:ItemTypeGoogleActivityControls] autorelease]; | 318 [[AccountControlItem alloc] initWithType:ItemTypeGoogleActivityControls]; |
| 320 item.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_GOOGLE_TITLE); | 319 item.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_GOOGLE_TITLE); |
| 321 item.detailText = | 320 item.detailText = |
| 322 l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_GOOGLE_DESCRIPTION); | 321 l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_GOOGLE_DESCRIPTION); |
| 323 item.image = ios::GetChromeBrowserProvider() | 322 item.image = ios::GetChromeBrowserProvider() |
| 324 ->GetBrandedImageProvider() | 323 ->GetBrandedImageProvider() |
| 325 ->GetAccountsListActivityControlsImage(); | 324 ->GetAccountsListActivityControlsImage(); |
| 326 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; | 325 item.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 327 return item; | 326 return item; |
| 328 } | 327 } |
| 329 | 328 |
| 330 - (CollectionViewItem*)signOutItem { | 329 - (CollectionViewItem*)signOutItem { |
| 331 CollectionViewTextItem* item = [[[CollectionViewTextItem alloc] | 330 CollectionViewTextItem* item = |
| 332 initWithType:ItemTypeSignOut] autorelease]; | 331 [[CollectionViewTextItem alloc] initWithType:ItemTypeSignOut]; |
| 333 item.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_SIGNOUT); | 332 item.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_ACCOUNTS_SIGNOUT); |
| 334 item.accessibilityTraits |= UIAccessibilityTraitButton; | 333 item.accessibilityTraits |= UIAccessibilityTraitButton; |
| 335 item.accessibilityIdentifier = kSettingsAccountsSignoutCellId; | 334 item.accessibilityIdentifier = kSettingsAccountsSignoutCellId; |
| 336 return item; | 335 return item; |
| 337 } | 336 } |
| 338 | 337 |
| 339 #pragma mark - UICollectionViewDelegate | 338 #pragma mark - UICollectionViewDelegate |
| 340 | 339 |
| 341 - (void)collectionView:(UICollectionView*)collectionView | 340 - (void)collectionView:(UICollectionView*)collectionView |
| 342 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 341 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 409 } |
| 411 } | 410 } |
| 412 | 411 |
| 413 #pragma mark - OAuth2TokenServiceObserverBridgeDelegate | 412 #pragma mark - OAuth2TokenServiceObserverBridgeDelegate |
| 414 | 413 |
| 415 - (void)onEndBatchChanges { | 414 - (void)onEndBatchChanges { |
| 416 [self reloadData]; | 415 [self reloadData]; |
| 417 [self popViewIfSignedOut]; | 416 [self popViewIfSignedOut]; |
| 418 if (![self authService]->IsAuthenticated() && _settingsDetails) { | 417 if (![self authService]->IsAuthenticated() && _settingsDetails) { |
| 419 [_settingsDetails dismissViewControllerAnimated:YES completion:nil]; | 418 [_settingsDetails dismissViewControllerAnimated:YES completion:nil]; |
| 420 _settingsDetails.reset(); | 419 _settingsDetails = nil; |
| 421 } | 420 } |
| 422 } | 421 } |
| 423 | 422 |
| 424 #pragma mark - Sync and Activity Controls | 423 #pragma mark - Sync and Activity Controls |
| 425 | 424 |
| 426 - (void)showSyncSettings { | 425 - (void)showSyncSettings { |
| 427 if ([_alertCoordinator isVisible]) | 426 if ([_alertCoordinator isVisible]) |
| 428 return; | 427 return; |
| 429 | 428 |
| 430 if ([self authService]->ShowMDMErrorDialogForIdentity( | 429 if ([self authService]->ShowMDMErrorDialogForIdentity( |
| 431 [self authService]->GetAuthenticatedIdentity())) { | 430 [self authService]->GetAuthenticatedIdentity())) { |
| 432 // If there is an MDM error for the synced identity, show it instead. | 431 // If there is an MDM error for the synced identity, show it instead. |
| 433 return; | 432 return; |
| 434 } | 433 } |
| 435 | 434 |
| 436 base::scoped_nsobject<UIViewController> controllerToPush( | 435 UIViewController* controllerToPush = |
| 437 [[SyncSettingsCollectionViewController alloc] | 436 [[SyncSettingsCollectionViewController alloc] |
| 438 initWithBrowserState:_browserState | 437 initWithBrowserState:_browserState |
| 439 allowSwitchSyncAccount:YES]); | 438 allowSwitchSyncAccount:YES]; |
| 440 [self.navigationController pushViewController:controllerToPush animated:YES]; | 439 [self.navigationController pushViewController:controllerToPush animated:YES]; |
| 441 } | 440 } |
| 442 | 441 |
| 443 - (void)showGoogleActivitySettings { | 442 - (void)showGoogleActivitySettings { |
| 444 if ([_alertCoordinator isVisible]) | 443 if ([_alertCoordinator isVisible]) |
| 445 return; | 444 return; |
| 446 base::RecordAction(base::UserMetricsAction( | 445 base::RecordAction(base::UserMetricsAction( |
| 447 "Signin_AccountSettings_GoogleActivityControlsClicked")); | 446 "Signin_AccountSettings_GoogleActivityControlsClicked")); |
| 448 base::scoped_nsobject<UINavigationController> settingsDetails( | 447 UINavigationController* settingsDetails = |
| 449 ios::GetChromeBrowserProvider() | 448 ios::GetChromeBrowserProvider() |
| 450 ->GetChromeIdentityService() | 449 ->GetChromeIdentityService() |
| 451 ->NewWebAndAppSettingDetails( | 450 ->NewWebAndAppSettingDetails( |
| 452 [self authService]->GetAuthenticatedIdentity(), self)); | 451 [self authService]->GetAuthenticatedIdentity(), self); |
| 453 UIImage* closeIcon = [ChromeIcon closeIcon]; | 452 UIImage* closeIcon = [ChromeIcon closeIcon]; |
| 454 SEL action = @selector(closeGoogleActivitySettings:); | 453 SEL action = @selector(closeGoogleActivitySettings:); |
| 455 [settingsDetails.get().topViewController navigationItem].leftBarButtonItem = | 454 [settingsDetails.topViewController navigationItem].leftBarButtonItem = |
| 456 [ChromeIcon templateBarButtonItemWithImage:closeIcon | 455 [ChromeIcon templateBarButtonItemWithImage:closeIcon |
| 457 target:self | 456 target:self |
| 458 action:action]; | 457 action:action]; |
| 459 [self presentViewController:settingsDetails animated:YES completion:nil]; | 458 [self presentViewController:settingsDetails animated:YES completion:nil]; |
| 460 | 459 |
| 461 // Keep a weak reference on the settings details, to be able to dismiss it | 460 // Keep a weak reference on the settings details, to be able to dismiss it |
| 462 // when the primary account is removed. | 461 // when the primary account is removed. |
| 463 _settingsDetails.reset(settingsDetails); | 462 _settingsDetails = settingsDetails; |
| 464 } | 463 } |
| 465 | 464 |
| 466 - (void)closeGoogleActivitySettings:(id)sender { | 465 - (void)closeGoogleActivitySettings:(id)sender { |
| 467 DCHECK(_settingsDetails); | 466 DCHECK(_settingsDetails); |
| 468 [self dismissViewControllerAnimated:YES completion:nil]; | 467 [self dismissViewControllerAnimated:YES completion:nil]; |
| 469 } | 468 } |
| 470 | 469 |
| 471 #pragma mark - Authentication operations | 470 #pragma mark - Authentication operations |
| 472 | 471 |
| 473 - (void)showAddAccount { | 472 - (void)showAddAccount { |
| 474 if ([_alertCoordinator isVisible]) | 473 if ([_alertCoordinator isVisible]) |
| 475 return; | 474 return; |
| 476 if (_signinInteractionController) { | 475 if (_signinInteractionController) { |
| 477 // Ignore this user action if there is already an add account operation | 476 // Ignore this user action if there is already an add account operation |
| 478 // in-progress. | 477 // in-progress. |
| 479 return; | 478 return; |
| 480 } | 479 } |
| 481 _signinInteractionController.reset([[SigninInteractionController alloc] | 480 _signinInteractionController = [[SigninInteractionController alloc] |
| 482 initWithBrowserState:_browserState | 481 initWithBrowserState:_browserState |
| 483 presentingViewController:self.navigationController | 482 presentingViewController:self.navigationController |
| 484 isPresentedOnSettings:YES | 483 isPresentedOnSettings:YES |
| 485 signInAccessPoint:signin_metrics::AccessPoint:: | 484 signInAccessPoint:signin_metrics::AccessPoint:: |
| 486 ACCESS_POINT_SETTINGS]); | 485 ACCESS_POINT_SETTINGS]; |
| 487 | 486 |
| 488 // |_authenticationOperationInProgress| is reset when the signin interaction | 487 // |_authenticationOperationInProgress| is reset when the signin interaction |
| 489 // controller is dismissed. | 488 // controller is dismissed. |
| 490 _authenticationOperationInProgress = YES; | 489 _authenticationOperationInProgress = YES; |
| 491 base::WeakNSObject<AccountsCollectionViewController> weakSelf(self); | 490 __weak AccountsCollectionViewController* weakSelf = self; |
| 492 [_signinInteractionController addAccountWithCompletion:^(BOOL success) { | 491 [_signinInteractionController addAccountWithCompletion:^(BOOL success) { |
| 493 [weakSelf handleDidAddAccount:success]; | 492 [weakSelf handleDidAddAccount:success]; |
| 494 } | 493 } |
| 495 viewController:self]; | 494 viewController:self]; |
| 496 } | 495 } |
| 497 | 496 |
| 498 - (void)handleDidAddAccount:(BOOL)success { | 497 - (void)handleDidAddAccount:(BOOL)success { |
| 499 _signinInteractionController.reset(); | 498 _signinInteractionController = nil; |
| 500 [self handleAuthenticationOperationDidFinish]; | 499 [self handleAuthenticationOperationDidFinish]; |
| 501 if (success && _closeSettingsOnAddAccount) { | 500 if (success && _closeSettingsOnAddAccount) { |
| 502 base::scoped_nsobject<GenericChromeCommand> closeSettingsCommand( | 501 GenericChromeCommand* closeSettingsCommand = |
| 503 [[GenericChromeCommand alloc] initWithTag:IDC_CLOSE_SETTINGS]); | 502 [[GenericChromeCommand alloc] initWithTag:IDC_CLOSE_SETTINGS]; |
| 504 [self chromeExecuteCommand:closeSettingsCommand]; | 503 [self chromeExecuteCommand:closeSettingsCommand]; |
| 505 } | 504 } |
| 506 } | 505 } |
| 507 | 506 |
| 508 - (void)showAccountDetails:(ChromeIdentity*)identity { | 507 - (void)showAccountDetails:(ChromeIdentity*)identity { |
| 509 if ([_alertCoordinator isVisible]) | 508 if ([_alertCoordinator isVisible]) |
| 510 return; | 509 return; |
| 511 base::scoped_nsobject<UIViewController> accountDetails( | 510 UIViewController* accountDetails = ios::GetChromeBrowserProvider() |
| 512 ios::GetChromeBrowserProvider() | 511 ->GetChromeIdentityService() |
| 513 ->GetChromeIdentityService() | 512 ->NewAccountDetails(identity, self); |
| 514 ->NewAccountDetails(identity, self)); | |
| 515 if (!accountDetails) { | 513 if (!accountDetails) { |
| 516 // Failed to create a new account details. Ignored. | 514 // Failed to create a new account details. Ignored. |
| 517 return; | 515 return; |
| 518 } | 516 } |
| 519 [self presentViewController:accountDetails animated:YES completion:nil]; | 517 [self presentViewController:accountDetails animated:YES completion:nil]; |
| 520 | 518 |
| 521 // Keep a weak reference on the account details, to be able to dismiss it | 519 // Keep a weak reference on the account details, to be able to dismiss it |
| 522 // when the primary account is removed. | 520 // when the primary account is removed. |
| 523 _settingsDetails.reset(accountDetails); | 521 _settingsDetails = accountDetails; |
| 524 } | 522 } |
| 525 | 523 |
| 526 - (void)showDisconnect { | 524 - (void)showDisconnect { |
| 527 if (_authenticationOperationInProgress || [_alertCoordinator isVisible] || | 525 if (_authenticationOperationInProgress || [_alertCoordinator isVisible] || |
| 528 self != [self.navigationController topViewController]) { | 526 self != [self.navigationController topViewController]) { |
| 529 // An action is already in progress, ignore user's request. | 527 // An action is already in progress, ignore user's request. |
| 530 return; | 528 return; |
| 531 } | 529 } |
| 532 | 530 |
| 533 NSString* title; | 531 NSString* title; |
| 534 NSString* message; | 532 NSString* message; |
| 535 NSString* continueButtonTitle; | 533 NSString* continueButtonTitle; |
| 536 if ([self authService]->IsAuthenticatedIdentityManaged()) { | 534 if ([self authService]->IsAuthenticatedIdentityManaged()) { |
| 537 std::string hosted_domain = | 535 std::string hosted_domain = |
| 538 ios::SigninManagerFactory::GetForBrowserState(_browserState) | 536 ios::SigninManagerFactory::GetForBrowserState(_browserState) |
| 539 ->GetAuthenticatedAccountInfo() | 537 ->GetAuthenticatedAccountInfo() |
| 540 .hosted_domain; | 538 .hosted_domain; |
| 541 title = l10n_util::GetNSString(IDS_IOS_MANAGED_DISCONNECT_DIALOG_TITLE); | 539 title = l10n_util::GetNSString(IDS_IOS_MANAGED_DISCONNECT_DIALOG_TITLE); |
| 542 message = l10n_util::GetNSStringF(IDS_IOS_MANAGED_DISCONNECT_DIALOG_INFO, | 540 message = l10n_util::GetNSStringF(IDS_IOS_MANAGED_DISCONNECT_DIALOG_INFO, |
| 543 base::UTF8ToUTF16(hosted_domain)); | 541 base::UTF8ToUTF16(hosted_domain)); |
| 544 continueButtonTitle = | 542 continueButtonTitle = |
| 545 l10n_util::GetNSString(IDS_IOS_MANAGED_DISCONNECT_DIALOG_ACCEPT); | 543 l10n_util::GetNSString(IDS_IOS_MANAGED_DISCONNECT_DIALOG_ACCEPT); |
| 546 } else { | 544 } else { |
| 547 title = l10n_util::GetNSString(IDS_IOS_DISCONNECT_DIALOG_TITLE); | 545 title = l10n_util::GetNSString(IDS_IOS_DISCONNECT_DIALOG_TITLE); |
| 548 message = l10n_util::GetNSString(IDS_IOS_DISCONNECT_DIALOG_INFO_MOBILE); | 546 message = l10n_util::GetNSString(IDS_IOS_DISCONNECT_DIALOG_INFO_MOBILE); |
| 549 continueButtonTitle = l10n_util::GetNSString( | 547 continueButtonTitle = l10n_util::GetNSString( |
| 550 IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE); | 548 IDS_IOS_DISCONNECT_DIALOG_CONTINUE_BUTTON_MOBILE); |
| 551 } | 549 } |
| 552 _alertCoordinator.reset([[AlertCoordinator alloc] | 550 _alertCoordinator = |
| 553 initWithBaseViewController:self | 551 [[AlertCoordinator alloc] initWithBaseViewController:self |
| 554 title:title | 552 title:title |
| 555 message:message]); | 553 message:message]; |
| 556 | 554 |
| 557 [_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) | 555 [_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) |
| 558 action:nil | 556 action:nil |
| 559 style:UIAlertActionStyleCancel]; | 557 style:UIAlertActionStyleCancel]; |
| 560 base::WeakNSObject<AccountsCollectionViewController> weakSelf(self); | 558 __weak AccountsCollectionViewController* weakSelf = self; |
| 561 [_alertCoordinator addItemWithTitle:continueButtonTitle | 559 [_alertCoordinator addItemWithTitle:continueButtonTitle |
| 562 action:^{ | 560 action:^{ |
| 563 [weakSelf handleDisconnect]; | 561 [weakSelf handleDisconnect]; |
| 564 } | 562 } |
| 565 style:UIAlertActionStyleDefault]; | 563 style:UIAlertActionStyleDefault]; |
| 566 [_alertCoordinator start]; | 564 [_alertCoordinator start]; |
| 567 } | 565 } |
| 568 | 566 |
| 569 - (void)handleDisconnect { | 567 - (void)handleDisconnect { |
| 570 AuthenticationService* authService = [self authService]; | 568 AuthenticationService* authService = [self authService]; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 626 |
| 629 - (void)didFinishSwitchAccount { | 627 - (void)didFinishSwitchAccount { |
| 630 [self handleAuthenticationOperationDidFinish]; | 628 [self handleAuthenticationOperationDidFinish]; |
| 631 } | 629 } |
| 632 | 630 |
| 633 #pragma mark - ChromeIdentityBrowserOpener | 631 #pragma mark - ChromeIdentityBrowserOpener |
| 634 | 632 |
| 635 - (void)openURL:(NSURL*)url | 633 - (void)openURL:(NSURL*)url |
| 636 view:(UIView*)view | 634 view:(UIView*)view |
| 637 viewController:(UIViewController*)viewController { | 635 viewController:(UIViewController*)viewController { |
| 638 base::scoped_nsobject<OpenUrlCommand> command( | 636 OpenUrlCommand* command = |
| 639 [[OpenUrlCommand alloc] initWithURLFromChrome:net::GURLWithNSURL(url)]); | 637 [[OpenUrlCommand alloc] initWithURLFromChrome:net::GURLWithNSURL(url)]; |
| 640 [command setTag:IDC_CLOSE_SETTINGS_AND_OPEN_URL]; | 638 [command setTag:IDC_CLOSE_SETTINGS_AND_OPEN_URL]; |
| 641 [self chromeExecuteCommand:command]; | 639 [self chromeExecuteCommand:command]; |
| 642 } | 640 } |
| 643 | 641 |
| 644 #pragma mark - ChromeIdentityServiceObserver | 642 #pragma mark - ChromeIdentityServiceObserver |
| 645 | 643 |
| 646 - (void)onProfileUpdate:(ChromeIdentity*)identity { | 644 - (void)onProfileUpdate:(ChromeIdentity*)identity { |
| 647 CollectionViewAccountItem* item = | 645 CollectionViewAccountItem* item = |
| 648 base::mac::ObjCCastStrict<CollectionViewAccountItem>( | 646 base::mac::ObjCCastStrict<CollectionViewAccountItem>( |
| 649 [_identityMap objectForKey:identity.gaiaID]); | 647 [_identityMap objectForKey:identity.gaiaID]); |
| 650 [self updateAccountItem:item withIdentity:identity]; | 648 [self updateAccountItem:item withIdentity:identity]; |
| 651 NSIndexPath* indexPath = | 649 NSIndexPath* indexPath = |
| 652 [self.collectionViewModel indexPathForItem:item | 650 [self.collectionViewModel indexPathForItem:item |
| 653 inSectionWithIdentifier:SectionIdentifierAccounts]; | 651 inSectionWithIdentifier:SectionIdentifierAccounts]; |
| 654 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 652 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 655 } | 653 } |
| 656 | 654 |
| 657 - (void)onChromeIdentityServiceWillBeDestroyed { | 655 - (void)onChromeIdentityServiceWillBeDestroyed { |
| 658 _identityServiceObserver.reset(); | 656 _identityServiceObserver.reset(); |
| 659 } | 657 } |
| 660 | 658 |
| 661 @end | 659 @end |
| OLD | NEW |