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 "sync/syncable/syncable_write_transaction.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "sync/syncable/directory.h" | 11 #include "sync/syncable/directory.h" |
10 #include "sync/syncable/directory_change_delegate.h" | 12 #include "sync/syncable/directory_change_delegate.h" |
11 #include "sync/syncable/mutable_entry.h" | 13 #include "sync/syncable/mutable_entry.h" |
12 #include "sync/syncable/transaction_observer.h" | 14 #include "sync/syncable/transaction_observer.h" |
13 #include "sync/syncable/write_transaction_info.h" | 15 #include "sync/syncable/write_transaction_info.h" |
14 | 16 |
15 namespace syncer { | 17 namespace syncer { |
16 namespace syncable { | 18 namespace syncable { |
17 | 19 |
18 const int64 kInvalidTransactionVersion = -1; | 20 const int64_t kInvalidTransactionVersion = -1; |
19 | 21 |
20 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, | 22 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, |
21 WriterTag writer, Directory* directory) | 23 WriterTag writer, Directory* directory) |
22 : BaseWriteTransaction(location, "WriteTransaction", writer, directory), | 24 : BaseWriteTransaction(location, "WriteTransaction", writer, directory), |
23 transaction_version_(NULL) { | 25 transaction_version_(NULL) { |
24 Lock(); | 26 Lock(); |
25 } | 27 } |
26 | 28 |
27 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, | 29 WriteTransaction::WriteTransaction(const tracked_objects::Location& location, |
28 Directory* directory, | 30 Directory* directory, |
29 int64* transaction_version) | 31 int64_t* transaction_version) |
30 : BaseWriteTransaction(location, "WriteTransaction", SYNCAPI, directory), | 32 : BaseWriteTransaction(location, "WriteTransaction", SYNCAPI, directory), |
31 transaction_version_(transaction_version) { | 33 transaction_version_(transaction_version) { |
32 Lock(); | 34 Lock(); |
33 if (transaction_version_) | 35 if (transaction_version_) |
34 *transaction_version_ = kInvalidTransactionVersion; | 36 *transaction_version_ = kInvalidTransactionVersion; |
35 } | 37 } |
36 | 38 |
37 void WriteTransaction::TrackChangesTo(const EntryKernel* entry) { | 39 void WriteTransaction::TrackChangesTo(const EntryKernel* entry) { |
38 if (!entry) { | 40 if (!entry) { |
39 return; | 41 return; |
40 } | 42 } |
41 // Insert only if it's not already there. | 43 // Insert only if it's not already there. |
42 const int64 handle = entry->ref(META_HANDLE); | 44 const int64_t handle = entry->ref(META_HANDLE); |
43 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); | 45 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); |
44 if (it == mutations_.end() || it->first != handle) { | 46 if (it == mutations_.end() || it->first != handle) { |
45 mutations_[handle].original = *entry; | 47 mutations_[handle].original = *entry; |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 ImmutableEntryKernelMutationMap WriteTransaction::RecordMutations() { | 51 ImmutableEntryKernelMutationMap WriteTransaction::RecordMutations() { |
50 directory_->kernel()->transaction_mutex.AssertAcquired(); | 52 directory_->kernel()->transaction_mutex.AssertAcquired(); |
51 for (syncable::EntryKernelMutationMap::iterator it = mutations_.begin(); | 53 for (syncable::EntryKernelMutationMap::iterator it = mutations_.begin(); |
52 it != mutations_.end();) { | 54 it != mutations_.end();) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 DCHECK(!mutations.Get().empty()); | 91 DCHECK(!mutations.Get().empty()); |
90 | 92 |
91 WriteTransactionInfo write_transaction_info( | 93 WriteTransactionInfo write_transaction_info( |
92 directory_->kernel()->next_write_transaction_id, | 94 directory_->kernel()->next_write_transaction_id, |
93 from_here_, writer_, mutations); | 95 from_here_, writer_, mutations); |
94 ++directory_->kernel()->next_write_transaction_id; | 96 ++directory_->kernel()->next_write_transaction_id; |
95 | 97 |
96 ImmutableWriteTransactionInfo immutable_write_transaction_info( | 98 ImmutableWriteTransactionInfo immutable_write_transaction_info( |
97 &write_transaction_info); | 99 &write_transaction_info); |
98 DirectoryChangeDelegate* const delegate = directory_->kernel()->delegate; | 100 DirectoryChangeDelegate* const delegate = directory_->kernel()->delegate; |
99 std::vector<int64> entry_changed; | 101 std::vector<int64_t> entry_changed; |
100 if (writer_ == syncable::SYNCAPI) { | 102 if (writer_ == syncable::SYNCAPI) { |
101 delegate->HandleCalculateChangesChangeEventFromSyncApi( | 103 delegate->HandleCalculateChangesChangeEventFromSyncApi( |
102 immutable_write_transaction_info, this, &entry_changed); | 104 immutable_write_transaction_info, this, &entry_changed); |
103 } else { | 105 } else { |
104 delegate->HandleCalculateChangesChangeEventFromSyncer( | 106 delegate->HandleCalculateChangesChangeEventFromSyncer( |
105 immutable_write_transaction_info, this, &entry_changed); | 107 immutable_write_transaction_info, this, &entry_changed); |
106 } | 108 } |
107 UpdateTransactionVersion(entry_changed); | 109 UpdateTransactionVersion(entry_changed); |
108 | 110 |
109 ModelTypeSet models_with_changes = | 111 ModelTypeSet models_with_changes = |
110 delegate->HandleTransactionEndingChangeEvent( | 112 delegate->HandleTransactionEndingChangeEvent( |
111 immutable_write_transaction_info, this); | 113 immutable_write_transaction_info, this); |
112 | 114 |
113 directory_->kernel()->transaction_observer.Call(FROM_HERE, | 115 directory_->kernel()->transaction_observer.Call(FROM_HERE, |
114 &TransactionObserver::OnTransactionWrite, | 116 &TransactionObserver::OnTransactionWrite, |
115 immutable_write_transaction_info, models_with_changes); | 117 immutable_write_transaction_info, models_with_changes); |
116 | 118 |
117 return models_with_changes; | 119 return models_with_changes; |
118 } | 120 } |
119 | 121 |
120 void WriteTransaction::NotifyTransactionComplete( | 122 void WriteTransaction::NotifyTransactionComplete( |
121 ModelTypeSet models_with_changes) { | 123 ModelTypeSet models_with_changes) { |
122 directory_->kernel()->delegate->HandleTransactionCompleteChangeEvent( | 124 directory_->kernel()->delegate->HandleTransactionCompleteChangeEvent( |
123 models_with_changes); | 125 models_with_changes); |
124 } | 126 } |
125 | 127 |
126 void WriteTransaction::UpdateTransactionVersion( | 128 void WriteTransaction::UpdateTransactionVersion( |
127 const std::vector<int64>& entry_changed) { | 129 const std::vector<int64_t>& entry_changed) { |
128 syncer::ModelTypeSet type_seen; | 130 syncer::ModelTypeSet type_seen; |
129 for (uint32 i = 0; i < entry_changed.size(); ++i) { | 131 for (uint32_t i = 0; i < entry_changed.size(); ++i) { |
130 MutableEntry entry(this, GET_BY_HANDLE, entry_changed[i]); | 132 MutableEntry entry(this, GET_BY_HANDLE, entry_changed[i]); |
131 if (entry.good()) { | 133 if (entry.good()) { |
132 ModelType type = GetModelTypeFromSpecifics(entry.GetSpecifics()); | 134 ModelType type = GetModelTypeFromSpecifics(entry.GetSpecifics()); |
133 if (type < FIRST_REAL_MODEL_TYPE) | 135 if (type < FIRST_REAL_MODEL_TYPE) |
134 continue; | 136 continue; |
135 if (!type_seen.Has(type)) { | 137 if (!type_seen.Has(type)) { |
136 directory_->IncrementTransactionVersion(type); | 138 directory_->IncrementTransactionVersion(type); |
137 type_seen.Put(type); | 139 type_seen.Put(type); |
138 } | 140 } |
139 entry.UpdateTransactionVersion(directory_->GetTransactionVersion(type)); | 141 entry.UpdateTransactionVersion(directory_->GetTransactionVersion(type)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ENUM_CASE(SYNCAPI); | 183 ENUM_CASE(SYNCAPI); |
182 } | 184 } |
183 NOTREACHED(); | 185 NOTREACHED(); |
184 return std::string(); | 186 return std::string(); |
185 } | 187 } |
186 | 188 |
187 #undef ENUM_CASE | 189 #undef ENUM_CASE |
188 | 190 |
189 } // namespace syncable | 191 } // namespace syncable |
190 } // namespace syncer | 192 } // namespace syncer |
OLD | NEW |