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

Unified Diff: ios/chrome/browser/ui/settings/sync_encryption_collection_view_controller.mm

Issue 2610403003: [iOS] Correctly reload Sync Encryption settings screen on sync changes. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/settings/sync_encryption_collection_view_controller.mm
diff --git a/ios/chrome/browser/ui/settings/sync_encryption_collection_view_controller.mm b/ios/chrome/browser/ui/settings/sync_encryption_collection_view_controller.mm
index 2c8be472c4a5d39aafecbe35397f161e9cc84ed4..424f3532cd239973aed71f8be5d89a8b8b386912 100644
--- a/ios/chrome/browser/ui/settings/sync_encryption_collection_view_controller.mm
+++ b/ios/chrome/browser/ui/settings/sync_encryption_collection_view_controller.mm
@@ -15,6 +15,7 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.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/collection_view_footer_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
@@ -42,8 +43,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace
-@interface SyncEncryptionCollectionViewController () {
+@interface SyncEncryptionCollectionViewController ()<SyncObserverModelBridge> {
ios::ChromeBrowserState* _browserState;
+ std::unique_ptr<SyncObserverBridge> _syncObserver;
+ BOOL _isUsingSecondaryPassphrase;
}
// Returns an account item.
- (CollectionViewItem*)accountItem;
@@ -63,6 +66,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
if (self) {
self.title = l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_TITLE);
_browserState = browserState;
+ browser_sync::ProfileSyncService* syncService =
+ IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
+ _isUsingSecondaryPassphrase = syncService->IsEngineInitialized() &&
+ syncService->IsUsingSecondaryPassphrase();
+ _syncObserver.reset(new SyncObserverBridge(self, syncService));
lpromero 2017/01/06 11:01:07 Use MakeUnique instead of new.
bzanotti 2017/01/06 12:41:26 Done.
[self loadModel];
}
return self;
@@ -80,9 +88,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model addItem:[self passphraseItem]
toSectionWithIdentifier:SectionIdentifierEncryption];
- browser_sync::ProfileSyncService* service =
- IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState);
- if (service->IsEngineInitialized() && service->IsUsingSecondaryPassphrase()) {
+ if (_isUsingSecondaryPassphrase) {
[model addSectionWithIdentifier:SectionIdentifierFooter];
[model addItem:[self footerItem]
toSectionWithIdentifier:SectionIdentifierFooter];
@@ -93,35 +99,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (CollectionViewItem*)accountItem {
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);
return [self itemWithType:ItemTypeAccount
text:text
- checked:checkedAndEnabled
- enabled:checkedAndEnabled];
+ checked:!_isUsingSecondaryPassphrase
+ enabled:!_isUsingSecondaryPassphrase];
}
- (CollectionViewItem*)passphraseItem {
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);
return [self itemWithType:ItemTypePassphrase
text:text
- checked:checked
- enabled:enabled];
+ checked:_isUsingSecondaryPassphrase
+ enabled:!_isUsingSecondaryPassphrase];
}
- (CollectionViewItem*)footerItem {
@@ -213,6 +204,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
- (CollectionViewItem*)itemWithType:(NSInteger)type
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698