OLD | NEW |
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) { |
18 Lock(); | 19 Lock(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 DCHECK(!mutations.Get().empty()); | 76 DCHECK(!mutations.Get().empty()); |
76 | 77 |
77 WriteTransactionInfo write_transaction_info( | 78 WriteTransactionInfo write_transaction_info( |
78 directory_->kernel_->next_write_transaction_id, | 79 directory_->kernel_->next_write_transaction_id, |
79 from_here_, writer_, mutations); | 80 from_here_, writer_, mutations); |
80 ++directory_->kernel_->next_write_transaction_id; | 81 ++directory_->kernel_->next_write_transaction_id; |
81 | 82 |
82 ImmutableWriteTransactionInfo immutable_write_transaction_info( | 83 ImmutableWriteTransactionInfo immutable_write_transaction_info( |
83 &write_transaction_info); | 84 &write_transaction_info); |
84 DirectoryChangeDelegate* const delegate = directory_->kernel_->delegate; | 85 DirectoryChangeDelegate* const delegate = directory_->kernel_->delegate; |
| 86 std::vector<int64> entry_changed; |
85 if (writer_ == syncable::SYNCAPI) { | 87 if (writer_ == syncable::SYNCAPI) { |
86 delegate->HandleCalculateChangesChangeEventFromSyncApi( | 88 delegate->HandleCalculateChangesChangeEventFromSyncApi( |
87 immutable_write_transaction_info, this); | 89 immutable_write_transaction_info, this, &entry_changed); |
88 } else { | 90 } else { |
89 delegate->HandleCalculateChangesChangeEventFromSyncer( | 91 delegate->HandleCalculateChangesChangeEventFromSyncer( |
90 immutable_write_transaction_info, this); | 92 immutable_write_transaction_info, this, &entry_changed); |
91 } | 93 } |
| 94 UpdateTransactionVersion(entry_changed); |
92 | 95 |
93 ModelTypeSet models_with_changes = | 96 ModelTypeSet models_with_changes = |
94 delegate->HandleTransactionEndingChangeEvent( | 97 delegate->HandleTransactionEndingChangeEvent( |
95 immutable_write_transaction_info, this); | 98 immutable_write_transaction_info, this); |
96 | 99 |
97 directory_->kernel_->transaction_observer.Call(FROM_HERE, | 100 directory_->kernel_->transaction_observer.Call(FROM_HERE, |
98 &TransactionObserver::OnTransactionWrite, | 101 &TransactionObserver::OnTransactionWrite, |
99 immutable_write_transaction_info, models_with_changes); | 102 immutable_write_transaction_info, models_with_changes); |
100 | 103 |
101 return models_with_changes; | 104 return models_with_changes; |
102 } | 105 } |
103 | 106 |
104 void WriteTransaction::NotifyTransactionComplete( | 107 void WriteTransaction::NotifyTransactionComplete( |
105 ModelTypeSet models_with_changes) { | 108 ModelTypeSet models_with_changes) { |
106 directory_->kernel_->delegate->HandleTransactionCompleteChangeEvent( | 109 directory_->kernel_->delegate->HandleTransactionCompleteChangeEvent( |
107 models_with_changes); | 110 models_with_changes); |
108 } | 111 } |
109 | 112 |
| 113 void WriteTransaction::UpdateTransactionVersion( |
| 114 const std::vector<int64>& entry_changed) { |
| 115 syncer::ModelTypeSet type_seen; |
| 116 for (uint32 i = 0; i < entry_changed.size(); ++i) { |
| 117 MutableEntry entry(this, GET_BY_HANDLE, entry_changed[i]); |
| 118 if (entry.good()) { |
| 119 ModelType type = GetModelTypeFromSpecifics(entry.Get(SPECIFICS)); |
| 120 if (!type_seen.Has(type)) { |
| 121 directory_->IncrementTransactionVersion(type); |
| 122 type_seen.Put(type); |
| 123 } |
| 124 entry.Put(TRANSACTION_VERSION, directory_->GetTransactionVersion(type)); |
| 125 } |
| 126 } |
| 127 } |
| 128 |
110 WriteTransaction::~WriteTransaction() { | 129 WriteTransaction::~WriteTransaction() { |
111 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); | 130 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); |
112 directory()->CheckInvariantsOnTransactionClose(this, mutations.Get()); | 131 directory()->CheckInvariantsOnTransactionClose(this, mutations.Get()); |
113 | 132 |
114 // |CheckTreeInvariants| could have thrown an unrecoverable error. | 133 // |CheckTreeInvariants| could have thrown an unrecoverable error. |
115 if (unrecoverable_error_set_) { | 134 if (unrecoverable_error_set_) { |
116 HandleUnrecoverableErrorIfSet(); | 135 HandleUnrecoverableErrorIfSet(); |
117 Unlock(); | 136 Unlock(); |
118 return; | 137 return; |
119 } | 138 } |
(...skipping 14 matching lines...) Expand all Loading... |
134 ENUM_CASE(SYNCAPI); | 153 ENUM_CASE(SYNCAPI); |
135 }; | 154 }; |
136 NOTREACHED(); | 155 NOTREACHED(); |
137 return ""; | 156 return ""; |
138 } | 157 } |
139 | 158 |
140 #undef ENUM_CASE | 159 #undef ENUM_CASE |
141 | 160 |
142 } // namespace syncable | 161 } // namespace syncable |
143 } // namespace syncer | 162 } // namespace syncer |
OLD | NEW |