Commit e63dc8bc authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

[unified-consent] Accept null sync service for UrlKeyedDataCollectionConsentHelper

This CL accepts a null sync service for the creation of
UrlKeyedDataCollectionConsentHelper objects. If such an object is backed by
the sync service, then a null sync service is treated like the consent
not being given for URL-keyed data collection.

Bug: 857589
Change-Id: I915963eeaba39539dc0ae9e9b0bc6d46d3b3e842
Reviewed-on: https://chromium-review.googlesource.com/1148323Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577491}
parent c5b409c2
......@@ -87,8 +87,10 @@ SyncBasedUrlKeyedDataCollectionConsentHelper::
sync_data_type_(sync_data_type),
sync_data_type_upload_state_(
syncer::GetUploadToGoogleState(sync_service_, sync_data_type_)) {
DCHECK(sync_service_);
sync_service_->AddObserver(this);
if (sync_service_)
sync_service_->AddObserver(this);
else
DCHECK_EQ(syncer::UploadState::NOT_ACTIVE, sync_data_type_upload_state_);
}
SyncBasedUrlKeyedDataCollectionConsentHelper::
......
......@@ -136,6 +136,16 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest,
helper->RemoveObserver(this);
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
AnonymizedDataCollection_UnifiedConsentDisabled_NullSyncService) {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewAnonymizedDataCollectionConsentHelper(
false /* is_unified_consent_enabled */, &pref_service_,
nullptr /* sync_service */);
EXPECT_FALSE(helper->IsEnabled());
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
PersonalizeddDataCollection_UnifiedConsentEnabled) {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
......@@ -171,5 +181,25 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest,
helper->RemoveObserver(this);
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
PersonalizedDataCollection_NullSyncService) {
{
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewPersonalizedDataCollectionConsentHelper(
false /* is_unified_consent_enabled */,
nullptr /* sync_service */);
EXPECT_FALSE(helper->IsEnabled());
}
{
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewPersonalizedDataCollectionConsentHelper(
true /* is_unified_consent_enabled */,
nullptr /* sync_service */);
EXPECT_FALSE(helper->IsEnabled());
}
}
} // namespace
} // namespace 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