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

Side by Side Diff: sync/syncable/write_transaction.cc

Issue 11341048: Populate versions on individual nodes in sync model and native bookmark model. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lock dir Created 8 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/syncable/write_transaction.h" 5 #include "sync/syncable/write_transaction.h"
6 6
7 #include "sync/syncable/directory.h" 7 #include "sync/syncable/directory.h"
8 #include "sync/syncable/directory_change_delegate.h" 8 #include "sync/syncable/directory_change_delegate.h"
9 #include "sync/syncable/mutable_entry.h"
9 #include "sync/syncable/transaction_observer.h" 10 #include "sync/syncable/transaction_observer.h"
10 #include "sync/syncable/write_transaction_info.h" 11 #include "sync/syncable/write_transaction_info.h"
11 12
12 namespace syncer { 13 namespace syncer {
13 namespace syncable { 14 namespace syncable {
14 15
15 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, 16 WriteTransaction::WriteTransaction(const tracked_objects::Location& location,
16 WriterTag writer, Directory* directory) 17 WriterTag writer, Directory* directory)
17 : BaseTransaction(location, "WriteTransaction", writer, directory) { 18 : BaseTransaction(location, "WriteTransaction", writer, directory) {
Nicolas Zea 2012/11/02 21:02:25 initialize new_model_version_ to NULL
haitaol1 2012/11/02 22:58:18 Done.
18 Lock(); 19 Lock();
19 } 20 }
20 21
22 WriteTransaction::WriteTransaction(const tracked_objects::Location& location,
23 Directory* directory,
24 int64* new_model_version)
25 : BaseTransaction(location, "WriteTransaction", SYNCAPI, directory),
26 new_model_version_(new_model_version) {
27 Lock();
28 if (new_model_version_)
29 *new_model_version_ = -1;
30 }
31
21 void WriteTransaction::SaveOriginal(const EntryKernel* entry) { 32 void WriteTransaction::SaveOriginal(const EntryKernel* entry) {
22 if (!entry) { 33 if (!entry) {
23 return; 34 return;
24 } 35 }
25 // Insert only if it's not already there. 36 // Insert only if it's not already there.
26 const int64 handle = entry->ref(META_HANDLE); 37 const int64 handle = entry->ref(META_HANDLE);
27 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); 38 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle);
28 if (it == mutations_.end() || it->first != handle) { 39 if (it == mutations_.end() || it->first != handle) {
29 EntryKernelMutation mutation; 40 EntryKernelMutation mutation;
30 mutation.original = *entry; 41 mutation.original = *entry;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 DCHECK(!mutations.Get().empty()); 86 DCHECK(!mutations.Get().empty());
76 87
77 WriteTransactionInfo write_transaction_info( 88 WriteTransactionInfo write_transaction_info(
78 directory_->kernel_->next_write_transaction_id, 89 directory_->kernel_->next_write_transaction_id,
79 from_here_, writer_, mutations); 90 from_here_, writer_, mutations);
80 ++directory_->kernel_->next_write_transaction_id; 91 ++directory_->kernel_->next_write_transaction_id;
81 92
82 ImmutableWriteTransactionInfo immutable_write_transaction_info( 93 ImmutableWriteTransactionInfo immutable_write_transaction_info(
83 &write_transaction_info); 94 &write_transaction_info);
84 DirectoryChangeDelegate* const delegate = directory_->kernel_->delegate; 95 DirectoryChangeDelegate* const delegate = directory_->kernel_->delegate;
96 std::vector<int64> entry_changed;
85 if (writer_ == syncable::SYNCAPI) { 97 if (writer_ == syncable::SYNCAPI) {
86 delegate->HandleCalculateChangesChangeEventFromSyncApi( 98 delegate->HandleCalculateChangesChangeEventFromSyncApi(
87 immutable_write_transaction_info, this); 99 immutable_write_transaction_info, this, &entry_changed);
88 } else { 100 } else {
89 delegate->HandleCalculateChangesChangeEventFromSyncer( 101 delegate->HandleCalculateChangesChangeEventFromSyncer(
90 immutable_write_transaction_info, this); 102 immutable_write_transaction_info, this, &entry_changed);
91 } 103 }
104 UpdateTransactionVersion(entry_changed);
92 105
93 ModelTypeSet models_with_changes = 106 ModelTypeSet models_with_changes =
94 delegate->HandleTransactionEndingChangeEvent( 107 delegate->HandleTransactionEndingChangeEvent(
95 immutable_write_transaction_info, this); 108 immutable_write_transaction_info, this);
96 109
97 directory_->kernel_->transaction_observer.Call(FROM_HERE, 110 directory_->kernel_->transaction_observer.Call(FROM_HERE,
98 &TransactionObserver::OnTransactionWrite, 111 &TransactionObserver::OnTransactionWrite,
99 immutable_write_transaction_info, models_with_changes); 112 immutable_write_transaction_info, models_with_changes);
100 113
101 return models_with_changes; 114 return models_with_changes;
102 } 115 }
103 116
104 void WriteTransaction::NotifyTransactionComplete( 117 void WriteTransaction::NotifyTransactionComplete(
105 ModelTypeSet models_with_changes) { 118 ModelTypeSet models_with_changes) {
106 directory_->kernel_->delegate->HandleTransactionCompleteChangeEvent( 119 directory_->kernel_->delegate->HandleTransactionCompleteChangeEvent(
107 models_with_changes); 120 models_with_changes);
108 } 121 }
109 122
123 void WriteTransaction::UpdateTransactionVersion(
124 const std::vector<int64>& entry_changed) {
125 syncer::ModelTypeSet type_seen;
126 for (uint32 i = 0; i < entry_changed.size(); ++i) {
127 MutableEntry entry(this, GET_BY_HANDLE, entry_changed[i]);
128 if (entry.good()) {
129 ModelType type = GetModelTypeFromSpecifics(entry.Get(SPECIFICS));
130 if (!type_seen.Has(type)) {
131 directory_->IncrementTransactionVersion(type);
132 type_seen.Put(type);
133 }
134 entry.Put(TRANSACTION_VERSION, directory_->GetTransactionVersion(type));
135 }
136 }
137
138 if (!type_seen.Empty() && new_model_version_) {
139 DCHECK_EQ(1u, type_seen.Size());
140 *new_model_version_ = directory_->GetTransactionVersion(
141 type_seen.First().Get());
142 }
143 }
144
110 WriteTransaction::~WriteTransaction() { 145 WriteTransaction::~WriteTransaction() {
111 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); 146 const ImmutableEntryKernelMutationMap& mutations = RecordMutations();
112 directory()->CheckInvariantsOnTransactionClose(this, mutations.Get()); 147 directory()->CheckInvariantsOnTransactionClose(this, mutations.Get());
113 148
114 // |CheckTreeInvariants| could have thrown an unrecoverable error. 149 // |CheckTreeInvariants| could have thrown an unrecoverable error.
115 if (unrecoverable_error_set_) { 150 if (unrecoverable_error_set_) {
116 HandleUnrecoverableErrorIfSet(); 151 HandleUnrecoverableErrorIfSet();
117 Unlock(); 152 Unlock();
118 return; 153 return;
119 } 154 }
(...skipping 14 matching lines...) Expand all
134 ENUM_CASE(SYNCAPI); 169 ENUM_CASE(SYNCAPI);
135 }; 170 };
136 NOTREACHED(); 171 NOTREACHED();
137 return ""; 172 return "";
138 } 173 }
139 174
140 #undef ENUM_CASE 175 #undef ENUM_CASE
141 176
142 } // namespace syncable 177 } // namespace syncable
143 } // namespace syncer 178 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698