OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/syncable_write_transaction.h" | 5 #include "components/sync/syncable/syncable_write_transaction.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "sync/syncable/directory.h" | 11 #include "components/sync/syncable/directory.h" |
12 #include "sync/syncable/directory_change_delegate.h" | 12 #include "components/sync/syncable/directory_change_delegate.h" |
13 #include "sync/syncable/mutable_entry.h" | 13 #include "components/sync/syncable/mutable_entry.h" |
14 #include "sync/syncable/transaction_observer.h" | 14 #include "components/sync/syncable/transaction_observer.h" |
15 #include "sync/syncable/write_transaction_info.h" | 15 #include "components/sync/syncable/write_transaction_info.h" |
16 | 16 |
17 namespace syncer { | 17 namespace syncer { |
18 namespace syncable { | 18 namespace syncable { |
19 | 19 |
20 const int64_t kInvalidTransactionVersion = -1; | 20 const int64_t kInvalidTransactionVersion = -1; |
21 | 21 |
22 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, | 22 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, |
23 WriterTag writer, Directory* directory) | 23 WriterTag writer, |
| 24 Directory* directory) |
24 : BaseWriteTransaction(location, "WriteTransaction", writer, directory), | 25 : BaseWriteTransaction(location, "WriteTransaction", writer, directory), |
25 transaction_version_(NULL) { | 26 transaction_version_(NULL) { |
26 Lock(); | 27 Lock(); |
27 } | 28 } |
28 | 29 |
29 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, | 30 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, |
30 Directory* directory, | 31 Directory* directory, |
31 int64_t* transaction_version) | 32 int64_t* transaction_version) |
32 : BaseWriteTransaction(location, "WriteTransaction", SYNCAPI, directory), | 33 : BaseWriteTransaction(location, "WriteTransaction", SYNCAPI, directory), |
33 transaction_version_(transaction_version) { | 34 transaction_version_(transaction_version) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 NotifyTransactionComplete(models_with_changes); | 85 NotifyTransactionComplete(models_with_changes); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 ModelTypeSet WriteTransaction::NotifyTransactionChangingAndEnding( | 89 ModelTypeSet WriteTransaction::NotifyTransactionChangingAndEnding( |
89 const ImmutableEntryKernelMutationMap& mutations) { | 90 const ImmutableEntryKernelMutationMap& mutations) { |
90 directory_->kernel()->transaction_mutex.AssertAcquired(); | 91 directory_->kernel()->transaction_mutex.AssertAcquired(); |
91 DCHECK(!mutations.Get().empty()); | 92 DCHECK(!mutations.Get().empty()); |
92 | 93 |
93 WriteTransactionInfo write_transaction_info( | 94 WriteTransactionInfo write_transaction_info( |
94 directory_->kernel()->next_write_transaction_id, | 95 directory_->kernel()->next_write_transaction_id, from_here_, writer_, |
95 from_here_, writer_, mutations); | 96 mutations); |
96 ++directory_->kernel()->next_write_transaction_id; | 97 ++directory_->kernel()->next_write_transaction_id; |
97 | 98 |
98 ImmutableWriteTransactionInfo immutable_write_transaction_info( | 99 ImmutableWriteTransactionInfo immutable_write_transaction_info( |
99 &write_transaction_info); | 100 &write_transaction_info); |
100 DirectoryChangeDelegate* const delegate = directory_->kernel()->delegate; | 101 DirectoryChangeDelegate* const delegate = directory_->kernel()->delegate; |
101 std::vector<int64_t> entry_changed; | 102 std::vector<int64_t> entry_changed; |
102 if (writer_ == syncable::SYNCAPI) { | 103 if (writer_ == syncable::SYNCAPI) { |
103 delegate->HandleCalculateChangesChangeEventFromSyncApi( | 104 delegate->HandleCalculateChangesChangeEventFromSyncApi( |
104 immutable_write_transaction_info, this, &entry_changed); | 105 immutable_write_transaction_info, this, &entry_changed); |
105 } else { | 106 } else { |
106 delegate->HandleCalculateChangesChangeEventFromSyncer( | 107 delegate->HandleCalculateChangesChangeEventFromSyncer( |
107 immutable_write_transaction_info, this, &entry_changed); | 108 immutable_write_transaction_info, this, &entry_changed); |
108 } | 109 } |
109 UpdateTransactionVersion(entry_changed); | 110 UpdateTransactionVersion(entry_changed); |
110 | 111 |
111 ModelTypeSet models_with_changes = | 112 ModelTypeSet models_with_changes = |
112 delegate->HandleTransactionEndingChangeEvent( | 113 delegate->HandleTransactionEndingChangeEvent( |
113 immutable_write_transaction_info, this); | 114 immutable_write_transaction_info, this); |
114 | 115 |
115 directory_->kernel()->transaction_observer.Call(FROM_HERE, | 116 directory_->kernel()->transaction_observer.Call( |
116 &TransactionObserver::OnTransactionWrite, | 117 FROM_HERE, &TransactionObserver::OnTransactionWrite, |
117 immutable_write_transaction_info, models_with_changes); | 118 immutable_write_transaction_info, models_with_changes); |
118 | 119 |
119 return models_with_changes; | 120 return models_with_changes; |
120 } | 121 } |
121 | 122 |
122 void WriteTransaction::NotifyTransactionComplete( | 123 void WriteTransaction::NotifyTransactionComplete( |
123 ModelTypeSet models_with_changes) { | 124 ModelTypeSet models_with_changes) { |
124 directory_->kernel()->delegate->HandleTransactionCompleteChangeEvent( | 125 directory_->kernel()->delegate->HandleTransactionCompleteChangeEvent( |
125 models_with_changes); | 126 models_with_changes); |
126 } | 127 } |
(...skipping 10 matching lines...) Expand all Loading... |
137 if (!type_seen.Has(type)) { | 138 if (!type_seen.Has(type)) { |
138 directory_->IncrementTransactionVersion(type); | 139 directory_->IncrementTransactionVersion(type); |
139 type_seen.Put(type); | 140 type_seen.Put(type); |
140 } | 141 } |
141 entry.UpdateTransactionVersion(directory_->GetTransactionVersion(type)); | 142 entry.UpdateTransactionVersion(directory_->GetTransactionVersion(type)); |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 if (!type_seen.Empty() && transaction_version_) { | 146 if (!type_seen.Empty() && transaction_version_) { |
146 DCHECK_EQ(1u, type_seen.Size()); | 147 DCHECK_EQ(1u, type_seen.Size()); |
147 *transaction_version_ = directory_->GetTransactionVersion( | 148 *transaction_version_ = |
148 type_seen.First().Get()); | 149 directory_->GetTransactionVersion(type_seen.First().Get()); |
149 } | 150 } |
150 } | 151 } |
151 | 152 |
152 WriteTransaction::~WriteTransaction() { | 153 WriteTransaction::~WriteTransaction() { |
153 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); | 154 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); |
154 | 155 |
155 MetahandleSet modified_handles; | 156 MetahandleSet modified_handles; |
156 for (EntryKernelMutationMap::const_iterator i = mutations.Get().begin(); | 157 for (EntryKernelMutationMap::const_iterator i = mutations.Get().begin(); |
157 i != mutations.Get().end(); ++i) { | 158 i != mutations.Get().end(); ++i) { |
158 modified_handles.insert(i->first); | 159 modified_handles.insert(i->first); |
159 } | 160 } |
160 directory()->CheckInvariantsOnTransactionClose(this, modified_handles); | 161 directory()->CheckInvariantsOnTransactionClose(this, modified_handles); |
161 | 162 |
162 // |CheckTreeInvariants| could have thrown an unrecoverable error. | 163 // |CheckTreeInvariants| could have thrown an unrecoverable error. |
163 if (unrecoverable_error_set_) { | 164 if (unrecoverable_error_set_) { |
164 HandleUnrecoverableErrorIfSet(); | 165 HandleUnrecoverableErrorIfSet(); |
165 Unlock(); | 166 Unlock(); |
166 return; | 167 return; |
167 } | 168 } |
168 | 169 |
169 UnlockAndNotify(mutations); | 170 UnlockAndNotify(mutations); |
170 } | 171 } |
171 | 172 |
172 #define ENUM_CASE(x) case x: return #x; break | 173 #define ENUM_CASE(x) \ |
| 174 case x: \ |
| 175 return #x; \ |
| 176 break |
173 | 177 |
174 std::string WriterTagToString(WriterTag writer_tag) { | 178 std::string WriterTagToString(WriterTag writer_tag) { |
175 switch (writer_tag) { | 179 switch (writer_tag) { |
176 ENUM_CASE(INVALID); | 180 ENUM_CASE(INVALID); |
177 ENUM_CASE(SYNCER); | 181 ENUM_CASE(SYNCER); |
178 ENUM_CASE(AUTHWATCHER); | 182 ENUM_CASE(AUTHWATCHER); |
179 ENUM_CASE(UNITTEST); | 183 ENUM_CASE(UNITTEST); |
180 ENUM_CASE(VACUUM_AFTER_SAVE); | 184 ENUM_CASE(VACUUM_AFTER_SAVE); |
181 ENUM_CASE(HANDLE_SAVE_FAILURE); | 185 ENUM_CASE(HANDLE_SAVE_FAILURE); |
182 ENUM_CASE(PURGE_ENTRIES); | 186 ENUM_CASE(PURGE_ENTRIES); |
183 ENUM_CASE(SYNCAPI); | 187 ENUM_CASE(SYNCAPI); |
184 } | 188 } |
185 NOTREACHED(); | 189 NOTREACHED(); |
186 return std::string(); | 190 return std::string(); |
187 } | 191 } |
188 | 192 |
189 #undef ENUM_CASE | 193 #undef ENUM_CASE |
190 | 194 |
191 } // namespace syncable | 195 } // namespace syncable |
192 } // namespace syncer | 196 } // namespace syncer |
OLD | NEW |