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

[iOS] Adding user event data type into SyncSetupService

Adding user event data type to sync on iOS. Available only if unified
consent is enabled.

Bug: 827072
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ib8c01a40dd10e2aa61df65cad9ddfa6bb8881774
Reviewed-on: https://chromium-review.googlesource.com/1150140
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578344}
parent f12d4ba6
...@@ -72,6 +72,7 @@ source_set("sync") { ...@@ -72,6 +72,7 @@ source_set("sync") {
"//ios/chrome/browser/sync/sessions", "//ios/chrome/browser/sync/sessions",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/undo", "//ios/chrome/browser/undo",
"//ios/chrome/browser/unified_consent:feature",
"//ios/chrome/common", "//ios/chrome/common",
"//ios/web", "//ios/web",
"//net", "//net",
......
...@@ -15,15 +15,16 @@ ...@@ -15,15 +15,16 @@
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/unified_consent/feature.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
namespace { namespace {
// The set of user-selectable datatypes. This must be in the same order as // The set of user-selectable datatypes. This must be in the same order as
// |SyncSetupService::SyncableDatatype|. // |SyncSetupService::SyncableDatatype|.
syncer::ModelType kDataTypes[] = { syncer::ModelType kDataTypes[] = {
syncer::BOOKMARKS, syncer::TYPED_URLS, syncer::PASSWORDS, syncer::BOOKMARKS, syncer::TYPED_URLS, syncer::PASSWORDS,
syncer::PROXY_TABS, syncer::AUTOFILL, syncer::PREFERENCES, syncer::PROXY_TABS, syncer::AUTOFILL, syncer::PREFERENCES,
syncer::READING_LIST, syncer::READING_LIST, syncer::USER_EVENTS,
}; };
} // namespace } // namespace
...@@ -33,6 +34,8 @@ SyncSetupService::SyncSetupService(syncer::SyncService* sync_service, ...@@ -33,6 +34,8 @@ SyncSetupService::SyncSetupService(syncer::SyncService* sync_service,
DCHECK(sync_service_); DCHECK(sync_service_);
DCHECK(prefs_); DCHECK(prefs_);
for (unsigned int i = 0; i < arraysize(kDataTypes); ++i) { for (unsigned int i = 0; i < arraysize(kDataTypes); ++i) {
if (kDataTypes[i] == syncer::USER_EVENTS && !IsUnifiedConsentEnabled())
continue;
user_selectable_types_.Put(kDataTypes[i]); user_selectable_types_.Put(kDataTypes[i]);
} }
} }
......
...@@ -45,6 +45,7 @@ class SyncSetupService : public KeyedService { ...@@ -45,6 +45,7 @@ class SyncSetupService : public KeyedService {
kSyncAutofill, kSyncAutofill,
kSyncPreferences, kSyncPreferences,
kSyncReadingList, kSyncReadingList,
kSyncUserEvent,
kNumberOfSyncableDatatypes kNumberOfSyncableDatatypes
}; };
......
...@@ -59,6 +59,7 @@ source_set("authentication") { ...@@ -59,6 +59,7 @@ source_set("authentication") {
"//ios/chrome/browser/ui/signin_interaction/public", "//ios/chrome/browser/ui/signin_interaction/public",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/unified_consent", "//ios/chrome/browser/unified_consent",
"//ios/chrome/browser/unified_consent:feature",
"//ios/chrome/common", "//ios/chrome/common",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/images", "//ios/public/provider/chrome/browser/images",
......
...@@ -188,6 +188,7 @@ source_set("settings") { ...@@ -188,6 +188,7 @@ source_set("settings") {
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/ui/table_view/cells/resources:table_view_cell_check_mark", "//ios/chrome/browser/ui/table_view/cells/resources:table_view_cell_check_mark",
"//ios/chrome/browser/unified_consent", "//ios/chrome/browser/unified_consent",
"//ios/chrome/browser/unified_consent:feature",
"//ios/chrome/browser/voice", "//ios/chrome/browser/voice",
"//ios/chrome/browser/web:web", "//ios/chrome/browser/web:web",
"//ios/chrome/common", "//ios/chrome/common",
...@@ -334,6 +335,7 @@ source_set("unit_tests") { ...@@ -334,6 +335,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/ui/icons", "//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/settings/cells", "//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/settings/sync_utils", "//ios/chrome/browser/ui/settings/sync_utils",
"//ios/chrome/browser/unified_consent:feature",
"//ios/chrome/browser/voice", "//ios/chrome/browser/voice",
"//ios/chrome/browser/web", "//ios/chrome/browser/web",
"//ios/chrome/browser/web:test_support", "//ios/chrome/browser/web:test_support",
......
...@@ -332,6 +332,10 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -332,6 +332,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) { for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; ++i) {
SyncSetupService::SyncableDatatype dataType = SyncSetupService::SyncableDatatype dataType =
static_cast<SyncSetupService::SyncableDatatype>(i); static_cast<SyncSetupService::SyncableDatatype>(i);
if (dataType == SyncSetupService::kSyncUserEvent) {
// This data type should only be used with the unified consent UI.
continue;
}
[model addItem:[self switchItemForDataType:dataType] [model addItem:[self switchItemForDataType:dataType]
toSectionWithIdentifier:SectionIdentifierSyncServices]; toSectionWithIdentifier:SectionIdentifierSyncServices];
} }
...@@ -829,16 +833,21 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -829,16 +833,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Syncable data types cells // Syncable data types cells
NSMutableArray* switchsToReconfigure = [[NSMutableArray alloc] init]; NSMutableArray* switchsToReconfigure = [[NSMutableArray alloc] init];
for (NSUInteger index = 0; for (NSInteger index = 0;
index < SyncSetupService::kNumberOfSyncableDatatypes; ++index) { index < SyncSetupService::kNumberOfSyncableDatatypes; ++index) {
SyncSetupService::SyncableDatatype dataType =
static_cast<SyncSetupService::SyncableDatatype>(index);
if (dataType == SyncSetupService::kSyncUserEvent) {
// This data type should only be used with the unified consent UI.
continue;
}
NSIndexPath* indexPath = [self.collectionViewModel NSIndexPath* indexPath = [self.collectionViewModel
indexPathForItemType:ItemTypeSyncableDataType indexPathForItemType:ItemTypeSyncableDataType
sectionIdentifier:SectionIdentifierSyncServices sectionIdentifier:SectionIdentifierSyncServices
atIndex:index]; atIndex:index];
SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>( SyncSwitchItem* syncSwitchItem = base::mac::ObjCCastStrict<SyncSwitchItem>(
[self.collectionViewModel itemAtIndexPath:indexPath]); [self.collectionViewModel itemAtIndexPath:indexPath]);
SyncSetupService::SyncableDatatype dataType = DCHECK_EQ(index, syncSwitchItem.dataType);
(SyncSetupService::SyncableDatatype)syncSwitchItem.dataType;
syncer::ModelType modelType = _syncSetupService->GetModelType(dataType); syncer::ModelType modelType = _syncSetupService->GetModelType(dataType);
syncSwitchItem.on = _syncSetupService->IsDataTypePreferred(modelType); syncSwitchItem.on = _syncSetupService->IsDataTypePreferred(modelType);
syncSwitchItem.enabled = [self shouldSyncableItemsBeEnabled]; syncSwitchItem.enabled = [self shouldSyncableItemsBeEnabled];
...@@ -967,6 +976,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -967,6 +976,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
return IDS_SYNC_DATATYPE_PREFERENCES; return IDS_SYNC_DATATYPE_PREFERENCES;
case SyncSetupService::kSyncReadingList: case SyncSetupService::kSyncReadingList:
return IDS_SYNC_DATATYPE_READING_LIST; return IDS_SYNC_DATATYPE_READING_LIST;
case SyncSetupService::kSyncUserEvent:
// Not supported for the code before the unified consent.
case SyncSetupService::kNumberOfSyncableDatatypes: case SyncSetupService::kNumberOfSyncableDatatypes:
NOTREACHED(); NOTREACHED();
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#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/cells/text_and_error_item.h" #import "ios/chrome/browser/ui/settings/cells/text_and_error_item.h"
#import "ios/chrome/browser/ui/settings/sync_utils/sync_util.h" #import "ios/chrome/browser/ui/settings/sync_utils/sync_util.h"
#include "ios/chrome/browser/unified_consent/feature.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ios/web/public/test/test_web_thread_bundle.h" #include "ios/web/public/test/test_web_thread_bundle.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
...@@ -240,9 +241,11 @@ TEST_F(SyncSettingsCollectionViewControllerTest, TestModel) { ...@@ -240,9 +241,11 @@ TEST_F(SyncSettingsCollectionViewControllerTest, TestModel) {
EXPECT_EQ(3, NumberOfSections()); EXPECT_EQ(3, NumberOfSections());
EXPECT_EQ(1, NumberOfItemsInSection(0)); EXPECT_EQ(1, NumberOfItemsInSection(0));
// One extra item for "Sync Everything" and one for Autofill wallet import. // There is one item per data type, except for unified consent that is
int expected_number_of_items = // unsupported by the old UI. In addition, there are two extra items, one
SyncSetupService::kNumberOfSyncableDatatypes + 2; // for "Sync Everything" and another for Autofill wallet import.
constexpr int expected_number_of_items =
SyncSetupService::kNumberOfSyncableDatatypes - 1 + 2;
EXPECT_EQ(expected_number_of_items, NumberOfItemsInSection(1)); EXPECT_EQ(expected_number_of_items, NumberOfItemsInSection(1));
EXPECT_EQ(2, NumberOfItemsInSection(2)); EXPECT_EQ(2, NumberOfItemsInSection(2));
...@@ -263,6 +266,10 @@ TEST_F(SyncSettingsCollectionViewControllerTest, TestModel) { ...@@ -263,6 +266,10 @@ TEST_F(SyncSettingsCollectionViewControllerTest, TestModel) {
for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; i++) { for (int i = 0; i < SyncSetupService::kNumberOfSyncableDatatypes; i++) {
SyncSetupService::SyncableDatatype dataType = SyncSetupService::SyncableDatatype dataType =
static_cast<SyncSetupService::SyncableDatatype>(i); static_cast<SyncSetupService::SyncableDatatype>(i);
if (dataType == SyncSetupService::kSyncUserEvent) {
// Old UI without unified consent doesn't support user event data type.
continue;
}
SyncSwitchItem* syncDataTypeItem = GetCollectionViewItem(1, item++); SyncSwitchItem* syncDataTypeItem = GetCollectionViewItem(1, item++);
EXPECT_NSEQ(syncDataTypeItem.text, EXPECT_NSEQ(syncDataTypeItem.text,
l10n_util::GetNSString( l10n_util::GetNSString(
......
...@@ -22,6 +22,7 @@ source_set("signin_interaction") { ...@@ -22,6 +22,7 @@ source_set("signin_interaction") {
"//ios/chrome/browser/ui/authentication", "//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/unified_consent", "//ios/chrome/browser/unified_consent",
"//ios/chrome/browser/unified_consent:feature",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/signin", "//ios/public/provider/chrome/browser/signin",
] ]
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
source_set("unified_consent") { source_set("unified_consent") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"feature.cc",
"feature.h",
"unified_consent_service_client_impl.cc", "unified_consent_service_client_impl.cc",
"unified_consent_service_client_impl.h", "unified_consent_service_client_impl.h",
"unified_consent_service_factory.cc", "unified_consent_service_factory.cc",
"unified_consent_service_factory.h", "unified_consent_service_factory.h",
] ]
deps = [ deps = [
":feature",
"//components/browser_sync", "//components/browser_sync",
"//components/keyed_service/ios", "//components/keyed_service/ios",
"//components/metrics", "//components/metrics",
...@@ -25,3 +24,14 @@ source_set("unified_consent") { ...@@ -25,3 +24,14 @@ source_set("unified_consent") {
"//ios/chrome/browser/sync", "//ios/chrome/browser/sync",
] ]
} }
source_set("feature") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"feature.cc",
"feature.h",
]
deps = [
"//components/unified_consent",
]
}
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