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

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

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 #include "components/ukm/observers/sync_disable_observer.h"
6
7 #include "base/stl_util.h"
8
9 namespace ukm {
10
11 SyncDisableObserver::SyncDisableObserver()
12 : sync_observer_(this), all_profiles_enabled_(false) {}
13
14 SyncDisableObserver::~SyncDisableObserver() {}
15
16 // static
17 bool SyncDisableObserver::IsHistorySyncEnabled(
18 syncer::SyncService* sync_service) {
19 return sync_service &&
20 // User must not be using a passphrase to encrypt synced data.
skym 2017/02/03 01:04:00 Can you swap this comment with the IsEngineInitial
Steven Holte 2017/02/04 00:16:33 Done.
21 sync_service->IsEngineInitialized() &&
skym 2017/02/03 01:04:00 I'm having a hard time convincing myself this is s
Steven Holte 2017/02/04 00:16:33 Done. I think the only assumption I'm making is t
22 !sync_service->IsUsingSecondaryPassphrase() &&
23 // User must have history sync option enabled.
24 sync_service->GetPreferredDataTypes().Has(
25 syncer::HISTORY_DELETE_DIRECTIVES);
26 }
27
28 void SyncDisableObserver::ObserveServiceForSyncDisables(
29 syncer::SyncService* sync_service) {
30 was_enabled_map_[sync_service] = IsHistorySyncEnabled(sync_service);
31 sync_observer_.Add(sync_service);
32 UpdateAllProfileEnabled(false);
33 }
34
35 void SyncDisableObserver::UpdateAllProfileEnabled(bool must_purge) {
skym 2017/02/03 01:04:00 Would be great to get unit tests on all this logic
Steven Holte 2017/02/04 00:16:33 Added some tests
36 // If there are no services, default to being disabled.
37 if (was_enabled_map_.empty()) {
38 all_profiles_enabled_ = false;
39 OnSyncPrefsChanged(must_purge);
40 return;
41 }
42
43 bool all_enabled = true;
44 for (const auto& kv : was_enabled_map_) {
45 if (!kv.second) {
46 all_enabled = false;
47 break;
48 }
49 }
50 if (must_purge || (all_enabled != all_profiles_enabled_)) {
51 all_profiles_enabled_ = all_enabled;
52 OnSyncPrefsChanged(must_purge);
53 }
54 }
55
56 void SyncDisableObserver::OnSyncConfigurationCompleted(
skym 2017/02/03 01:04:00 I'm worried this isn't going to be work like you w
Steven Holte 2017/02/04 00:16:33 I've changed this to OnStateChange, and the I thin
skym 2017/02/07 16:45:45 Depends on what you mean by "engines". When we (sy
57 syncer::SyncService* sync) {
58 DCHECK(!ContainsKey(was_enabled_map_, sync));
59 bool is_enabled = IsHistorySyncEnabled(sync);
60 bool must_purge = was_enabled_map_[sync] && !is_enabled;
61 was_enabled_map_[sync] = is_enabled;
62 UpdateAllProfileEnabled(must_purge);
63 }
64
65 void SyncDisableObserver::OnSyncShutdown(syncer::SyncService* sync) {
skym 2017/02/03 01:04:00 So this hasn't landed yet, but I don't see a depen
Steven Holte 2017/02/04 00:16:33 Rebased now that the patch has landed.
66 DCHECK(!ContainsKey(was_enabled_map_, sync));
67 sync_observer_.Remove(sync);
68 was_enabled_map_.erase(sync);
69 UpdateAllProfileEnabled(false);
70 }
71
72 bool SyncDisableObserver::IsHistorySyncEnabledOnAllProfiles() {
73 return all_profiles_enabled_;
74 }
75
76 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698