Commit bcad0a4d authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Adding implementation for Passphrase dialog in Manage Sync settings

Opens the sync encryption dialog when the user taps on the "Encryption"
item.

Bug: 914059
Change-Id: I5a750107f2594e64c4d81e468a47c8a7607e5286
Reviewed-on: https://chromium-review.googlesource.com/c/1477237
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635144}
parent 911807f0
......@@ -5,11 +5,14 @@
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_coordinator.h"
#include "base/logging.h"
#include "components/browser_sync/profile_sync_service.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#include "ios/chrome/browser/sync/sync_setup_service_factory.h"
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_command_handler.h"
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_mediator.h"
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/sync/sync_encryption_passphrase_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/sync/sync_encryption_table_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -60,6 +63,21 @@
#pragma mark - ManageSyncSettingsCommandHandler
- (void)openPassphraseDialog {
DCHECK(self.mediator.shouldEncryptionItemBeEnabled);
syncer::SyncService* syncService =
ProfileSyncServiceFactory::GetForBrowserState(self.browserState);
UIViewController<SettingsRootViewControlling>* controllerToPush;
// If there was a sync error, prompt the user to enter the passphrase.
// Otherwise, show the full encryption options.
if (syncService->GetUserSettings()->IsPassphraseRequired()) {
controllerToPush = [[SyncEncryptionPassphraseTableViewController alloc]
initWithBrowserState:self.browserState];
} else {
controllerToPush = [[SyncEncryptionTableViewController alloc]
initWithBrowserState:self.browserState];
}
controllerToPush.dispatcher = self.dispatcher;
[self.navigationController pushViewController:controllerToPush animated:YES];
}
- (void)openWebAppActivityDialog {
......
......@@ -28,6 +28,8 @@ class SyncService;
@property(nonatomic, assign) SyncSetupService* syncSetupService;
// Command handler.
@property(nonatomic, weak) id<ManageSyncSettingsCommandHandler> commandHandler;
// Returns YES if the encryption item should be enabled.
@property(nonatomic, assign, readonly) BOOL shouldEncryptionItemBeEnabled;
// Designated initializer.
// |syncService|: Sync service. Should not be null.
......
......@@ -220,13 +220,9 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// Updates encryption item, and notifies the consumer if |notifyConsumer| is set
// to YES.
- (void)updateEncryptionItem:(BOOL)notifyConsumer {
BOOL shouldEncryptionItemBeEnabled =
self.syncService->IsEngineInitialized() &&
self.syncSetupService->IsSyncEnabled() &&
!self.disabledBecauseOfSyncError;
BOOL needsUpdate =
shouldEncryptionItemBeEnabled &&
(self.encryptionItem.enabled != shouldEncryptionItemBeEnabled);
self.shouldEncryptionItemBeEnabled &&
(self.encryptionItem.enabled != self.shouldEncryptionItemBeEnabled);
if (self.syncSetupService->GetSyncServiceState() ==
SyncSetupService::kSyncServiceNeedsPassphrase) {
needsUpdate = needsUpdate || self.encryptionItem.image == nil;
......@@ -239,8 +235,8 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
self.encryptionItem.image = nil;
self.encryptionItem.detailText = nil;
}
self.encryptionItem.enabled = shouldEncryptionItemBeEnabled;
if (shouldEncryptionItemBeEnabled) {
self.encryptionItem.enabled = self.shouldEncryptionItemBeEnabled;
if (self.shouldEncryptionItemBeEnabled) {
self.encryptionItem.textColor = nil;
} else {
self.encryptionItem.textColor =
......@@ -308,6 +304,12 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
state != SyncSetupService::kSyncServiceNeedsPassphrase;
}
- (BOOL)shouldEncryptionItemBeEnabled {
return self.syncService->IsEngineInitialized() &&
self.syncSetupService->IsSyncEnabled() &&
!self.disabledBecauseOfSyncError;
}
#pragma mark - ManageSyncSettingsTableViewControllerModelDelegate
- (void)manageSyncSettingsTableViewControllerLoadModel:
......
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