Commit 6ed9cbbe authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Revert "[unified-consent] Add shutdown information for the UrlKeyedDataCollectionConsentHelper."

This reverts commit bfc33b7c.

Reason for revert: The work for UKM is done in a separate CL, so this is no longer needed.

Original change's description:
> [unified-consent] Add shutdown information for the UrlKeyedDataCollectionConsentHelper.
> 
> This CL adds methods that handle the shutdown state for the
> UrlKeyedDataCollectionConsentHelper. This is set when the dependent sync
> service is shut down.
> 
> Bug: 867388
> 
> Change-Id: Id6f948bc0aa1a55ec2943590a5f77cd179b65e3f
> Reviewed-on: https://chromium-review.googlesource.com/1148564
> Reviewed-by: Brian White <bcwhite@chromium.org>
> Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#578242}

TBR=msarda@chromium.org,bcwhite@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 867388
Change-Id: If3978f977afcb9ea1997bdde1b7220f56a271bbb
Reviewed-on: https://chromium-review.googlesource.com/1152847Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578598}
parent 5ba3af4e
...@@ -26,7 +26,6 @@ class PrefBasedUrlKeyedDataCollectionConsentHelper ...@@ -26,7 +26,6 @@ class PrefBasedUrlKeyedDataCollectionConsentHelper
// UrlKeyedDataCollectionConsentHelper: // UrlKeyedDataCollectionConsentHelper:
bool IsEnabled() override; bool IsEnabled() override;
bool IsShutDown() override;
private: private:
void OnPrefChanged(); void OnPrefChanged();
...@@ -47,7 +46,6 @@ class SyncBasedUrlKeyedDataCollectionConsentHelper ...@@ -47,7 +46,6 @@ class SyncBasedUrlKeyedDataCollectionConsentHelper
// UrlKeyedDataCollectionConsentHelper: // UrlKeyedDataCollectionConsentHelper:
bool IsEnabled() override; bool IsEnabled() override;
bool IsShutDown() override;
// syncer::SyncServiceObserver: // syncer::SyncServiceObserver:
void OnStateChanged(syncer::SyncService* sync) override; void OnStateChanged(syncer::SyncService* sync) override;
...@@ -77,10 +75,6 @@ bool PrefBasedUrlKeyedDataCollectionConsentHelper::IsEnabled() { ...@@ -77,10 +75,6 @@ bool PrefBasedUrlKeyedDataCollectionConsentHelper::IsEnabled() {
prefs::kUrlKeyedAnonymizedDataCollectionEnabled); prefs::kUrlKeyedAnonymizedDataCollectionEnabled);
} }
bool PrefBasedUrlKeyedDataCollectionConsentHelper::IsShutDown() {
return false;
}
void PrefBasedUrlKeyedDataCollectionConsentHelper::OnPrefChanged() { void PrefBasedUrlKeyedDataCollectionConsentHelper::OnPrefChanged() {
FireOnStateChanged(); FireOnStateChanged();
} }
...@@ -109,10 +103,6 @@ bool SyncBasedUrlKeyedDataCollectionConsentHelper::IsEnabled() { ...@@ -109,10 +103,6 @@ bool SyncBasedUrlKeyedDataCollectionConsentHelper::IsEnabled() {
return sync_data_type_upload_state_ == syncer::UploadState::ACTIVE; return sync_data_type_upload_state_ == syncer::UploadState::ACTIVE;
} }
bool SyncBasedUrlKeyedDataCollectionConsentHelper::IsShutDown() {
return !sync_service_;
}
void SyncBasedUrlKeyedDataCollectionConsentHelper::OnStateChanged( void SyncBasedUrlKeyedDataCollectionConsentHelper::OnStateChanged(
syncer::SyncService* sync_service) { syncer::SyncService* sync_service) {
DCHECK_EQ(sync_service_, sync_service); DCHECK_EQ(sync_service_, sync_service);
...@@ -127,11 +117,8 @@ void SyncBasedUrlKeyedDataCollectionConsentHelper::OnStateChanged( ...@@ -127,11 +117,8 @@ void SyncBasedUrlKeyedDataCollectionConsentHelper::OnStateChanged(
void SyncBasedUrlKeyedDataCollectionConsentHelper::OnSyncShutdown( void SyncBasedUrlKeyedDataCollectionConsentHelper::OnSyncShutdown(
syncer::SyncService* sync_service) { syncer::SyncService* sync_service) {
DCHECK_EQ(sync_service_, sync_service); DCHECK_EQ(sync_service_, sync_service);
DCHECK_EQ(syncer::UploadState::NOT_ACTIVE, sync_data_type_upload_state_);
sync_service_->RemoveObserver(this); sync_service_->RemoveObserver(this);
sync_service_ = nullptr; sync_service_ = nullptr;
FireOnShutDown();
} }
} // namespace } // namespace
...@@ -180,9 +167,4 @@ void UrlKeyedDataCollectionConsentHelper::FireOnStateChanged() { ...@@ -180,9 +167,4 @@ void UrlKeyedDataCollectionConsentHelper::FireOnStateChanged() {
observer.OnUrlKeyedDataCollectionConsentStateChanged(this); observer.OnUrlKeyedDataCollectionConsentStateChanged(this);
} }
void UrlKeyedDataCollectionConsentHelper::FireOnShutDown() {
for (auto& observer : observer_list_)
observer.OnUrlKeyedDataCollectionConsentHelperShutDown(this);
}
} // namespace unified_consent } // namespace unified_consent
...@@ -25,12 +25,6 @@ class UrlKeyedDataCollectionConsentHelper { ...@@ -25,12 +25,6 @@ class UrlKeyedDataCollectionConsentHelper {
// Called when the state of the URL-keyed data collection changes. // Called when the state of the URL-keyed data collection changes.
virtual void OnUrlKeyedDataCollectionConsentStateChanged( virtual void OnUrlKeyedDataCollectionConsentStateChanged(
UrlKeyedDataCollectionConsentHelper* consent_helper) = 0; UrlKeyedDataCollectionConsentHelper* consent_helper) = 0;
// Called when |consent_helper| is shut down.
// See UrlKeyedDataCollectionConsentHelper::IsShutDown for more information
// on when a UrlKeyedDataCollectionConsentHelper is shut down.
virtual void OnUrlKeyedDataCollectionConsentHelperShutDown(
UrlKeyedDataCollectionConsentHelper* consent_helper){};
}; };
// Creates a new |UrlKeyedDataCollectionConsentHelper| instance that checks // Creates a new |UrlKeyedDataCollectionConsentHelper| instance that checks
...@@ -73,16 +67,6 @@ class UrlKeyedDataCollectionConsentHelper { ...@@ -73,16 +67,6 @@ class UrlKeyedDataCollectionConsentHelper {
// collection. // collection.
virtual bool IsEnabled() = 0; virtual bool IsEnabled() = 0;
// Returns true if this UrlKeyedDataCollectionConsentHelper was shut down.
// For sync backed implementations of consent helper, this matches the state
// when the underlying sync service was shut down.
//
// When |UrlKeyedDataCollectionConsentHelper| is shut down, it is guaranteed
// that calls to |IsEnabled| will always return false.
// |UrlKeyedDataCollectionConsentHelper| that are shut down will never again
// become active.
virtual bool IsShutDown() = 0;
// Methods to register or remove observers. // Methods to register or remove observers.
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
...@@ -93,9 +77,6 @@ class UrlKeyedDataCollectionConsentHelper { ...@@ -93,9 +77,6 @@ class UrlKeyedDataCollectionConsentHelper {
// Fires |OnUrlKeyedDataCollectionConsentStateChanged| on all the observers. // Fires |OnUrlKeyedDataCollectionConsentStateChanged| on all the observers.
void FireOnStateChanged(); void FireOnStateChanged();
// Fires |OnUrlKeyedDataCollectionConsentHelperShutDown| on all the observers.
void FireOnShutDown();
private: private:
base::ObserverList<Observer, true> observer_list_; base::ObserverList<Observer, true> observer_list_;
......
...@@ -28,10 +28,6 @@ class TestSyncService : public syncer::FakeSyncService { ...@@ -28,10 +28,6 @@ class TestSyncService : public syncer::FakeSyncService {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnStateChanged(this); observer.OnStateChanged(this);
} }
void FireOnSyncShutdownOnAllObservers() {
for (auto& observer : observers_)
observer.OnSyncShutdown(this);
}
// syncer::FakeSyncService: // syncer::FakeSyncService:
int GetDisableReasons() const override { return DISABLE_REASON_NONE; } int GetDisableReasons() const override { return DISABLE_REASON_NONE; }
...@@ -87,18 +83,12 @@ class UrlKeyedDataCollectionConsentHelperTest ...@@ -87,18 +83,12 @@ class UrlKeyedDataCollectionConsentHelperTest
void OnUrlKeyedDataCollectionConsentStateChanged( void OnUrlKeyedDataCollectionConsentStateChanged(
UrlKeyedDataCollectionConsentHelper* consent_helper) override { UrlKeyedDataCollectionConsentHelper* consent_helper) override {
state_changed_notifications_.push_back(consent_helper->IsEnabled()); state_changed_notifications.push_back(consent_helper->IsEnabled());
}
void OnUrlKeyedDataCollectionConsentHelperShutDown(
UrlKeyedDataCollectionConsentHelper* consent_helper) override {
shutdown_notifications_.push_back(consent_helper->IsShutDown());
} }
protected: protected:
sync_preferences::TestingPrefServiceSyncable pref_service_; sync_preferences::TestingPrefServiceSyncable pref_service_;
std::vector<bool> state_changed_notifications_; std::vector<bool> state_changed_notifications;
std::vector<bool> shutdown_notifications_;
TestSyncService sync_service_; TestSyncService sync_service_;
}; };
...@@ -110,20 +100,20 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest, ...@@ -110,20 +100,20 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest,
&sync_service_); &sync_service_);
helper->AddObserver(this); helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled()); EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications_.empty()); EXPECT_TRUE(state_changed_notifications.empty());
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled, pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
true); true);
EXPECT_TRUE(helper->IsEnabled()); EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications_.size()); ASSERT_EQ(1U, state_changed_notifications.size());
EXPECT_TRUE(state_changed_notifications_[0]); EXPECT_TRUE(state_changed_notifications[0]);
state_changed_notifications_.clear(); state_changed_notifications.clear();
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled, pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
false); false);
EXPECT_FALSE(helper->IsEnabled()); EXPECT_FALSE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications_.size()); ASSERT_EQ(1U, state_changed_notifications.size());
EXPECT_FALSE(state_changed_notifications_[0]); EXPECT_FALSE(state_changed_notifications[0]);
helper->RemoveObserver(this); helper->RemoveObserver(this);
} }
...@@ -135,14 +125,14 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest, ...@@ -135,14 +125,14 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest,
&sync_service_); &sync_service_);
helper->AddObserver(this); helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled()); EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications_.empty()); EXPECT_TRUE(state_changed_notifications.empty());
sync_service_.set_sync_initialized(true); sync_service_.set_sync_initialized(true);
sync_service_.set_sync_active_data_type( sync_service_.set_sync_active_data_type(
syncer::ModelType::HISTORY_DELETE_DIRECTIVES); syncer::ModelType::HISTORY_DELETE_DIRECTIVES);
sync_service_.FireOnStateChangeOnAllObservers(); sync_service_.FireOnStateChangeOnAllObservers();
EXPECT_TRUE(helper->IsEnabled()); EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications_.size()); ASSERT_EQ(1U, state_changed_notifications.size());
helper->RemoveObserver(this); helper->RemoveObserver(this);
} }
...@@ -163,13 +153,13 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest, ...@@ -163,13 +153,13 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest,
NewPersonalizedDataCollectionConsentHelper(true, &sync_service_); NewPersonalizedDataCollectionConsentHelper(true, &sync_service_);
helper->AddObserver(this); helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled()); EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications_.empty()); EXPECT_TRUE(state_changed_notifications.empty());
sync_service_.set_sync_initialized(true); sync_service_.set_sync_initialized(true);
sync_service_.set_sync_active_data_type(syncer::ModelType::USER_EVENTS); sync_service_.set_sync_active_data_type(syncer::ModelType::USER_EVENTS);
sync_service_.FireOnStateChangeOnAllObservers(); sync_service_.FireOnStateChangeOnAllObservers();
EXPECT_TRUE(helper->IsEnabled()); EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications_.size()); ASSERT_EQ(1U, state_changed_notifications.size());
helper->RemoveObserver(this); helper->RemoveObserver(this);
} }
...@@ -180,44 +170,34 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest, ...@@ -180,44 +170,34 @@ TEST_F(UrlKeyedDataCollectionConsentHelperTest,
NewPersonalizedDataCollectionConsentHelper(false, &sync_service_); NewPersonalizedDataCollectionConsentHelper(false, &sync_service_);
helper->AddObserver(this); helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled()); EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications_.empty()); EXPECT_TRUE(state_changed_notifications.empty());
sync_service_.set_sync_initialized(true); sync_service_.set_sync_initialized(true);
sync_service_.set_sync_active_data_type( sync_service_.set_sync_active_data_type(
syncer::ModelType::HISTORY_DELETE_DIRECTIVES); syncer::ModelType::HISTORY_DELETE_DIRECTIVES);
sync_service_.FireOnStateChangeOnAllObservers(); sync_service_.FireOnStateChangeOnAllObservers();
EXPECT_TRUE(helper->IsEnabled()); EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications_.size()); ASSERT_EQ(1U, state_changed_notifications.size());
helper->RemoveObserver(this); helper->RemoveObserver(this);
} }
TEST_F(UrlKeyedDataCollectionConsentHelperTest, TEST_F(UrlKeyedDataCollectionConsentHelperTest,
PersonalizedDataCollection_NullSyncService) { PersonalizedDataCollection_NullSyncService) {
for (bool is_unified_consent_enabled : {true, false}) { {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper = std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper:: UrlKeyedDataCollectionConsentHelper::
NewPersonalizedDataCollectionConsentHelper( NewPersonalizedDataCollectionConsentHelper(
is_unified_consent_enabled, nullptr /* sync_service */); false /* is_unified_consent_enabled */,
nullptr /* sync_service */);
EXPECT_FALSE(helper->IsEnabled()); EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(helper->IsShutDown());
} }
} {
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
PersonalizedDataCollection_ShutDown) {
for (bool is_unified_consent_enabled : {true, false}) {
ASSERT_TRUE(shutdown_notifications_.empty());
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper = std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper:: UrlKeyedDataCollectionConsentHelper::
NewPersonalizedDataCollectionConsentHelper( NewPersonalizedDataCollectionConsentHelper(
is_unified_consent_enabled, &sync_service_); true /* is_unified_consent_enabled */,
helper->AddObserver(this); nullptr /* sync_service */);
EXPECT_FALSE(helper->IsShutDown()); EXPECT_FALSE(helper->IsEnabled());
sync_service_.FireOnSyncShutdownOnAllObservers();
EXPECT_TRUE(helper->IsShutDown());
EXPECT_EQ(1U, shutdown_notifications_.size());
helper->RemoveObserver(this);
shutdown_notifications_.clear();
} }
} }
......
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