Commit e97a0d3d authored by bzanotti's avatar bzanotti Committed by Commit bot

[iOS] Correctly reload Sync Encryption settings screen on sync changes.

Sync Encryption screen now listens to sync changes and reloads itself
when necessary. This ensures modifications to the passphrase (done by
the Sync Encryption Passphrase screen) are reflected in the UI.

BUG=678609

Review-Url: https://codereview.chromium.org/2610403003
Cr-Commit-Position: refs/heads/master@{#441927}
parent 9abd41a8
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "base/ios/weak_nsobject.h" #import "base/ios/weak_nsobject.h"
#import "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/browser_sync/profile_sync_service.h" #include "components/browser_sync/profile_sync_service.h"
#include "components/google/core/browser/google_util.h" #include "components/google/core/browser/google_util.h"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
#import "ios/chrome/browser/sync/sync_observer_bridge.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h" #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
...@@ -42,8 +44,10 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -42,8 +44,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace } // namespace
@interface SyncEncryptionCollectionViewController () { @interface SyncEncryptionCollectionViewController ()<SyncObserverModelBridge> {
ios::ChromeBrowserState* _browserState; ios::ChromeBrowserState* _browserState;
std::unique_ptr<SyncObserverBridge> _syncObserver;
BOOL _isUsingSecondaryPassphrase;
} }
// Returns an account item. // Returns an account item.
- (CollectionViewItem*)accountItem; - (CollectionViewItem*)accountItem;
...@@ -63,6 +67,11 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -63,6 +67,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
if (self) { if (self) {
self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE); self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE);
_browserState = browserState; _browserState = browserState;
browser_sync::ProfileSyncService* syncService =
IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
_isUsingSecondaryPassphrase = syncService->IsEngineInitialized() &&
syncService->IsUsingSecondaryPassphrase();
_syncObserver = base::MakeUnique<SyncObserverBridge>(self, syncService);
[self loadModel]; [self loadModel];
} }
return self; return self;
...@@ -80,9 +89,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -80,9 +89,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model addItem:[self passphraseItem] [model addItem:[self passphraseItem]
toSectionWithIdentifier:SectionIdentifierEncryption]; toSectionWithIdentifier:SectionIdentifierEncryption];
browser_sync::ProfileSyncService* service = if (_isUsingSecondaryPassphrase) {
IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
[model addSectionWithIdentifier:SectionIdentifierFooter]; [model addSectionWithIdentifier:SectionIdentifierFooter];
[model addItem:[self footerItem] [model addItem:[self footerItem]
toSectionWithIdentifier:SectionIdentifierFooter]; toSectionWithIdentifier:SectionIdentifierFooter];
...@@ -93,35 +100,20 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -93,35 +100,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (CollectionViewItem*)accountItem { - (CollectionViewItem*)accountItem {
DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag());
BOOL checkedAndEnabled = YES;
browser_sync::ProfileSyncService* service =
IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
checkedAndEnabled = NO;
}
NSString* text = l10n_util::GetNSString(IDS_SYNC_BASIC_ENCRYPTION_DATA); NSString* text = l10n_util::GetNSString(IDS_SYNC_BASIC_ENCRYPTION_DATA);
return [self itemWithType:ItemTypeAccount return [self itemWithType:ItemTypeAccount
text:text text:text
checked:checkedAndEnabled checked:!_isUsingSecondaryPassphrase
enabled:checkedAndEnabled]; enabled:!_isUsingSecondaryPassphrase];
} }
- (CollectionViewItem*)passphraseItem { - (CollectionViewItem*)passphraseItem {
DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag()); DCHECK(browser_sync::ProfileSyncService::IsSyncAllowedByFlag());
BOOL checked = NO;
BOOL enabled = NO;
browser_sync::ProfileSyncService* service =
IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
checked = YES;
} else {
enabled = YES;
}
NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA); NSString* text = l10n_util::GetNSString(IDS_SYNC_FULL_ENCRYPTION_DATA);
return [self itemWithType:ItemTypePassphrase return [self itemWithType:ItemTypePassphrase
text:text text:text
checked:checked checked:_isUsingSecondaryPassphrase
enabled:enabled]; enabled:!_isUsingSecondaryPassphrase];
} }
- (CollectionViewItem*)footerItem { - (CollectionViewItem*)footerItem {
...@@ -213,6 +205,19 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -213,6 +205,19 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
} }
#pragma mark SyncObserverModelBridge
- (void)onSyncStateChanged {
browser_sync::ProfileSyncService* service =
IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
BOOL isNowUsingSecondaryPassphrase =
service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase();
if (_isUsingSecondaryPassphrase != isNowUsingSecondaryPassphrase) {
_isUsingSecondaryPassphrase = isNowUsingSecondaryPassphrase;
[self reloadData];
}
}
#pragma mark - Private methods #pragma mark - Private methods
- (CollectionViewItem*)itemWithType:(NSInteger)type - (CollectionViewItem*)itemWithType:(NSInteger)type
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment