| 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/sync_settings_collection_view_controller
.h" | 5 #import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #import "base/mac/scoped_nsobject.h" | |
| 12 #include "components/browser_sync/profile_sync_service.h" | 11 #include "components/browser_sync/profile_sync_service.h" |
| 13 #include "components/google/core/browser/google_util.h" | 12 #include "components/google/core/browser/google_util.h" |
| 14 #include "components/signin/core/browser/account_tracker_service.h" | 13 #include "components/signin/core/browser/account_tracker_service.h" |
| 15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 14 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 16 #import "components/signin/ios/browser/oauth2_token_service_observer_bridge.h" | 15 #import "components/signin/ios/browser/oauth2_token_service_observer_bridge.h" |
| 17 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 18 #include "components/sync/base/model_type.h" | 17 #include "components/sync/base/model_type.h" |
| 19 #include "ios/chrome/browser/application_context.h" | 18 #include "ios/chrome/browser/application_context.h" |
| 20 #include "ios/chrome/browser/chrome_url_constants.h" | 19 #include "ios/chrome/browser/chrome_url_constants.h" |
| 21 #include "ios/chrome/browser/experimental_flags.h" | 20 #include "ios/chrome/browser/experimental_flags.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 45 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi
ew_controller.h" | 44 #import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_vi
ew_controller.h" |
| 46 #import "ios/chrome/browser/ui/sync/sync_util.h" | 45 #import "ios/chrome/browser/ui/sync/sync_util.h" |
| 47 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 46 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 48 #include "ios/chrome/grit/ios_strings.h" | 47 #include "ios/chrome/grit/ios_strings.h" |
| 49 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 48 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 50 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 49 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
| 51 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 50 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 52 #include "ui/base/l10n/l10n_util_mac.h" | 51 #include "ui/base/l10n/l10n_util_mac.h" |
| 53 #include "url/gurl.h" | 52 #include "url/gurl.h" |
| 54 | 53 |
| 54 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 55 #error "This file requires ARC support." |
| 56 #endif |
| 57 |
| 55 // The a11y identifier of the view controller's view. | 58 // The a11y identifier of the view controller's view. |
| 56 NSString* const kSettingsSyncId = @"kSettingsSyncId"; | 59 NSString* const kSettingsSyncId = @"kSettingsSyncId"; |
| 57 // Notification when a switch account operation will start. | 60 // Notification when a switch account operation will start. |
| 58 NSString* const kSwitchAccountWillStartNotification = | 61 NSString* const kSwitchAccountWillStartNotification = |
| 59 @"kSwitchAccountWillStartNotification"; | 62 @"kSwitchAccountWillStartNotification"; |
| 60 // Notification when a switch account operation did finish. | 63 // Notification when a switch account operation did finish. |
| 61 NSString* const kSwitchAccountDidFinishNotification = | 64 NSString* const kSwitchAccountDidFinishNotification = |
| 62 @"kSwitchAccountDidFinishNotification"; | 65 @"kSwitchAccountDidFinishNotification"; |
| 63 // Used to tag and retrieve ItemTypeSyncableDataType cell tags. | 66 // Used to tag and retrieve ItemTypeSyncableDataType cell tags. |
| 64 const NSInteger kTagShift = 1000; | 67 const NSInteger kTagShift = 1000; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 | 91 |
| 89 @interface SyncSettingsCollectionViewController ()< | 92 @interface SyncSettingsCollectionViewController ()< |
| 90 ChromeIdentityServiceObserver, | 93 ChromeIdentityServiceObserver, |
| 91 OAuth2TokenServiceObserverBridgeDelegate, | 94 OAuth2TokenServiceObserverBridgeDelegate, |
| 92 SettingsControllerProtocol, | 95 SettingsControllerProtocol, |
| 93 SyncObserverModelBridge> { | 96 SyncObserverModelBridge> { |
| 94 ios::ChromeBrowserState* _browserState; // Weak. | 97 ios::ChromeBrowserState* _browserState; // Weak. |
| 95 SyncSetupService* _syncSetupService; // Weak. | 98 SyncSetupService* _syncSetupService; // Weak. |
| 96 std::unique_ptr<SyncObserverBridge> _syncObserver; | 99 std::unique_ptr<SyncObserverBridge> _syncObserver; |
| 97 std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver; | 100 std::unique_ptr<OAuth2TokenServiceObserverBridge> _tokenServiceObserver; |
| 98 base::scoped_nsobject<AuthenticationFlow> _authenticationFlow; | 101 AuthenticationFlow* _authenticationFlow; |
| 99 // Whether switching sync account is allowed on the screen. | 102 // Whether switching sync account is allowed on the screen. |
| 100 BOOL _allowSwitchSyncAccount; | 103 BOOL _allowSwitchSyncAccount; |
| 101 // Whether an authentication operation is in progress (e.g switch accounts). | 104 // Whether an authentication operation is in progress (e.g switch accounts). |
| 102 BOOL _authenticationOperationInProgress; | 105 BOOL _authenticationOperationInProgress; |
| 103 // Whether Sync State changes should be currently ignored. | 106 // Whether Sync State changes should be currently ignored. |
| 104 BOOL _ignoreSyncStateChanges; | 107 BOOL _ignoreSyncStateChanges; |
| 105 | 108 |
| 106 // Cache for Identity items avatar images. | 109 // Cache for Identity items avatar images. |
| 107 base::scoped_nsobject<ResizedAvatarCache> _avatarCache; | 110 ResizedAvatarCache* _avatarCache; |
| 108 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; | 111 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; |
| 109 // Enable lookup of item corresponding to a given identity GAIA ID string. | 112 // Enable lookup of item corresponding to a given identity GAIA ID string. |
| 110 base::scoped_nsobject<NSDictionary<NSString*, CollectionViewItem*>> | 113 NSDictionary<NSString*, CollectionViewItem*>* _identityMap; |
| 111 _identityMap; | |
| 112 } | 114 } |
| 113 | 115 |
| 114 // Stops observing browser state services. | 116 // Stops observing browser state services. |
| 115 - (void)stopBrowserStateServiceObservers; | 117 - (void)stopBrowserStateServiceObservers; |
| 116 // Pops the view if user is signed out and not authentication operation is in | 118 // Pops the view if user is signed out and not authentication operation is in |
| 117 // progress. Returns YES if the view was popped. | 119 // progress. Returns YES if the view was popped. |
| 118 - (BOOL)popViewIfSignedOut; | 120 - (BOOL)popViewIfSignedOut; |
| 119 | 121 |
| 120 // Returns a switch item for sync, set to on if |isOn| is YES. | 122 // Returns a switch item for sync, set to on if |isOn| is YES. |
| 121 - (CollectionViewItem*)syncSwitchItem:(BOOL)isOn; | 123 - (CollectionViewItem*)syncSwitchItem:(BOOL)isOn; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 _browserState = browserState; | 200 _browserState = browserState; |
| 199 _syncSetupService = | 201 _syncSetupService = |
| 200 SyncSetupServiceFactory::GetForBrowserState(_browserState); | 202 SyncSetupServiceFactory::GetForBrowserState(_browserState); |
| 201 self.title = l10n_util::GetNSString(IDS_IOS_SYNC_SETTING_TITLE); | 203 self.title = l10n_util::GetNSString(IDS_IOS_SYNC_SETTING_TITLE); |
| 202 browser_sync::ProfileSyncService* syncService = | 204 browser_sync::ProfileSyncService* syncService = |
| 203 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | 205 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); |
| 204 _syncObserver.reset(new SyncObserverBridge(self, syncService)); | 206 _syncObserver.reset(new SyncObserverBridge(self, syncService)); |
| 205 _tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge( | 207 _tokenServiceObserver.reset(new OAuth2TokenServiceObserverBridge( |
| 206 OAuth2TokenServiceFactory::GetForBrowserState(_browserState), self)); | 208 OAuth2TokenServiceFactory::GetForBrowserState(_browserState), self)); |
| 207 self.collectionViewAccessibilityIdentifier = kSettingsSyncId; | 209 self.collectionViewAccessibilityIdentifier = kSettingsSyncId; |
| 208 _avatarCache.reset([[ResizedAvatarCache alloc] init]); | 210 _avatarCache = [[ResizedAvatarCache alloc] init]; |
| 209 _identityServiceObserver.reset( | 211 _identityServiceObserver.reset( |
| 210 new ChromeIdentityServiceObserverBridge(self)); | 212 new ChromeIdentityServiceObserverBridge(self)); |
| 211 [self loadModel]; | 213 [self loadModel]; |
| 212 } | 214 } |
| 213 return self; | 215 return self; |
| 214 } | 216 } |
| 215 | 217 |
| 216 - (void)stopBrowserStateServiceObservers { | 218 - (void)stopBrowserStateServiceObservers { |
| 217 _syncObserver.reset(); | 219 _syncObserver.reset(); |
| 218 _tokenServiceObserver.reset(); | 220 _tokenServiceObserver.reset(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 259 |
| 258 // Sync Section. | 260 // Sync Section. |
| 259 BOOL syncEnabled = _syncSetupService->IsSyncEnabled(); | 261 BOOL syncEnabled = _syncSetupService->IsSyncEnabled(); |
| 260 [model addSectionWithIdentifier:SectionIdentifierEnableSync]; | 262 [model addSectionWithIdentifier:SectionIdentifierEnableSync]; |
| 261 [model addItem:[self syncSwitchItem:syncEnabled] | 263 [model addItem:[self syncSwitchItem:syncEnabled] |
| 262 toSectionWithIdentifier:SectionIdentifierEnableSync]; | 264 toSectionWithIdentifier:SectionIdentifierEnableSync]; |
| 263 | 265 |
| 264 // Sync to Section. | 266 // Sync to Section. |
| 265 if ([self hasAccountsSection]) { | 267 if ([self hasAccountsSection]) { |
| 266 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = | 268 NSMutableDictionary<NSString*, CollectionViewItem*>* mutableIdentityMap = |
| 267 [[[NSMutableDictionary alloc] init] autorelease]; | 269 [[NSMutableDictionary alloc] init]; |
| 268 // Accounts section. Cells enabled if sync is on. | 270 // Accounts section. Cells enabled if sync is on. |
| 269 [model addSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 271 [model addSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 270 CollectionViewTextItem* syncToHeader = [[[CollectionViewTextItem alloc] | 272 CollectionViewTextItem* syncToHeader = |
| 271 initWithType:ItemTypeHeader] autorelease]; | 273 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 272 syncToHeader.text = l10n_util::GetNSString(IDS_IOS_SYNC_TO_TITLE); | 274 syncToHeader.text = l10n_util::GetNSString(IDS_IOS_SYNC_TO_TITLE); |
| 273 syncToHeader.textColor = [[MDCPalette greyPalette] tint500]; | 275 syncToHeader.textColor = [[MDCPalette greyPalette] tint500]; |
| 274 [model setHeader:syncToHeader | 276 [model setHeader:syncToHeader |
| 275 forSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 277 forSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 276 ProfileOAuth2TokenService* oauth2_service = | 278 ProfileOAuth2TokenService* oauth2_service = |
| 277 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); | 279 OAuth2TokenServiceFactory::GetForBrowserState(_browserState); |
| 278 AccountTrackerService* accountTracker = | 280 AccountTrackerService* accountTracker = |
| 279 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); | 281 ios::AccountTrackerServiceFactory::GetForBrowserState(_browserState); |
| 280 | 282 |
| 281 for (const std::string& account_id : oauth2_service->GetAccounts()) { | 283 for (const std::string& account_id : oauth2_service->GetAccounts()) { |
| 282 AccountInfo account = accountTracker->GetAccountInfo(account_id); | 284 AccountInfo account = accountTracker->GetAccountInfo(account_id); |
| 283 ChromeIdentity* identity = ios::GetChromeBrowserProvider() | 285 ChromeIdentity* identity = ios::GetChromeBrowserProvider() |
| 284 ->GetChromeIdentityService() | 286 ->GetChromeIdentityService() |
| 285 ->GetIdentityWithGaiaID(account.gaia); | 287 ->GetIdentityWithGaiaID(account.gaia); |
| 286 CollectionViewItem* accountItem = [self accountItem:identity]; | 288 CollectionViewItem* accountItem = [self accountItem:identity]; |
| 287 [model addItem:accountItem | 289 [model addItem:accountItem |
| 288 toSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 290 toSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 289 [mutableIdentityMap setObject:accountItem forKey:identity.gaiaID]; | 291 [mutableIdentityMap setObject:accountItem forKey:identity.gaiaID]; |
| 290 } | 292 } |
| 291 _identityMap.reset([mutableIdentityMap retain]); | 293 _identityMap = mutableIdentityMap; |
| 292 } | 294 } |
| 293 | 295 |
| 294 // Data Types to sync. Enabled if sync is on. | 296 // Data Types to sync. Enabled if sync is on. |
| 295 [model addSectionWithIdentifier:SectionIdentifierSyncServices]; | 297 [model addSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 296 CollectionViewTextItem* syncServicesHeader = [ | 298 CollectionViewTextItem* syncServicesHeader = |
| 297 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 299 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 298 syncServicesHeader.text = | 300 syncServicesHeader.text = |
| 299 l10n_util::GetNSString(IDS_IOS_SYNC_DATA_TYPES_TITLE); | 301 l10n_util::GetNSString(IDS_IOS_SYNC_DATA_TYPES_TITLE); |
| 300 syncServicesHeader.textColor = [[MDCPalette greyPalette] tint500]; | 302 syncServicesHeader.textColor = [[MDCPalette greyPalette] tint500]; |
| 301 [model setHeader:syncServicesHeader | 303 [model setHeader:syncServicesHeader |
| 302 forSectionWithIdentifier:SectionIdentifierSyncServices]; | 304 forSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 303 BOOL syncEverythingEnabled = _syncSetupService->IsSyncingAllDataTypes(); | 305 BOOL syncEverythingEnabled = _syncSetupService->IsSyncingAllDataTypes(); |
| 304 [model addItem:[self syncEverythingSwitchItem:syncEverythingEnabled] | 306 [model addItem:[self syncEverythingSwitchItem:syncEverythingEnabled] |
| 305 toSectionWithIdentifier:SectionIdentifierSyncServices]; | 307 toSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 306 // Specific Data Types to sync. Enabled if Sync Everything is off. | 308 // Specific Data Types to sync. Enabled if Sync Everything is off. |
| 307 for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { | 309 for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 326 switchItemWithType:ItemTypeSyncSwitch | 328 switchItemWithType:ItemTypeSyncSwitch |
| 327 title:l10n_util::GetNSString(IDS_IOS_SYNC_SETTING_TITLE) | 329 title:l10n_util::GetNSString(IDS_IOS_SYNC_SETTING_TITLE) |
| 328 subTitle:l10n_util::GetNSString( | 330 subTitle:l10n_util::GetNSString( |
| 329 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SUBTITLE)]; | 331 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SUBTITLE)]; |
| 330 syncSwitchItem.on = isOn; | 332 syncSwitchItem.on = isOn; |
| 331 return syncSwitchItem; | 333 return syncSwitchItem; |
| 332 } | 334 } |
| 333 | 335 |
| 334 - (CollectionViewItem*)syncErrorItem { | 336 - (CollectionViewItem*)syncErrorItem { |
| 335 DCHECK([self shouldDisplaySyncError]); | 337 DCHECK([self shouldDisplaySyncError]); |
| 336 CollectionViewAccountItem* syncErrorItem = [[[CollectionViewAccountItem alloc] | 338 CollectionViewAccountItem* syncErrorItem = |
| 337 initWithType:ItemTypeSyncError] autorelease]; | 339 [[CollectionViewAccountItem alloc] initWithType:ItemTypeSyncError]; |
| 338 syncErrorItem.text = l10n_util::GetNSString(IDS_IOS_SYNC_ERROR_TITLE); | 340 syncErrorItem.text = l10n_util::GetNSString(IDS_IOS_SYNC_ERROR_TITLE); |
| 339 syncErrorItem.image = [UIImage imageNamed:@"settings_error"]; | 341 syncErrorItem.image = [UIImage imageNamed:@"settings_error"]; |
| 340 syncErrorItem.detailText = | 342 syncErrorItem.detailText = |
| 341 ios_internal::sync::GetSyncErrorMessageForBrowserState(_browserState); | 343 ios_internal::sync::GetSyncErrorMessageForBrowserState(_browserState); |
| 342 return syncErrorItem; | 344 return syncErrorItem; |
| 343 } | 345 } |
| 344 | 346 |
| 345 - (CollectionViewItem*)accountItem:(ChromeIdentity*)identity { | 347 - (CollectionViewItem*)accountItem:(ChromeIdentity*)identity { |
| 346 CollectionViewAccountItem* identityAccountItem = | 348 CollectionViewAccountItem* identityAccountItem = |
| 347 [[[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount] | 349 [[CollectionViewAccountItem alloc] initWithType:ItemTypeAccount]; |
| 348 autorelease]; | |
| 349 [self updateAccountItem:identityAccountItem withIdentity:identity]; | 350 [self updateAccountItem:identityAccountItem withIdentity:identity]; |
| 350 | 351 |
| 351 identityAccountItem.enabled = _syncSetupService->IsSyncEnabled(); | 352 identityAccountItem.enabled = _syncSetupService->IsSyncEnabled(); |
| 352 ChromeIdentity* authenticatedIdentity = | 353 ChromeIdentity* authenticatedIdentity = |
| 353 AuthenticationServiceFactory::GetForBrowserState(_browserState) | 354 AuthenticationServiceFactory::GetForBrowserState(_browserState) |
| 354 ->GetAuthenticatedIdentity(); | 355 ->GetAuthenticatedIdentity(); |
| 355 if (identity == authenticatedIdentity) { | 356 if (identity == authenticatedIdentity) { |
| 356 identityAccountItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 357 identityAccountItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
| 357 } | 358 } |
| 358 return identityAccountItem; | 359 return identityAccountItem; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 379 [self titleIdForSyncableDataType:dataType]) | 380 [self titleIdForSyncableDataType:dataType]) |
| 380 subTitle:nil]; | 381 subTitle:nil]; |
| 381 syncDataTypeItem.dataType = dataType; | 382 syncDataTypeItem.dataType = dataType; |
| 382 syncDataTypeItem.on = isOn; | 383 syncDataTypeItem.on = isOn; |
| 383 syncDataTypeItem.enabled = [self shouldSyncableItemsBeEnabled]; | 384 syncDataTypeItem.enabled = [self shouldSyncableItemsBeEnabled]; |
| 384 return syncDataTypeItem; | 385 return syncDataTypeItem; |
| 385 } | 386 } |
| 386 | 387 |
| 387 - (CollectionViewItem*)encryptionCellItem { | 388 - (CollectionViewItem*)encryptionCellItem { |
| 388 TextAndErrorItem* encryptionCellItem = | 389 TextAndErrorItem* encryptionCellItem = |
| 389 [[[TextAndErrorItem alloc] initWithType:ItemTypeEncryption] autorelease]; | 390 [[TextAndErrorItem alloc] initWithType:ItemTypeEncryption]; |
| 390 encryptionCellItem.text = | 391 encryptionCellItem.text = |
| 391 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE); | 392 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE); |
| 392 encryptionCellItem.accessoryType = | 393 encryptionCellItem.accessoryType = |
| 393 MDCCollectionViewCellAccessoryDisclosureIndicator; | 394 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 394 encryptionCellItem.shouldDisplayError = [self shouldDisplayEncryptionError]; | 395 encryptionCellItem.shouldDisplayError = [self shouldDisplayEncryptionError]; |
| 395 encryptionCellItem.enabled = [self shouldEncryptionItemBeEnabled]; | 396 encryptionCellItem.enabled = [self shouldEncryptionItemBeEnabled]; |
| 396 return encryptionCellItem; | 397 return encryptionCellItem; |
| 397 } | 398 } |
| 398 | 399 |
| 399 - (CollectionViewItem*)manageSyncedDataItem { | 400 - (CollectionViewItem*)manageSyncedDataItem { |
| 400 CollectionViewTextItem* manageSyncedDataItem = | 401 CollectionViewTextItem* manageSyncedDataItem = |
| 401 [[[CollectionViewTextItem alloc] initWithType:ItemTypeManageSyncedData] | 402 [[CollectionViewTextItem alloc] initWithType:ItemTypeManageSyncedData]; |
| 402 autorelease]; | |
| 403 manageSyncedDataItem.text = | 403 manageSyncedDataItem.text = |
| 404 l10n_util::GetNSString(IDS_IOS_SYNC_RESET_GOOGLE_DASHBOARD_NO_LINK); | 404 l10n_util::GetNSString(IDS_IOS_SYNC_RESET_GOOGLE_DASHBOARD_NO_LINK); |
| 405 manageSyncedDataItem.accessibilityTraits |= UIAccessibilityTraitButton; | 405 manageSyncedDataItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| 406 return manageSyncedDataItem; | 406 return manageSyncedDataItem; |
| 407 } | 407 } |
| 408 | 408 |
| 409 #pragma mark Item Constructors | 409 #pragma mark Item Constructors |
| 410 | 410 |
| 411 - (SyncSwitchItem*)switchItemWithType:(NSInteger)type | 411 - (SyncSwitchItem*)switchItemWithType:(NSInteger)type |
| 412 title:(NSString*)title | 412 title:(NSString*)title |
| 413 subTitle:(NSString*)detailText { | 413 subTitle:(NSString*)detailText { |
| 414 SyncSwitchItem* switchItem = | 414 SyncSwitchItem* switchItem = [[SyncSwitchItem alloc] initWithType:type]; |
| 415 [[[SyncSwitchItem alloc] initWithType:type] autorelease]; | |
| 416 switchItem.text = title; | 415 switchItem.text = title; |
| 417 switchItem.detailText = detailText; | 416 switchItem.detailText = detailText; |
| 418 return switchItem; | 417 return switchItem; |
| 419 } | 418 } |
| 420 | 419 |
| 421 #pragma mark - UICollectionViewDataSource | 420 #pragma mark - UICollectionViewDataSource |
| 422 | 421 |
| 423 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 422 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 424 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | 423 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 425 UICollectionViewCell* cell = | 424 UICollectionViewCell* cell = |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 488 } |
| 490 break; | 489 break; |
| 491 } | 490 } |
| 492 case ItemTypeEncryption: | 491 case ItemTypeEncryption: |
| 493 [self showEncryption]; | 492 [self showEncryption]; |
| 494 break; | 493 break; |
| 495 case ItemTypeManageSyncedData: { | 494 case ItemTypeManageSyncedData: { |
| 496 GURL learnMoreUrl = google_util::AppendGoogleLocaleParam( | 495 GURL learnMoreUrl = google_util::AppendGoogleLocaleParam( |
| 497 GURL(kSyncGoogleDashboardURL), | 496 GURL(kSyncGoogleDashboardURL), |
| 498 GetApplicationContext()->GetApplicationLocale()); | 497 GetApplicationContext()->GetApplicationLocale()); |
| 499 base::scoped_nsobject<OpenUrlCommand> command( | 498 OpenUrlCommand* command = |
| 500 [[OpenUrlCommand alloc] initWithURLFromChrome:learnMoreUrl]); | 499 [[OpenUrlCommand alloc] initWithURLFromChrome:learnMoreUrl]; |
| 501 [command setTag:IDC_CLOSE_SETTINGS_AND_OPEN_URL]; | 500 [command setTag:IDC_CLOSE_SETTINGS_AND_OPEN_URL]; |
| 502 [self chromeExecuteCommand:command]; | 501 [self chromeExecuteCommand:command]; |
| 503 break; | 502 break; |
| 504 } | 503 } |
| 505 default: | 504 default: |
| 506 break; | 505 break; |
| 507 } | 506 } |
| 508 } | 507 } |
| 509 | 508 |
| 510 #pragma mark MDCCollectionViewStylingDelegate | 509 #pragma mark MDCCollectionViewStylingDelegate |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 if (_syncSetupService->GetSyncServiceState() == | 583 if (_syncSetupService->GetSyncServiceState() == |
| 585 SyncSetupService::kSyncServiceUnrecoverableError) { | 584 SyncSetupService::kSyncServiceUnrecoverableError) { |
| 586 ChromeIdentity* authenticatedIdentity = | 585 ChromeIdentity* authenticatedIdentity = |
| 587 AuthenticationServiceFactory::GetForBrowserState(_browserState) | 586 AuthenticationServiceFactory::GetForBrowserState(_browserState) |
| 588 ->GetAuthenticatedIdentity(); | 587 ->GetAuthenticatedIdentity(); |
| 589 [self startSwitchAccountForIdentity:authenticatedIdentity | 588 [self startSwitchAccountForIdentity:authenticatedIdentity |
| 590 postSignInAction:POST_SIGNIN_ACTION_START_SYNC]; | 589 postSignInAction:POST_SIGNIN_ACTION_START_SYNC]; |
| 591 return; | 590 return; |
| 592 } | 591 } |
| 593 | 592 |
| 594 base::scoped_nsobject<GenericChromeCommand> command( | 593 GenericChromeCommand* command = |
| 595 [ios_internal::sync::GetSyncCommandForBrowserState(_browserState) | 594 ios_internal::sync::GetSyncCommandForBrowserState(_browserState); |
| 596 retain]); | |
| 597 [self chromeExecuteCommand:command]; | 595 [self chromeExecuteCommand:command]; |
| 598 } | 596 } |
| 599 | 597 |
| 600 - (void)startSwitchAccountForIdentity:(ChromeIdentity*)identity | 598 - (void)startSwitchAccountForIdentity:(ChromeIdentity*)identity |
| 601 postSignInAction:(PostSignInAction)postSignInAction { | 599 postSignInAction:(PostSignInAction)postSignInAction { |
| 602 if (!_syncSetupService->IsSyncEnabled()) | 600 if (!_syncSetupService->IsSyncEnabled()) |
| 603 return; | 601 return; |
| 604 | 602 |
| 605 _authenticationOperationInProgress = YES; | 603 _authenticationOperationInProgress = YES; |
| 606 [[NSNotificationCenter defaultCenter] | 604 [[NSNotificationCenter defaultCenter] |
| 607 postNotificationName:kSwitchAccountWillStartNotification | 605 postNotificationName:kSwitchAccountWillStartNotification |
| 608 object:self]; | 606 object:self]; |
| 609 [self preventUserInteraction]; | 607 [self preventUserInteraction]; |
| 610 DCHECK(!_authenticationFlow); | 608 DCHECK(!_authenticationFlow); |
| 611 _authenticationFlow.reset([[AuthenticationFlow alloc] | 609 _authenticationFlow = [[AuthenticationFlow alloc] |
| 612 initWithBrowserState:_browserState | 610 initWithBrowserState:_browserState |
| 613 identity:identity | 611 identity:identity |
| 614 shouldClearData:SHOULD_CLEAR_DATA_USER_CHOICE | 612 shouldClearData:SHOULD_CLEAR_DATA_USER_CHOICE |
| 615 postSignInAction:postSignInAction | 613 postSignInAction:postSignInAction |
| 616 presentingViewController:self]); | 614 presentingViewController:self]; |
| 617 | 615 |
| 618 base::WeakNSObject<SyncSettingsCollectionViewController> weakSelf(self); | 616 __weak SyncSettingsCollectionViewController* weakSelf = self; |
| 619 [_authenticationFlow startSignInWithCompletion:^(BOOL success) { | 617 [_authenticationFlow startSignInWithCompletion:^(BOOL success) { |
| 620 [weakSelf didSwitchAccountWithSuccess:success]; | 618 [weakSelf didSwitchAccountWithSuccess:success]; |
| 621 }]; | 619 }]; |
| 622 } | 620 } |
| 623 | 621 |
| 624 - (void)didSwitchAccountWithSuccess:(BOOL)success { | 622 - (void)didSwitchAccountWithSuccess:(BOOL)success { |
| 625 _authenticationFlow.reset(); | 623 _authenticationFlow = nil; |
| 626 [self allowUserInteraction]; | 624 [self allowUserInteraction]; |
| 627 [[NSNotificationCenter defaultCenter] | 625 [[NSNotificationCenter defaultCenter] |
| 628 postNotificationName:kSwitchAccountDidFinishNotification | 626 postNotificationName:kSwitchAccountDidFinishNotification |
| 629 object:self]; | 627 object:self]; |
| 630 _authenticationOperationInProgress = NO; | 628 _authenticationOperationInProgress = NO; |
| 631 if (![self popViewIfSignedOut]) { | 629 if (![self popViewIfSignedOut]) { |
| 632 // Only reload the view if it wasn't popped. | 630 // Only reload the view if it wasn't popped. |
| 633 [self reloadData]; | 631 [self reloadData]; |
| 634 } | 632 } |
| 635 } | 633 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 } | 682 } |
| 685 | 683 |
| 686 - (void)showEncryption { | 684 - (void)showEncryption { |
| 687 browser_sync::ProfileSyncService* syncService = | 685 browser_sync::ProfileSyncService* syncService = |
| 688 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); | 686 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); |
| 689 if (!syncService->IsEngineInitialized() || | 687 if (!syncService->IsEngineInitialized() || |
| 690 !_syncSetupService->IsSyncEnabled() || | 688 !_syncSetupService->IsSyncEnabled() || |
| 691 [self shouldDisableSettingsOnSyncError]) | 689 [self shouldDisableSettingsOnSyncError]) |
| 692 return; | 690 return; |
| 693 | 691 |
| 694 base::scoped_nsobject<UIViewController> controllerToPush; | 692 UIViewController* controllerToPush; |
| 695 // If there was a sync error, prompt the user to enter the passphrase. | 693 // If there was a sync error, prompt the user to enter the passphrase. |
| 696 // Otherwise, show the full encryption options. | 694 // Otherwise, show the full encryption options. |
| 697 if (syncService->IsPassphraseRequired()) { | 695 if (syncService->IsPassphraseRequired()) { |
| 698 controllerToPush.reset( | 696 controllerToPush = [[SyncEncryptionPassphraseCollectionViewController alloc] |
| 699 [[SyncEncryptionPassphraseCollectionViewController alloc] | 697 initWithBrowserState:_browserState]; |
| 700 initWithBrowserState:_browserState]); | |
| 701 } else { | 698 } else { |
| 702 controllerToPush.reset([[SyncEncryptionCollectionViewController alloc] | 699 controllerToPush = [[SyncEncryptionCollectionViewController alloc] |
| 703 initWithBrowserState:_browserState]); | 700 initWithBrowserState:_browserState]; |
| 704 } | 701 } |
| 705 [self.navigationController pushViewController:controllerToPush animated:YES]; | 702 [self.navigationController pushViewController:controllerToPush animated:YES]; |
| 706 } | 703 } |
| 707 | 704 |
| 708 #pragma mark Updates | 705 #pragma mark Updates |
| 709 | 706 |
| 710 - (void)updateCollectionView { | 707 - (void)updateCollectionView { |
| 711 base::WeakNSObject<SyncSettingsCollectionViewController> weakSelf(self); | 708 __weak SyncSettingsCollectionViewController* weakSelf = self; |
| 712 [self.collectionView performBatchUpdates:^{ | 709 [self.collectionView performBatchUpdates:^{ |
| 713 [weakSelf updateCollectionViewInternal]; | 710 [weakSelf updateCollectionViewInternal]; |
| 714 } | 711 } |
| 715 completion:nil]; | 712 completion:nil]; |
| 716 } | 713 } |
| 717 | 714 |
| 718 - (void)updateCollectionViewInternal { | 715 - (void)updateCollectionViewInternal { |
| 719 NSIndexPath* indexPath = [self.collectionViewModel | 716 NSIndexPath* indexPath = [self.collectionViewModel |
| 720 indexPathForItemType:ItemTypeSyncSwitch | 717 indexPathForItemType:ItemTypeSyncSwitch |
| 721 sectionIdentifier:SectionIdentifierEnableSync]; | 718 sectionIdentifier:SectionIdentifierEnableSync]; |
| 722 | 719 |
| 723 SyncSwitchItem* syncItem = base::mac::ObjCCastStrict<SyncSwitchItem>( | 720 SyncSwitchItem* syncItem = base::mac::ObjCCastStrict<SyncSwitchItem>( |
| 724 [self.collectionViewModel itemAtIndexPath:indexPath]); | 721 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 725 syncItem.on = _syncSetupService->IsSyncEnabled(); | 722 syncItem.on = _syncSetupService->IsSyncEnabled(); |
| 726 [self reconfigureCellsForItems:@[ syncItem ] | 723 [self reconfigureCellsForItems:@[ syncItem ] |
| 727 inSectionWithIdentifier:SectionIdentifierEnableSync]; | 724 inSectionWithIdentifier:SectionIdentifierEnableSync]; |
| 728 | 725 |
| 729 // Update Sync Accounts section. | 726 // Update Sync Accounts section. |
| 730 if ([self hasAccountsSection]) { | 727 if ([self hasAccountsSection]) { |
| 731 NSInteger section = [self.collectionViewModel | 728 NSInteger section = [self.collectionViewModel |
| 732 sectionForSectionIdentifier:SectionIdentifierSyncAccounts]; | 729 sectionForSectionIdentifier:SectionIdentifierSyncAccounts]; |
| 733 NSInteger itemsCount = | 730 NSInteger itemsCount = |
| 734 [self.collectionViewModel numberOfItemsInSection:section]; | 731 [self.collectionViewModel numberOfItemsInSection:section]; |
| 735 NSMutableArray* accountsToReconfigure = | 732 NSMutableArray* accountsToReconfigure = [[NSMutableArray alloc] init]; |
| 736 [[[NSMutableArray alloc] init] autorelease]; | |
| 737 for (NSInteger item = 0; item < itemsCount; ++item) { | 733 for (NSInteger item = 0; item < itemsCount; ++item) { |
| 738 NSIndexPath* indexPath = [self.collectionViewModel | 734 NSIndexPath* indexPath = [self.collectionViewModel |
| 739 indexPathForItemType:ItemTypeAccount | 735 indexPathForItemType:ItemTypeAccount |
| 740 sectionIdentifier:SectionIdentifierSyncAccounts | 736 sectionIdentifier:SectionIdentifierSyncAccounts |
| 741 atIndex:item]; | 737 atIndex:item]; |
| 742 CollectionViewAccountItem* accountItem = | 738 CollectionViewAccountItem* accountItem = |
| 743 base::mac::ObjCCastStrict<CollectionViewAccountItem>( | 739 base::mac::ObjCCastStrict<CollectionViewAccountItem>( |
| 744 [self.collectionViewModel itemAtIndexPath:indexPath]); | 740 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 745 accountItem.enabled = _syncSetupService->IsSyncEnabled(); | 741 accountItem.enabled = _syncSetupService->IsSyncEnabled(); |
| 746 [accountsToReconfigure addObject:accountItem]; | 742 [accountsToReconfigure addObject:accountItem]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 759 syncEverythingItem.on = _syncSetupService->IsSyncingAllDataTypes(); | 755 syncEverythingItem.on = _syncSetupService->IsSyncingAllDataTypes(); |
| 760 syncEverythingItem.enabled = [self shouldSyncEverythingItemBeEnabled]; | 756 syncEverythingItem.enabled = [self shouldSyncEverythingItemBeEnabled]; |
| 761 [self reconfigureCellsForItems:@[ syncEverythingItem ] | 757 [self reconfigureCellsForItems:@[ syncEverythingItem ] |
| 762 inSectionWithIdentifier:SectionIdentifierSyncServices]; | 758 inSectionWithIdentifier:SectionIdentifierSyncServices]; |
| 763 | 759 |
| 764 NSInteger section = [self.collectionViewModel | 760 NSInteger section = [self.collectionViewModel |
| 765 sectionForSectionIdentifier:SectionIdentifierSyncServices]; | 761 sectionForSectionIdentifier:SectionIdentifierSyncServices]; |
| 766 NSInteger itemsCount = | 762 NSInteger itemsCount = |
| 767 [self.collectionViewModel numberOfItemsInSection:section]; | 763 [self.collectionViewModel numberOfItemsInSection:section]; |
| 768 // Syncable data types cells are offset by the Sync Everything cell. | 764 // Syncable data types cells are offset by the Sync Everything cell. |
| 769 NSMutableArray* switchsToReconfigure = | 765 NSMutableArray* switchsToReconfigure = [[NSMutableArray alloc] init]; |
| 770 [[[NSMutableArray alloc] init] autorelease]; | |
| 771 for (NSInteger item = 1; item < itemsCount; ++item) { | 766 for (NSInteger item = 1; item < itemsCount; ++item) { |
| 772 NSUInteger index = item - 1; | 767 NSUInteger index = item - 1; |
| 773 NSIndexPath* indexPath = [self.collectionViewModel | 768 NSIndexPath* indexPath = [self.collectionViewModel |
| 774 indexPathForItemType:ItemTypeSyncableDataType | 769 indexPathForItemType:ItemTypeSyncableDataType |
| 775 sectionIdentifier:SectionIdentifierSyncServices | 770 sectionIdentifier:SectionIdentifierSyncServices |
| 776 atIndex:index]; | 771 atIndex:index]; |
| 777 SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>( | 772 SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>( |
| 778 [self.collectionViewModel itemAtIndexPath:indexPath]); | 773 [self.collectionViewModel itemAtIndexPath:indexPath]); |
| 779 SyncSetupService::SyncableDatatype dataType = | 774 SyncSetupService::SyncableDatatype dataType = |
| 780 (SyncSetupService::SyncableDatatype)syncSwitchItem.dataType; | 775 (SyncSetupService::SyncableDatatype)syncSwitchItem.dataType; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 [self updateAccountItem:item withIdentity:identity]; | 962 [self updateAccountItem:item withIdentity:identity]; |
| 968 [self reconfigureCellsForItems:@[ item ] | 963 [self reconfigureCellsForItems:@[ item ] |
| 969 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; | 964 inSectionWithIdentifier:SectionIdentifierSyncAccounts]; |
| 970 } | 965 } |
| 971 | 966 |
| 972 - (void)onChromeIdentityServiceWillBeDestroyed { | 967 - (void)onChromeIdentityServiceWillBeDestroyed { |
| 973 _identityServiceObserver.reset(); | 968 _identityServiceObserver.reset(); |
| 974 } | 969 } |
| 975 | 970 |
| 976 @end | 971 @end |
| OLD | NEW |