Chromium Code Reviews| Index: components/ukm/observers/sync_disable_observer.h |
| diff --git a/components/ukm/observers/sync_disable_observer.h b/components/ukm/observers/sync_disable_observer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..904ac38a4cb9ca0b388bc979e074f43b346e9825 |
| --- /dev/null |
| +++ b/components/ukm/observers/sync_disable_observer.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_ |
| +#define COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/scoped_observer.h" |
| +#include "components/sync/driver/sync_service.h" |
| +#include "components/sync/driver/sync_service_observer.h" |
| + |
| +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 { |
| + public: |
| + SyncDisableObserver(); |
| + ~SyncDisableObserver() override; |
| + |
| + // Helper method to check if history sync is enabled. |
| + static bool IsHistorySyncEnabled(syncer::SyncService* sync_service); |
| + |
| + // Starts observing a service for sync disables. |
| + void ObserveServiceForSyncDisables(syncer::SyncService* sync_service); |
| + |
| + // Returns if history sync is enabled on all active profiles. |
| + virtual bool IsHistorySyncEnabledOnAllProfiles(); |
| + |
| + // syncer::SyncServiceObserver |
|
Alexei Svitkine (slow)
2017/02/01 19:31:07
Nit: Add :
Steven Holte
2017/02/03 00:04:34
Done.
|
| + void OnSyncConfigurationCompleted(syncer::SyncService* sync) override; |
| + void OnSyncShutdown(syncer::SyncService* sync) override; |
|
Alexei Svitkine (slow)
2017/02/01 19:31:07
Can these be in private section?
Steven Holte
2017/02/03 00:04:34
Done.
|
| + |
| + protected: |
| + // Called after state changes and some profile has sync disabled. |
| + // If |must_purge| is true, sync was disabled for some profile, and |
| + // local data should be purged. |
| + virtual void OnSyncPrefsChanged(bool must_purge) = 0; |
| + |
| + private: |
| + // Recomputes all_profiles_enabled_ state from was_enabled_map_; |
| + void UpdateAllProfileEnabled(bool must_purge); |
| + |
| + // Tracks observed history services, for cleanup. |
| + ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver> |
| + sync_observer_; |
| + |
| + // The list of services that had sync enabled when we last checked. |
| + std::map<syncer::SyncService*, bool> was_enabled_map_; |
| + |
| + // Tracks if sync was enabled on all profiles after the last state change. |
| + bool all_profiles_enabled_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SyncDisableObserver); |
| +}; |
| + |
| +} // namespace ukm |
| + |
| +#endif // COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_ |