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

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: Use MakeUnique with std::unique_ptr 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..9930c152ca4001a4499807b94eec512e2047c652 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
@@ -6,6 +6,7 @@
#import "base/ios/weak_nsobject.h"
#import "base/mac/scoped_nsobject.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/google/core/browser/google_util.h"
@@ -15,6 +16,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 +44,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 +67,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 = base::MakeUnique<SyncObserverBridge>(self, syncService);
[self loadModel];
}
return self;
@@ -80,9 +89,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 +100,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 +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
- (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