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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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();
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
22 GetUserShare()->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 UpdateNewEntryStats(type);
47 if (e.ref(syncable::IS_DEL))
48 UpdateDeletedEntryStats(type);
49 }
50 }
51 return types;
52 }
53
54 void SyncBackupManager::NormalizeEntries() {
55 WriteTransaction trans(FROM_HERE, GetUserShare());
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698