OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "sync/internal_api/sync_backup_manager.h" |
| 6 |
| 7 #include "sync/internal_api/public/write_transaction.h" |
| 8 #include "sync/syncable/directory.h" |
| 9 #include "sync/syncable/mutable_entry.h" |
| 10 |
| 11 namespace syncer { |
| 12 |
| 13 SyncBackupManager::SyncBackupManager() |
| 14 : in_normalization_(false) { |
| 15 } |
| 16 |
| 17 SyncBackupManager::~SyncBackupManager() { |
| 18 } |
| 19 |
| 20 void SyncBackupManager::SaveChanges() { |
| 21 NormalizeEntries(); |
| 22 share_.directory->SaveChanges(); |
| 23 } |
| 24 |
| 25 ModelTypeSet SyncBackupManager::HandleTransactionEndingChangeEvent( |
| 26 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 27 syncable::BaseTransaction* trans) { |
| 28 ModelTypeSet types; |
| 29 if (in_normalization_) { |
| 30 // Skip if in our own WriteTransaction from NormalizeEntries(). |
| 31 in_normalization_ = false; |
| 32 return types; |
| 33 } |
| 34 |
| 35 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 36 write_transaction_info.Get().mutations.Get().begin(); |
| 37 it != write_transaction_info.Get().mutations.Get().end(); ++it) { |
| 38 int64 id = it->first; |
| 39 if (unsynced_.find(id) == unsynced_.end()) { |
| 40 unsynced_.insert(id); |
| 41 |
| 42 const syncable::EntryKernel& e = it->second.mutated; |
| 43 ModelType type = e.GetModelType(); |
| 44 types.Put(type); |
| 45 if (!e.ref(syncable::ID).ServerKnows()) |
| 46 status_.num_entries_by_type[type]++; |
| 47 if (e.ref(syncable::IS_DEL)) |
| 48 status_.num_to_delete_entries_by_type[type]++; |
| 49 } |
| 50 } |
| 51 return types; |
| 52 } |
| 53 |
| 54 void SyncBackupManager::NormalizeEntries() { |
| 55 WriteTransaction trans(FROM_HERE, &share_); |
| 56 in_normalization_ = true; |
| 57 for (std::set<int64>::const_iterator it = unsynced_.begin(); |
| 58 it != unsynced_.end(); ++it) { |
| 59 syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), |
| 60 syncable::GET_BY_HANDLE, *it); |
| 61 CHECK(entry.good()); |
| 62 |
| 63 if (!entry.GetId().ServerKnows()) |
| 64 entry.PutId(syncable::Id::CreateFromServerId(entry.GetId().value())); |
| 65 entry.PutBaseVersion(1); |
| 66 entry.PutIsUnsynced(false); |
| 67 } |
| 68 unsynced_.clear(); |
| 69 } |
| 70 |
| 71 } // namespace syncer |
OLD | NEW |