Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: components/ukm/observers/sync_disable_observer.h

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: Address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_
6 #define COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_
7
8 #include <map>
9
10 #include "base/scoped_observer.h"
11 #include "components/sync/driver/sync_service.h"
12 #include "components/sync/driver/sync_service_observer.h"
13
14 namespace ukm {
15
16 // Observes the state of a set of SyncServices for changes to history sync
17 // preferences. This is for used to trigger purging of local state when
18 // sync is disabled on a profile and disabling recording when any non-syncing
19 // profiles are active.
20 class SyncDisableObserver : public syncer::SyncServiceObserver {
21 public:
22 SyncDisableObserver();
23 ~SyncDisableObserver() override;
24
25 // Helper method to check if history sync is enabled.
26 static bool IsHistorySyncEnabled(syncer::SyncService* sync_service);
27
28 // Starts observing a service for sync disables.
29 void ObserveServiceForSyncDisables(syncer::SyncService* sync_service);
30
31 // Returns if history sync is enabled on all active profiles.
32 virtual bool IsHistorySyncEnabledOnAllProfiles();
33
34 protected:
35 // Called after state changes and some profile has sync disabled.
36 // If |must_purge| is true, sync was disabled for some profile, and
37 // local data should be purged.
38 virtual void OnSyncPrefsChanged(bool must_purge) = 0;
39
40 private:
41 // syncer::SyncServiceObserver:
42 void OnSyncConfigurationCompleted(syncer::SyncService* sync) override;
43 void OnSyncShutdown(syncer::SyncService* sync) override;
44
45 // Recomputes all_profiles_enabled_ state from was_enabled_map_;
46 void UpdateAllProfileEnabled(bool must_purge);
47
48 // Tracks observed history services, for cleanup.
49 ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver>
50 sync_observer_;
51
52 // The list of services that had sync enabled when we last checked.
53 std::map<syncer::SyncService*, bool> was_enabled_map_;
54
55 // Tracks if sync was enabled on all profiles after the last state change.
56 bool all_profiles_enabled_;
57
58 DISALLOW_COPY_AND_ASSIGN(SyncDisableObserver);
59 };
60
61 } // namespace ukm
62
63 #endif // COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698