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

Unified Diff: sync/internal_api/sync_backup_manager.cc

Issue 235053006: Add sync manager classes for backup/rollback: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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: sync/internal_api/sync_backup_manager.cc
diff --git a/sync/internal_api/sync_backup_manager.cc b/sync/internal_api/sync_backup_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0aff436ba981b90213fea12b323eba9fb40782c1
--- /dev/null
+++ b/sync/internal_api/sync_backup_manager.cc
@@ -0,0 +1,71 @@
+// Copyright 2014 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 "sync/internal_api/sync_backup_manager.h"
+
+#include "sync/internal_api/public/write_transaction.h"
+#include "sync/syncable/directory.h"
+#include "sync/syncable/mutable_entry.h"
+
+namespace syncer {
+
+SyncBackupManager::SyncBackupManager()
+ : in_normalization_(false) {
+}
+
+SyncBackupManager::~SyncBackupManager() {
+}
+
+void SyncBackupManager::SaveChanges() {
+ NormalizeEntries();
Nicolas Zea 2014/04/17 18:22:56 Is it necessary to call NormalizeEntries on every
haitaol1 2014/04/17 19:30:38 It only checks entries that are changed, so cost i
+ GetUserShare()->directory->SaveChanges();
+}
+
+ModelTypeSet SyncBackupManager::HandleTransactionEndingChangeEvent(
+ const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
+ syncable::BaseTransaction* trans) {
+ ModelTypeSet types;
+ if (in_normalization_) {
+ // Skip if in our own WriteTransaction from NormalizeEntries().
+ in_normalization_ = false;
+ return types;
+ }
+
+ for (syncable::EntryKernelMutationMap::const_iterator it =
+ write_transaction_info.Get().mutations.Get().begin();
+ it != write_transaction_info.Get().mutations.Get().end(); ++it) {
+ int64 id = it->first;
+ if (unsynced_.find(id) == unsynced_.end()) {
+ unsynced_.insert(id);
+
+ const syncable::EntryKernel& e = it->second.mutated;
+ ModelType type = e.GetModelType();
+ types.Put(type);
+ if (!e.ref(syncable::ID).ServerKnows())
+ UpdateNewEntryStats(type);
+ if (e.ref(syncable::IS_DEL))
+ UpdateDeletedEntryStats(type);
+ }
+ }
+ return types;
+}
+
+void SyncBackupManager::NormalizeEntries() {
+ WriteTransaction trans(FROM_HERE, GetUserShare());
+ in_normalization_ = true;
+ for (std::set<int64>::const_iterator it = unsynced_.begin();
+ it != unsynced_.end(); ++it) {
+ syncable::MutableEntry entry(trans.GetWrappedWriteTrans(),
+ syncable::GET_BY_HANDLE, *it);
+ CHECK(entry.good());
+
+ if (!entry.GetId().ServerKnows())
+ entry.PutId(syncable::Id::CreateFromServerId(entry.GetId().value()));
+ entry.PutBaseVersion(1);
+ entry.PutIsUnsynced(false);
+ }
+ unsynced_.clear();
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698