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

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

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: Split 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 #include "components/ukm/observers/sync_disable_observer.h"
6
7 namespace ukm {
8
9 SyncDisableObserver::SyncDisableObserver()
10 : sync_observer_(this), all_profiles_enabled_(false) {}
11
12 SyncDisableObserver::~SyncDisableObserver() {}
13
14 // static
15 bool SyncDisableObserver::IsHistorySyncEnabled(
16 syncer::SyncService* sync_service) {
17 return sync_service &&
18 sync_service->GetPreferredDataTypes().Has(
rkaplow 2017/02/01 16:40:55 can you comment on this
Steven Holte 2017/02/03 00:04:34 Done.
19 syncer::HISTORY_DELETE_DIRECTIVES);
20 }
21
22 void SyncDisableObserver::ObserveServiceForSyncDisables(
23 syncer::SyncService* sync_service) {
24 was_enabled_map_[sync_service] = IsHistorySyncEnabled(sync_service);
25 sync_observer_.Add(sync_service);
26 UpdateAllProfileEnabled(false);
27 }
28
29 void SyncDisableObserver::UpdateAllProfileEnabled(bool must_purge) {
30 // If there are no services, default to being disabled.
31 if (was_enabled_map_.empty()) {
32 all_profiles_enabled_ = false;
33 OnSyncPrefsChanged(must_purge);
34 return;
35 }
36
37 bool all_enabled = true;
38 for (auto const& kv : was_enabled_map_) {
Alexei Svitkine (slow) 2017/02/01 19:31:07 Nit: const auto&
Steven Holte 2017/02/03 00:04:34 Done.
39 if (!kv.second) {
40 all_enabled = false;
41 break;
42 }
43 }
44 if (must_purge || (all_enabled != all_profiles_enabled_)) {
45 all_profiles_enabled_ = all_enabled;
46 OnSyncPrefsChanged(must_purge);
47 }
48 }
49
50 void SyncDisableObserver::OnSyncConfigurationCompleted(
51 syncer::SyncService* sync) {
52 DCHECK(was_enabled_map_.find(sync) != was_enabled_map_.end());
Alexei Svitkine (slow) 2017/02/01 19:31:07 Nit: !ContainsKey()
Steven Holte 2017/02/03 00:04:34 Done.
53
54 bool is_enabled = IsHistorySyncEnabled(sync);
55 bool must_purge = was_enabled_map_[sync] && !is_enabled;
56 was_enabled_map_[sync] = is_enabled;
57 UpdateAllProfileEnabled(must_purge);
58 }
59
60 void SyncDisableObserver::OnSyncShutdown(syncer::SyncService* sync) {
61 DCHECK(was_enabled_map_.find(sync) != was_enabled_map_.end());
62 sync_observer_.Remove(sync);
63 was_enabled_map_.erase(sync);
64 UpdateAllProfileEnabled(false);
65 }
66
67 bool SyncDisableObserver::IsHistorySyncEnabledOnAllProfiles() {
68 return all_profiles_enabled_;
69 }
70
71 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698