diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-28 15:28:34 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-28 13:54:51 +0000 |
commit | 2a19c63448c84c1805fb1a585c3651318bb86ca7 (patch) | |
tree | eb17888e8531aa6ee5e85721bd553b832a7e5156 /chromium/components/ukm/observers/sync_disable_observer.h | |
parent | b014812705fc80bff0a5c120dfcef88f349816dc (diff) | |
download | qtwebengine-chromium-2a19c63448c84c1805fb1a585c3651318bb86ca7.tar.gz |
BASELINE: Update Chromium to 69.0.3497.70
Change-Id: I2b7b56e4e7a8b26656930def0d4575dc32b900a0
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/ukm/observers/sync_disable_observer.h')
-rw-r--r-- | chromium/components/ukm/observers/sync_disable_observer.h | 97 |
1 files changed, 80 insertions, 17 deletions
diff --git a/chromium/components/ukm/observers/sync_disable_observer.h b/chromium/components/ukm/observers/sync_disable_observer.h index 2de46181f0f..e051443a676 100644 --- a/chromium/components/ukm/observers/sync_disable_observer.h +++ b/chromium/components/ukm/observers/sync_disable_observer.h @@ -10,25 +10,38 @@ #include "base/scoped_observer.h" #include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service_observer.h" +#include "components/unified_consent/url_keyed_data_collection_consent_helper.h" + +class PrefService; namespace ukm { -// Observes the state of a set of SyncServices for changes to history sync -// preferences. This is for used to trigger purging of local state when -// sync is disabled on a profile and disabling recording when any non-syncing -// profiles are active. -class SyncDisableObserver : public syncer::SyncServiceObserver { +// Observer that monitors whether UKM is allowed for all profiles. +// +// For one profile, UKM is allowed under the following conditions: +// * If unified consent is disabled, then UKM is allowed for the profile iff +// sync history is active; +// * If unified consent is enabled, then UKM is allowed for the profile iff +// URL-keyed anonymized data collectiion is enabled. +class SyncDisableObserver + : public syncer::SyncServiceObserver, + public unified_consent::UrlKeyedDataCollectionConsentHelper::Observer { public: SyncDisableObserver(); ~SyncDisableObserver() override; // Starts observing a service for sync disables. - void ObserveServiceForSyncDisables(syncer::SyncService* sync_service); - - // Returns true iff sync is in a state that allows UKM to be enabled. - // This means that for all profiles, sync is initialized, connected, has the - // HISTORY_DELETE_DIRECTIVES data type enabled, and does not have a secondary - // passphrase enabled. + void ObserveServiceForSyncDisables(syncer::SyncService* sync_service, + PrefService* pref_service, + bool is_unified_consent_enabled); + + // Returns true iff all sync states alllow UKM to be enabled. This means that + // for all profiles: + // * If unified consent is disabled, then sync is initialized, connected, has + // the HISTORY_DELETE_DIRECTIVES data type enabled, and does not have a + // secondary passphrase enabled. + // * If unified consent is enabled, then URL-keyed anonymized data collection + // is enabled for that profile. virtual bool SyncStateAllowsUkm(); // Returns true iff sync is in a state that allows UKM to capture extensions. @@ -46,6 +59,11 @@ class SyncDisableObserver : public syncer::SyncServiceObserver { void OnStateChanged(syncer::SyncService* sync) override; void OnSyncShutdown(syncer::SyncService* sync) override; + // unified_consent::UrlKeyedDataCollectionConsentHelper::Observer: + void OnUrlKeyedDataCollectionConsentStateChanged( + unified_consent::UrlKeyedDataCollectionConsentHelper* consent_helper) + override; + // Recomputes all_profiles_enabled_ state from previous_states_; void UpdateAllProfileEnabled(bool must_purge); @@ -61,8 +79,29 @@ class SyncDisableObserver : public syncer::SyncServiceObserver { ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver> sync_observer_; + enum class DataCollectionState { + // Matches the case when unified consent feature is disabled + kIgnored, + // Unified consent feature is enabled and the user has disabled URL-keyed + // anonymized data collection. + kDisabled, + // Unified consent feature is enabled and the user has enabled URL-keyed + // anonymized data collection. + kEnabled + }; + // State data about sync services that we need to remember. struct SyncState { + // Returns true if this sync state allows UKM: + // * If unified consent is disabled, then sync is initialized, connected, + // has history data type enabled, and does not have a secondary passphrase + // enabled. + // * If unified consent is enabled, then URL-keyed anonymized data + // collection is enabled. + bool AllowsUkm() const; + // Returns true if |AllowUkm| and if sync extensions are enabled. + bool AllowsUkmWithExtension() const; + // If the user has history sync enabled. bool history_enabled = false; // If the user has extension sync enabled. @@ -74,21 +113,45 @@ class SyncDisableObserver : public syncer::SyncServiceObserver { // Whether user data is hidden by a secondary passphrase. // This is not valid if the state is not initialized. bool passphrase_protected = false; + + // Whether anonymized data collection is enabled. + // Note: This is not managed by sync service. It was added in this enum + // for convenience. + DataCollectionState anonymized_data_collection_state = + DataCollectionState::kIgnored; }; + // Updates the sync state for |sync| service. Updates all profiles if needed. + void UpdateSyncState( + syncer::SyncService* sync, + unified_consent::UrlKeyedDataCollectionConsentHelper* consent_helper); + // Gets the current state of a SyncService. - static SyncState GetSyncState(syncer::SyncService* sync); + // A non-null |consent_helper| implies that Unified Consent is enabled. + static SyncState GetSyncState( + syncer::SyncService* sync, + unified_consent::UrlKeyedDataCollectionConsentHelper* consent_helper); - // The list of services that had sync enabled when we last checked. + // The state of the sync services being observed. std::map<syncer::SyncService*, SyncState> previous_states_; - // Tracks if history sync was enabled on all profiles after the last state - // change. - bool all_histories_enabled_; + // The list of URL-keyed anonymized data collection consent helpers. + // + // Note: UrlKeyedDataCollectionConsentHelper do not rely on sync when + // unified consent feature is enabled but there must be exactly one per + // Chromium profile. As there is a single sync service per profile, it is safe + // to key them by sync service instead of introducing an additional map. + std::map< + syncer::SyncService*, + std::unique_ptr<unified_consent::UrlKeyedDataCollectionConsentHelper>> + consent_helpers_; + + // Tracks if UKM is allowed on all profiles after the last state change. + bool all_sync_states_allow_ukm_ = false; // Tracks if extension sync was enabled on all profiles after the last state // change. - bool all_extensions_enabled_; + bool all_sync_states_allow_extension_ukm_ = false; DISALLOW_COPY_AND_ASSIGN(SyncDisableObserver); }; |