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

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

Issue 2653693004: UKM Sync Observer (Closed)
Patch Set: Split 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..697a1609422ac1c9fd53a40d846faaaa9f1d9ff5
--- /dev/null
+++ b/components/ukm/observers/sync_disable_observer.cc
@@ -0,0 +1,71 @@
+// 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"
+
+namespace ukm {
+
+SyncDisableObserver::SyncDisableObserver()
+ : sync_observer_(this), all_profiles_enabled_(false) {}
+
+SyncDisableObserver::~SyncDisableObserver() {}
+
+// static
+bool SyncDisableObserver::IsHistorySyncEnabled(
+ syncer::SyncService* sync_service) {
+ return sync_service &&
+ 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.
+ 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) {
+ // 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 (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.
+ 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(
+ syncer::SyncService* sync) {
+ 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.
+
+ 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) {
+ DCHECK(was_enabled_map_.find(sync) != was_enabled_map_.end());
+ 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