OLD | NEW |
---|---|
(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 // syncer::SyncServiceObserver | |
Alexei Svitkine (slow)
2017/02/01 19:31:07
Nit: Add :
Steven Holte
2017/02/03 00:04:34
Done.
| |
35 void OnSyncConfigurationCompleted(syncer::SyncService* sync) override; | |
36 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.
| |
37 | |
38 protected: | |
39 // Called after state changes and some profile has sync disabled. | |
40 // If |must_purge| is true, sync was disabled for some profile, and | |
41 // local data should be purged. | |
42 virtual void OnSyncPrefsChanged(bool must_purge) = 0; | |
43 | |
44 private: | |
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_ | |
OLD | NEW |