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

Unified Diff: components/ukm/observers/sync_disable_observer.cc

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: Address comments Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/ukm/observers/sync_disable_observer.cc
diff --git a/components/ukm/observers/sync_disable_observer.cc b/components/ukm/observers/sync_disable_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..05274f7ed6215efd800d6e9bfea98271b1a7db49
--- /dev/null
+++ b/components/ukm/observers/sync_disable_observer.cc
@@ -0,0 +1,76 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/ukm/observers/sync_disable_observer.h"
+
+#include "base/stl_util.h"
+
+namespace ukm {
+
+SyncDisableObserver::SyncDisableObserver()
+ : sync_observer_(this), all_profiles_enabled_(false) {}
+
+SyncDisableObserver::~SyncDisableObserver() {}
+
+// static
+bool SyncDisableObserver::IsHistorySyncEnabled(
+ syncer::SyncService* sync_service) {
+ return sync_service &&
+ // 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.
+ 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
+ !sync_service->IsUsingSecondaryPassphrase() &&
+ // User must have history sync option enabled.
+ sync_service->GetPreferredDataTypes().Has(
+ syncer::HISTORY_DELETE_DIRECTIVES);
+}
+
+void SyncDisableObserver::ObserveServiceForSyncDisables(
+ syncer::SyncService* sync_service) {
+ was_enabled_map_[sync_service] = IsHistorySyncEnabled(sync_service);
+ sync_observer_.Add(sync_service);
+ UpdateAllProfileEnabled(false);
+}
+
+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
+ // If there are no services, default to being disabled.
+ if (was_enabled_map_.empty()) {
+ all_profiles_enabled_ = false;
+ OnSyncPrefsChanged(must_purge);
+ return;
+ }
+
+ bool all_enabled = true;
+ for (const auto& kv : was_enabled_map_) {
+ if (!kv.second) {
+ all_enabled = false;
+ break;
+ }
+ }
+ if (must_purge || (all_enabled != all_profiles_enabled_)) {
+ all_profiles_enabled_ = all_enabled;
+ OnSyncPrefsChanged(must_purge);
+ }
+}
+
+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
+ syncer::SyncService* sync) {
+ DCHECK(!ContainsKey(was_enabled_map_, sync));
+ bool is_enabled = IsHistorySyncEnabled(sync);
+ bool must_purge = was_enabled_map_[sync] && !is_enabled;
+ was_enabled_map_[sync] = is_enabled;
+ UpdateAllProfileEnabled(must_purge);
+}
+
+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.
+ DCHECK(!ContainsKey(was_enabled_map_, sync));
+ sync_observer_.Remove(sync);
+ was_enabled_map_.erase(sync);
+ UpdateAllProfileEnabled(false);
+}
+
+bool SyncDisableObserver::IsHistorySyncEnabledOnAllProfiles() {
+ return all_profiles_enabled_;
+}
+
+} // namespace ukm

Powered by Google App Engine
This is Rietveld 408576698