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

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

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: MSVC struct initializer 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
« no previous file with comments | « components/ukm/observers/DEPS ('k') | components/ukm/observers/sync_disable_observer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Starts observing a service for sync disables.
26 void ObserveServiceForSyncDisables(syncer::SyncService* sync_service);
27
28 // Returns if history sync is enabled on all active profiles.
29 virtual bool IsHistorySyncEnabledOnAllProfiles();
30
31 protected:
32 // Called after state changes and some profile has sync disabled.
33 // If |must_purge| is true, sync was disabled for some profile, and
34 // local data should be purged.
35 virtual void OnSyncPrefsChanged(bool must_purge) = 0;
36
37 private:
38 // syncer::SyncServiceObserver:
39 void OnStateChanged(syncer::SyncService* sync) override;
40 void OnSyncShutdown(syncer::SyncService* sync) override;
41
42 // Recomputes all_profiles_enabled_ state from previous_states_;
43 void UpdateAllProfileEnabled(bool must_purge);
44
45 // Returns true iff all profiles are enabled in previous_states_.
46 // If there are no profiles being observed, this returns false.
47 bool AreAllProfilesEnabled();
48
49 // Tracks observed history services, for cleanup.
50 ScopedObserver<syncer::SyncService, syncer::SyncServiceObserver>
51 sync_observer_;
52
53 // State data about sync services that we need to remember.
54 struct SyncState {
55 // If the user has history sync enabled.
56 bool history_enabled;
57 // Whether the sync service has been initialized.
58 bool initialized;
59 // Whether user data is hidden by a secondary passphrase.
60 // This is not valid if the state is not initialized.
61 bool passphrase_protected;
62 };
63
64 // Gets the current state of a SyncService.
65 static SyncState GetSyncState(syncer::SyncService* sync);
66
67 // The list of services that had sync enabled when we last checked.
68 std::map<syncer::SyncService*, SyncState> previous_states_;
69
70 // Tracks if sync was enabled on all profiles after the last state change.
71 bool all_profiles_enabled_;
72
73 DISALLOW_COPY_AND_ASSIGN(SyncDisableObserver);
74 };
75
76 } // namespace ukm
77
78 #endif // COMPONENTS_UKM_OBSERVERS_SYNC_DISABLE_OBSERVER_H_
OLDNEW
« no previous file with comments | « components/ukm/observers/DEPS ('k') | components/ukm/observers/sync_disable_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698