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") {
"//components/browser_sync",
"//components/google/core/common",
"//components/metrics",
"//components/password_manager/core/common",
"//components/prefs",
"//components/signin/public/identity_manager",
"//components/signin/public/identity_manager/objc",
......
......@@ -7,6 +7,8 @@
#include "base/auto_reset.h"
#include "base/mac/foundation_util.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"
#import "components/signin/public/identity_manager/objc/identity_manager_observer_bridge.h"
#include "components/sync/driver/sync_service.h"
......@@ -21,6 +23,7 @@
#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/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/google_services/google_services_settings_command_handler.h"
#import "ios/chrome/browser/ui/settings/sync/utils/sync_util.h"
......@@ -80,6 +83,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
AutocompleteSearchesAndURLsItemType,
ImproveChromeItemType,
BetterSearchAndBrowsingItemType,
ItemTypePasswordLeakCheckSwitch,
};
// Enterprise icon.
......@@ -143,6 +147,15 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// Preference value for the "Make searches and browsing better" feature.
@property(nonatomic, strong, readonly)
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.
@property(nonatomic, strong, readonly) ItemArray nonPersonalizedItems;
......@@ -178,6 +191,14 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
initWithPrefService:localPrefService
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]
initWithPrefService:userPrefService
prefName:unified_consent::prefs::
......@@ -484,8 +505,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (void)updateNonPersonalizedSection {
for (TableViewItem* item in self.nonPersonalizedItems) {
ItemType type = static_cast<ItemType>(item.type);
SyncSwitchItem* switchItem =
base::mac::ObjCCastStrict<SyncSwitchItem>(item);
SyncSwitchItem* switchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
switch (type) {
case AutocompleteSearchesAndURLsItemType:
switchItem.on = self.autocompleteSearchPreference.value;
......@@ -496,6 +516,11 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case BetterSearchAndBrowsingItemType:
switchItem.on = self.anonymizedDataCollectionPreference.value;
break;
case ItemTypePasswordLeakCheckSwitch:
DCHECK(base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection));
[self updateLeakCheckItem];
break;
case IdentityItemType:
case ManageGoogleAccountItemType:
case SignInItemType:
......@@ -562,14 +587,39 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
dataType:0];
betterSearchAndBrowsingItemType.accessibilityIdentifier =
kBetterSearchAndBrowsingItemAccessibilityID;
_nonPersonalizedItems = @[
autocompleteSearchesAndURLsItem, improveChromeItem,
betterSearchAndBrowsingItemType
];
if (base::FeatureList::IsEnabled(
password_manager::features::kLeakDetection)) {
_nonPersonalizedItems = @[
autocompleteSearchesAndURLsItem, self.passwordLeakCheckItem,
improveChromeItem, betterSearchAndBrowsingItemType
];
} else {
_nonPersonalizedItems = @[
autocompleteSearchesAndURLsItem, improveChromeItem,
betterSearchAndBrowsingItemType
];
}
}
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
// Creates a SyncSwitchItem instance.
......@@ -627,6 +677,42 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
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
- (void)googleServicesSettingsViewControllerLoadModel:
......@@ -644,9 +730,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
#pragma mark - GoogleServicesSettingsServiceDelegate
- (void)toggleSwitchItem:(SyncSwitchItem*)switchItem withValue:(BOOL)value {
ItemType type = static_cast<ItemType>(switchItem.type);
switchItem.on = value;
- (void)toggleSwitchItem:(TableViewItem*)item withValue:(BOOL)value {
ItemType type = static_cast<ItemType>(item.type);
SyncSwitchItem* syncSwitchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
syncSwitchItem.on = value;
switch (type) {
case AutocompleteSearchesAndURLsItemType:
self.autocompleteSearchPreference.value = value;
......@@ -678,6 +765,12 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
syncer::SyncFirstSetupCompleteSource::BASIC_FLOW);
}
break;
case ItemTypePasswordLeakCheckSwitch:
// Update the pref.
self.passwordLeakCheckEnabled.value = value;
// Update the item.
[self updateLeakCheckItem];
break;
case IdentityItemType:
case ManageGoogleAccountItemType:
case SignInItemType:
......@@ -719,6 +812,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case SyncDisabledByAdministratorErrorItemType:
case SyncSettingsNotCofirmedErrorItemType:
case AutocompleteSearchesAndURLsItemType:
case ItemTypePasswordLeakCheckSwitch:
case ImproveChromeItemType:
case BetterSearchAndBrowsingItemType:
case SyncChromeDataItemType:
......@@ -740,12 +834,14 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (void)onPrimaryAccountSet:(const CoreAccountInfo&)primaryAccountInfo {
[self updateSyncSection:YES];
[self updateIdentitySectionAndNotifyConsumer];
[self updateLeakCheckItemAndReload];
}
- (void)onPrimaryAccountCleared:
(const CoreAccountInfo&)previousPrimaryAccountInfo {
[self updateSyncSection:YES];
[self updateIdentitySectionAndNotifyConsumer];
[self updateLeakCheckItemAndReload];
}
#pragma mark - BooleanObserver
......@@ -763,6 +859,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (void)profileUpdate:(ChromeIdentity*)identity {
[self updateIdentitySectionAndNotifyConsumer];
[self updateLeakCheckItemAndReload];
}
- (void)chromeIdentityServiceWillBeDestroyed {
......
......@@ -5,14 +5,13 @@
#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_
@class SyncSwitchItem;
@class TableViewItem;
// Protocol to handle user actions from the Google services settings view.
@protocol GoogleServicesSettingsServiceDelegate <NSObject>
// Called when the UISwitch from the SyncSwitchItem is toggled.
- (void)toggleSwitchItem:(SyncSwitchItem*)switchItem withValue:(BOOL)value;
// Called when the UISwitch from a TableViewItem is toggled.
- (void)toggleSwitchItem:(TableViewItem*)switchItem withValue:(BOOL)value;
// Called when cell is tapped.
- (void)didSelectItem:(TableViewItem*)item;
......
......@@ -35,9 +35,8 @@ NSString* const kGoogleServicesSettingsViewIdentifier =
NSIndexPath* indexPath =
[self.tableViewModel indexPathForItemType:sender.tag];
DCHECK(indexPath);
SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>(
[self.tableViewModel itemAtIndexPath:indexPath]);
[self.serviceDelegate toggleSwitchItem:syncSwitchItem withValue:sender.isOn];
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
[self.serviceDelegate toggleSwitchItem:item withValue:sender.isOn];
}
#pragma mark - UITableViewDataSource
......
......@@ -6,6 +6,7 @@
#include "base/auto_reset.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync/driver/sync_service.h"
......@@ -398,14 +399,15 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
#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.
// Notifications are sent by SyncObserverModelBridge while changing
// settings.
base::AutoReset<BOOL> autoReset(&_ignoreSyncStateChanges, YES);
switchItem.on = value;
ItemType itemType = static_cast<ItemType>(switchItem.type);
SyncSwitchItem* syncSwitchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
syncSwitchItem.on = value;
ItemType itemType = static_cast<ItemType>(item.type);
switch (itemType) {
case SyncEverythingItemType:
self.syncSetupService->SetSyncingAllDataTypes(value);
......@@ -423,9 +425,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case PasswordsDataTypeItemType:
case ReadingListDataTypeItemType:
case SettingsDataTypeItemType: {
DCHECK(syncSwitchItem);
SyncSetupService::SyncableDatatype dataType =
static_cast<SyncSetupService::SyncableDatatype>(
switchItem.dataType);
syncSwitchItem.dataType);
syncer::ModelType modelType =
self.syncSetupService->GetModelType(dataType);
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