Commit 6421bf9e authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

Reland "[unified-consent] Refactor migration code and add settings updates"

This is a reland of 28ac1ad7
The were two problems:
 - There was a call to internal::GetUnifiedConsentFeatureState()
 in UnifiedConsentService::ShouldShowConsentBump().
 Instead of using this function, the check for the feature state should
 happen on the platform level. This is already done on Desktop, so
 removing the call will resolve the problem.
 - The initialization of scoped_unified_consent_ in the unit tests had a
 bug. When the variable was reset with a new value, the new value was
 created before the old one was deleted which led to a memory leak.

Original change's description:
> [unified-consent] Refactor migration code and add settings updates
>
> The migration code in the UnifiedConsentService is refactored:
>  - The migration state IN_PROGRESS_SHOULD_SHOW_CONSENT_BUMP is
>  extracted to it's own pref kShouldShowUnifiedConsentBump.
>  - The migration state kInProgressWaitForSyncInit is introduced
>  to be able to update the settings for migration when sync is
>  initialized.
>
> Additional changes:
>  - ShouldShowConsentBump only returns true if the consent bump
>  feature is enabled.
>  - The rollback enables sync-everything now also when the user is
>  not syncing USER_EVENTS (which is disabled during the migration).
>
> Users that previously had the unified consent feature enabled and
> for which ShouldShowConsentBump=true, will not be shown the consent
> bump anymore after this CL is landed. This will only affect a few
> users on Canary and Dev.
>
> Bug: 863932
> Change-Id: I211805f9059cd26056ed81d01ff19470b8caed3c
> Reviewed-on: https://chromium-review.googlesource.com/1172690
> Reviewed-by: David Roger <droger@chromium.org>
> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
> Commit-Queue: Thomas Tangl <tangltom@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#584341}

TBR=ellyjones@chromium.org
TBR=droger@chromium.org

Bug: 863932
Change-Id: Ic041ac99da729d072f49fc9aa6adfe5624fc089e
Reviewed-on: https://chromium-review.googlesource.com/1180921
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584451}
parent e3fd7864
...@@ -116,8 +116,7 @@ class ConsentBumpActivator : public BrowserListObserver, ...@@ -116,8 +116,7 @@ class ConsentBumpActivator : public BrowserListObserver,
unified_consent::UnifiedConsentService* consent_service = unified_consent::UnifiedConsentService* consent_service =
UnifiedConsentServiceFactory::GetForProfile(profile_); UnifiedConsentServiceFactory::GetForProfile(profile_);
consent_service->MarkMigrationComplete( consent_service->MarkConsentBumpShown();
unified_consent::ConsentBumpSuppressReason::kNone);
switch (result) { switch (result) {
case LoginUIService::CONFIGURE_SYNC_FIRST: case LoginUIService::CONFIGURE_SYNC_FIRST:
......
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
namespace unified_consent { namespace unified_consent {
namespace prefs { namespace prefs {
// Boolean indicating whether all criteria is met for the consent bump to be
// shown.
const char kShouldShowUnifiedConsentBump[] =
"unified_consent.consent_bump.should_show";
// Boolean that is true when the user opted into unified consent. // Boolean that is true when the user opted into unified consent.
const char kUnifiedConsentGiven[] = "unified_consent_given"; const char kUnifiedConsentGiven[] = "unified_consent_given";
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace unified_consent { namespace unified_consent {
namespace prefs { namespace prefs {
extern const char kShouldShowUnifiedConsentBump[];
extern const char kUnifiedConsentGiven[]; extern const char kUnifiedConsentGiven[];
extern const char kUnifiedConsentMigrationState[]; extern const char kUnifiedConsentMigrationState[];
extern const char kUrlKeyedAnonymizedDataCollectionEnabled[]; extern const char kUrlKeyedAnonymizedDataCollectionEnabled[];
......
...@@ -31,10 +31,10 @@ using Service = UnifiedConsentServiceClient::Service; ...@@ -31,10 +31,10 @@ using Service = UnifiedConsentServiceClient::Service;
using ServiceState = UnifiedConsentServiceClient::ServiceState; using ServiceState = UnifiedConsentServiceClient::ServiceState;
enum class MigrationState : int { enum class MigrationState : int {
NOT_INITIALIZED = 0, kNotInitialized = 0,
IN_PROGRESS_SHOULD_SHOW_CONSENT_BUMP = 1, kInProgressWaitForSyncInit = 1,
// Reserve space for other IN_PROGRESS_* entries to be added here. // Reserve space for other kInProgress* entries to be added here.
COMPLETED = 10, kCompleted = 10,
}; };
enum class ConsentBumpSuppressReason { enum class ConsentBumpSuppressReason {
...@@ -75,19 +75,14 @@ class UnifiedConsentService : public KeyedService, ...@@ -75,19 +75,14 @@ class UnifiedConsentService : public KeyedService,
void SetUnifiedConsentGiven(bool unified_consent_given); void SetUnifiedConsentGiven(bool unified_consent_given);
bool IsUnifiedConsentGiven(); bool IsUnifiedConsentGiven();
// Helper function for the consent bump. The consent bump has to // Returns true if all criteria is met to show the consent bump.
// be shown depending on the migration state.
MigrationState GetMigrationState();
// Returns true if the consent bump needs to be shown to the user as part
// of the migration of the Chrome profile to unified consent.
bool ShouldShowConsentBump(); bool ShouldShowConsentBump();
// Finishes the migration to unified consent. All future calls to // Marks the consent bump as shown. Any future calls to
// |GetMigrationState| are guranteed to return |MIGRATION_COMPLETED|. // |ShouldShowConsentBump| are guaranteed to return false.
// Takes as argument the suppress reason for not showing the consent void MarkConsentBumpShown();
// bump if it wasn't shown. // Records the consent bump suppress reason and updates the state whether the
void MarkMigrationComplete(ConsentBumpSuppressReason suppress_reason); // consent bump should be shown. Note: In some cases, e.g. sync paused,
// Records the suppress reason for the consent bump without changing the // |ShouldShowConsentBump| will still return true.
// migration state.
void RecordConsentBumpSuppressReason( void RecordConsentBumpSuppressReason(
ConsentBumpSuppressReason suppress_reason); ConsentBumpSuppressReason suppress_reason);
...@@ -115,9 +110,17 @@ class UnifiedConsentService : public KeyedService, ...@@ -115,9 +110,17 @@ class UnifiedConsentService : public KeyedService,
// Enables/disables syncing everything if the sync engine is initialized. // Enables/disables syncing everything if the sync engine is initialized.
void SetSyncEverythingIfPossible(bool sync_everything); void SetSyncEverythingIfPossible(bool sync_everything);
// Called when the unified consent service is created to resolve // Migration helpers.
// inconsistencies with sync-related prefs. MigrationState GetMigrationState();
void SetMigrationState(MigrationState migration_state);
// Called when the unified consent service is created. This sets the
// |kShouldShowUnifiedConsentBump| pref to true if the user is eligible and
// calls |UpdateSettingsForMigration| at the end.
void MigrateProfileToUnifiedConsent(); void MigrateProfileToUnifiedConsent();
// Updates the settings preferences for the migration when the sync engine is
// initialized. When it is not, this function will be called again from
// |OnStateChanged| when the sync engine is initialized.
void UpdateSettingsForMigration();
// Returns true if all non-personalized services are enabled. // Returns true if all non-personalized services are enabled.
bool AreAllNonPersonalizedServicesEnabled(); bool AreAllNonPersonalizedServicesEnabled();
...@@ -125,6 +128,10 @@ class UnifiedConsentService : public KeyedService, ...@@ -125,6 +128,10 @@ class UnifiedConsentService : public KeyedService,
// Checks if all on-by-default non-personalized services are on. // Checks if all on-by-default non-personalized services are on.
bool AreAllOnByDefaultPrivacySettingsOn(); bool AreAllOnByDefaultPrivacySettingsOn();
// Helper that checks whether it's okay to call
// |SyncService::OnUserChoseDatatypes|.
bool IsSyncConfigurable();
std::unique_ptr<UnifiedConsentServiceClient> service_client_; std::unique_ptr<UnifiedConsentServiceClient> service_client_;
PrefService* pref_service_; PrefService* pref_service_;
identity::IdentityManager* identity_manager_; identity::IdentityManager* identity_manager_;
......
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