Commit 2f7a1068 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Password-Breach] Move toggle to google services

This changes might over update the switch and therefore the on/off
animation is being killed. To be fixed in a follow up for a later
release.

Bug: 1028095
Change-Id: Id9e28eeecde05f230c34d1b4f00fdb3df650f73b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1937172
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719329}
parent 436ee16f
...@@ -41,6 +41,7 @@ source_set("google_services") { ...@@ -41,6 +41,7 @@ source_set("google_services") {
"//components/browser_sync", "//components/browser_sync",
"//components/google/core/common", "//components/google/core/common",
"//components/metrics", "//components/metrics",
"//components/password_manager/core/common",
"//components/prefs", "//components/prefs",
"//components/signin/public/identity_manager", "//components/signin/public/identity_manager",
"//components/signin/public/identity_manager/objc", "//components/signin/public/identity_manager/objc",
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "components/metrics/metrics_pref_names.h" #include "components/metrics/metrics_pref_names.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#import "components/signin/public/identity_manager/objc/identity_manager_observer_bridge.h" #import "components/signin/public/identity_manager/objc/identity_manager_observer_bridge.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
...@@ -21,6 +23,7 @@ ...@@ -21,6 +23,7 @@
#import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h" #import "ios/chrome/browser/ui/authentication/resized_avatar_cache.h"
#import "ios/chrome/browser/ui/settings/cells/account_sign_in_item.h" #import "ios/chrome/browser/ui/settings/cells/account_sign_in_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_image_detail_text_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h" #import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_command_handler.h" #import "ios/chrome/browser/ui/settings/google_services/google_services_settings_command_handler.h"
#import "ios/chrome/browser/ui/settings/sync/utils/sync_util.h" #import "ios/chrome/browser/ui/settings/sync/utils/sync_util.h"
...@@ -80,6 +83,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -80,6 +83,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
AutocompleteSearchesAndURLsItemType, AutocompleteSearchesAndURLsItemType,
ImproveChromeItemType, ImproveChromeItemType,
BetterSearchAndBrowsingItemType, BetterSearchAndBrowsingItemType,
ItemTypePasswordLeakCheckSwitch,
}; };
// Enterprise icon. // Enterprise icon.
...@@ -143,6 +147,15 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -143,6 +147,15 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// Preference value for the "Make searches and browsing better" feature. // Preference value for the "Make searches and browsing better" feature.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
PrefBackedBoolean* anonymizedDataCollectionPreference; PrefBackedBoolean* anonymizedDataCollectionPreference;
// The observable boolean that binds to the password leak check settings
// state.
@property(nonatomic, strong, readonly)
PrefBackedBoolean* passwordLeakCheckEnabled;
// The item related to the switch for the automatic password leak detection
// setting.
@property(nonatomic, strong, null_resettable)
SettingsSwitchItem* passwordLeakCheckItem;
// All the items for the non-personalized section. // All the items for the non-personalized section.
@property(nonatomic, strong, readonly) ItemArray nonPersonalizedItems; @property(nonatomic, strong, readonly) ItemArray nonPersonalizedItems;
...@@ -178,6 +191,14 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -178,6 +191,14 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
initWithPrefService:localPrefService initWithPrefService:localPrefService
prefName:prefs::kMetricsReportingWifiOnly]; prefName:prefs::kMetricsReportingWifiOnly];
} }
if (base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
_passwordLeakCheckEnabled = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:password_manager::prefs::
kPasswordLeakDetectionEnabled];
_passwordLeakCheckEnabled.observer = self;
}
_anonymizedDataCollectionPreference = [[PrefBackedBoolean alloc] _anonymizedDataCollectionPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService initWithPrefService:userPrefService
prefName:unified_consent::prefs:: prefName:unified_consent::prefs::
...@@ -484,8 +505,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -484,8 +505,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (void)updateNonPersonalizedSection { - (void)updateNonPersonalizedSection {
for (TableViewItem* item in self.nonPersonalizedItems) { for (TableViewItem* item in self.nonPersonalizedItems) {
ItemType type = static_cast<ItemType>(item.type); ItemType type = static_cast<ItemType>(item.type);
SyncSwitchItem* switchItem = SyncSwitchItem* switchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
base::mac::ObjCCastStrict<SyncSwitchItem>(item);
switch (type) { switch (type) {
case AutocompleteSearchesAndURLsItemType: case AutocompleteSearchesAndURLsItemType:
switchItem.on = self.autocompleteSearchPreference.value; switchItem.on = self.autocompleteSearchPreference.value;
...@@ -496,6 +516,11 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -496,6 +516,11 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case BetterSearchAndBrowsingItemType: case BetterSearchAndBrowsingItemType:
switchItem.on = self.anonymizedDataCollectionPreference.value; switchItem.on = self.anonymizedDataCollectionPreference.value;
break; break;
case ItemTypePasswordLeakCheckSwitch:
DCHECK(base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection));
[self updateLeakCheckItem];
break;
case IdentityItemType: case IdentityItemType:
case ManageGoogleAccountItemType: case ManageGoogleAccountItemType:
case SignInItemType: case SignInItemType:
...@@ -562,14 +587,39 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -562,14 +587,39 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
dataType:0]; dataType:0];
betterSearchAndBrowsingItemType.accessibilityIdentifier = betterSearchAndBrowsingItemType.accessibilityIdentifier =
kBetterSearchAndBrowsingItemAccessibilityID; kBetterSearchAndBrowsingItemAccessibilityID;
_nonPersonalizedItems = @[ if (base::FeatureList::IsEnabled(
autocompleteSearchesAndURLsItem, improveChromeItem, password_manager::features::kLeakDetection)) {
betterSearchAndBrowsingItemType _nonPersonalizedItems = @[
]; autocompleteSearchesAndURLsItem, self.passwordLeakCheckItem,
improveChromeItem, betterSearchAndBrowsingItemType
];
} else {
_nonPersonalizedItems = @[
autocompleteSearchesAndURLsItem, improveChromeItem,
betterSearchAndBrowsingItemType
];
}
} }
return _nonPersonalizedItems; return _nonPersonalizedItems;
} }
- (SettingsSwitchItem*)passwordLeakCheckItem {
DCHECK(
base::FeatureList::IsEnabled(password_manager::features::kLeakDetection));
if (!_passwordLeakCheckItem) {
SettingsSwitchItem* passwordLeakCheckItem = [[SettingsSwitchItem alloc]
initWithType:ItemTypePasswordLeakCheckSwitch];
passwordLeakCheckItem.text =
l10n_util::GetNSString(IDS_IOS_LEAK_CHECK_SWITCH);
passwordLeakCheckItem.on = [self passwordLeakCheckItemOnState];
passwordLeakCheckItem.accessibilityIdentifier =
@"passwordLeakCheckItem_switch";
passwordLeakCheckItem.enabled = self.isAuthenticated;
_passwordLeakCheckItem = passwordLeakCheckItem;
}
return _passwordLeakCheckItem;
}
#pragma mark - Private #pragma mark - Private
// Creates a SyncSwitchItem instance. // Creates a SyncSwitchItem instance.
...@@ -627,6 +677,42 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -627,6 +677,42 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
return item; return item;
} }
// Returns a boolean indicating if the switch should appear as "On" or "Off"
// based on the sync preference and the sign in status.
- (BOOL)passwordLeakCheckItemOnState {
return [self.passwordLeakCheckEnabled value] && self.isAuthenticated;
}
// Updates the detail text and on state of the leak check item based on the
// state.
- (void)updateLeakCheckItem {
if (!base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
return;
}
self.passwordLeakCheckItem.enabled = self.isAuthenticated;
self.passwordLeakCheckItem.on = [self passwordLeakCheckItemOnState];
if (!self.isAuthenticated && self.passwordLeakCheckEnabled.value) {
// If the user is signed out and the sync preference is enabled, this
// informs that it will be turned on on sign in.
self.passwordLeakCheckItem.detailText =
l10n_util::GetNSString(IDS_IOS_LEAK_CHECK_SIGNED_OUT_ENABLED_DESC);
return;
}
self.passwordLeakCheckItem.detailText = nil;
}
// Updates leak item and asks the consumer to reload it.
- (void)updateLeakCheckItemAndReload {
if (base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
[self updateLeakCheckItem];
[self.consumer reloadItem:self.passwordLeakCheckItem];
}
}
#pragma mark - GoogleServicesSettingsViewControllerModelDelegate #pragma mark - GoogleServicesSettingsViewControllerModelDelegate
- (void)googleServicesSettingsViewControllerLoadModel: - (void)googleServicesSettingsViewControllerLoadModel:
...@@ -644,9 +730,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -644,9 +730,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
#pragma mark - GoogleServicesSettingsServiceDelegate #pragma mark - GoogleServicesSettingsServiceDelegate
- (void)toggleSwitchItem:(SyncSwitchItem*)switchItem withValue:(BOOL)value { - (void)toggleSwitchItem:(TableViewItem*)item withValue:(BOOL)value {
ItemType type = static_cast<ItemType>(switchItem.type); ItemType type = static_cast<ItemType>(item.type);
switchItem.on = value; SyncSwitchItem* syncSwitchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
syncSwitchItem.on = value;
switch (type) { switch (type) {
case AutocompleteSearchesAndURLsItemType: case AutocompleteSearchesAndURLsItemType:
self.autocompleteSearchPreference.value = value; self.autocompleteSearchPreference.value = value;
...@@ -678,6 +765,12 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -678,6 +765,12 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
syncer::SyncFirstSetupCompleteSource::BASIC_FLOW); syncer::SyncFirstSetupCompleteSource::BASIC_FLOW);
} }
break; break;
case ItemTypePasswordLeakCheckSwitch:
// Update the pref.
self.passwordLeakCheckEnabled.value = value;
// Update the item.
[self updateLeakCheckItem];
break;
case IdentityItemType: case IdentityItemType:
case ManageGoogleAccountItemType: case ManageGoogleAccountItemType:
case SignInItemType: case SignInItemType:
...@@ -719,6 +812,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -719,6 +812,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case SyncDisabledByAdministratorErrorItemType: case SyncDisabledByAdministratorErrorItemType:
case SyncSettingsNotCofirmedErrorItemType: case SyncSettingsNotCofirmedErrorItemType:
case AutocompleteSearchesAndURLsItemType: case AutocompleteSearchesAndURLsItemType:
case ItemTypePasswordLeakCheckSwitch:
case ImproveChromeItemType: case ImproveChromeItemType:
case BetterSearchAndBrowsingItemType: case BetterSearchAndBrowsingItemType:
case SyncChromeDataItemType: case SyncChromeDataItemType:
...@@ -740,12 +834,14 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -740,12 +834,14 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (void)onPrimaryAccountSet:(const CoreAccountInfo&)primaryAccountInfo { - (void)onPrimaryAccountSet:(const CoreAccountInfo&)primaryAccountInfo {
[self updateSyncSection:YES]; [self updateSyncSection:YES];
[self updateIdentitySectionAndNotifyConsumer]; [self updateIdentitySectionAndNotifyConsumer];
[self updateLeakCheckItemAndReload];
} }
- (void)onPrimaryAccountCleared: - (void)onPrimaryAccountCleared:
(const CoreAccountInfo&)previousPrimaryAccountInfo { (const CoreAccountInfo&)previousPrimaryAccountInfo {
[self updateSyncSection:YES]; [self updateSyncSection:YES];
[self updateIdentitySectionAndNotifyConsumer]; [self updateIdentitySectionAndNotifyConsumer];
[self updateLeakCheckItemAndReload];
} }
#pragma mark - BooleanObserver #pragma mark - BooleanObserver
...@@ -763,6 +859,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -763,6 +859,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (void)profileUpdate:(ChromeIdentity*)identity { - (void)profileUpdate:(ChromeIdentity*)identity {
[self updateIdentitySectionAndNotifyConsumer]; [self updateIdentitySectionAndNotifyConsumer];
[self updateLeakCheckItemAndReload];
} }
- (void)chromeIdentityServiceWillBeDestroyed { - (void)chromeIdentityServiceWillBeDestroyed {
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_SERVICE_DELEGATE_H_ #ifndef IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_SERVICE_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_SERVICE_DELEGATE_H_ #define IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_SERVICE_DELEGATE_H_
@class SyncSwitchItem;
@class TableViewItem; @class TableViewItem;
// Protocol to handle user actions from the Google services settings view. // Protocol to handle user actions from the Google services settings view.
@protocol GoogleServicesSettingsServiceDelegate <NSObject> @protocol GoogleServicesSettingsServiceDelegate <NSObject>
// Called when the UISwitch from the SyncSwitchItem is toggled. // Called when the UISwitch from a TableViewItem is toggled.
- (void)toggleSwitchItem:(SyncSwitchItem*)switchItem withValue:(BOOL)value; - (void)toggleSwitchItem:(TableViewItem*)switchItem withValue:(BOOL)value;
// Called when cell is tapped. // Called when cell is tapped.
- (void)didSelectItem:(TableViewItem*)item; - (void)didSelectItem:(TableViewItem*)item;
......
...@@ -35,9 +35,8 @@ NSString* const kGoogleServicesSettingsViewIdentifier = ...@@ -35,9 +35,8 @@ NSString* const kGoogleServicesSettingsViewIdentifier =
NSIndexPath* indexPath = NSIndexPath* indexPath =
[self.tableViewModel indexPathForItemType:sender.tag]; [self.tableViewModel indexPathForItemType:sender.tag];
DCHECK(indexPath); DCHECK(indexPath);
SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>( TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
[self.tableViewModel itemAtIndexPath:indexPath]); [self.serviceDelegate toggleSwitchItem:item withValue:sender.isOn];
[self.serviceDelegate toggleSwitchItem:syncSwitchItem withValue:sender.isOn];
} }
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "components/autofill/core/common/autofill_prefs.h" #include "components/autofill/core/common/autofill_prefs.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
...@@ -398,14 +399,15 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -398,14 +399,15 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
#pragma mark - ManageSyncSettingsServiceDelegate #pragma mark - ManageSyncSettingsServiceDelegate
- (void)toggleSwitchItem:(SyncSwitchItem*)switchItem withValue:(BOOL)value { - (void)toggleSwitchItem:(TableViewItem*)item withValue:(BOOL)value {
{ {
// The notifications should be ignored to get smooth switch animations. // The notifications should be ignored to get smooth switch animations.
// Notifications are sent by SyncObserverModelBridge while changing // Notifications are sent by SyncObserverModelBridge while changing
// settings. // settings.
base::AutoReset<BOOL> autoReset(&_ignoreSyncStateChanges, YES); base::AutoReset<BOOL> autoReset(&_ignoreSyncStateChanges, YES);
switchItem.on = value; SyncSwitchItem* syncSwitchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
ItemType itemType = static_cast<ItemType>(switchItem.type); syncSwitchItem.on = value;
ItemType itemType = static_cast<ItemType>(item.type);
switch (itemType) { switch (itemType) {
case SyncEverythingItemType: case SyncEverythingItemType:
self.syncSetupService->SetSyncingAllDataTypes(value); self.syncSetupService->SetSyncingAllDataTypes(value);
...@@ -423,9 +425,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -423,9 +425,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case PasswordsDataTypeItemType: case PasswordsDataTypeItemType:
case ReadingListDataTypeItemType: case ReadingListDataTypeItemType:
case SettingsDataTypeItemType: { case SettingsDataTypeItemType: {
DCHECK(syncSwitchItem);
SyncSetupService::SyncableDatatype dataType = SyncSetupService::SyncableDatatype dataType =
static_cast<SyncSetupService::SyncableDatatype>( static_cast<SyncSetupService::SyncableDatatype>(
switchItem.dataType); syncSwitchItem.dataType);
syncer::ModelType modelType = syncer::ModelType modelType =
self.syncSetupService->GetModelType(dataType); self.syncSetupService->GetModelType(dataType);
self.syncSetupService->SetDataTypeEnabled(modelType, value); self.syncSetupService->SetDataTypeEnabled(modelType, value);
......
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