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 "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/mutable_entry.h" |
10 #include "sync/syncable/transaction_observer.h" | 10 #include "sync/syncable/transaction_observer.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 // Insert only if it's not already there. | 39 // Insert only if it's not already there. |
40 const int64 handle = entry->ref(META_HANDLE); | 40 const int64 handle = entry->ref(META_HANDLE); |
41 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); | 41 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); |
42 if (it == mutations_.end() || it->first != handle) { | 42 if (it == mutations_.end() || it->first != handle) { |
43 mutations_[handle].original = *entry; | 43 mutations_[handle].original = *entry; |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 ImmutableEntryKernelMutationMap WriteTransaction::RecordMutations() { | 47 ImmutableEntryKernelMutationMap WriteTransaction::RecordMutations() { |
48 directory_->kernel_->transaction_mutex.AssertAcquired(); | 48 directory_->kernel()->transaction_mutex.AssertAcquired(); |
49 for (syncable::EntryKernelMutationMap::iterator it = mutations_.begin(); | 49 for (syncable::EntryKernelMutationMap::iterator it = mutations_.begin(); |
50 it != mutations_.end();) { | 50 it != mutations_.end();) { |
51 EntryKernel* kernel = directory()->GetEntryByHandle(it->first); | 51 EntryKernel* kernel = directory()->GetEntryByHandle(it->first); |
52 if (!kernel) { | 52 if (!kernel) { |
53 NOTREACHED(); | 53 NOTREACHED(); |
54 continue; | 54 continue; |
55 } | 55 } |
56 if (kernel->is_dirty()) { | 56 if (kernel->is_dirty()) { |
57 it->second.mutated = *kernel; | 57 it->second.mutated = *kernel; |
58 ++it; | 58 ++it; |
(...skipping 17 matching lines...) Expand all Loading... |
76 Unlock(); | 76 Unlock(); |
77 | 77 |
78 // Work after mutex is relased. | 78 // Work after mutex is relased. |
79 if (has_mutations) { | 79 if (has_mutations) { |
80 NotifyTransactionComplete(models_with_changes); | 80 NotifyTransactionComplete(models_with_changes); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 ModelTypeSet WriteTransaction::NotifyTransactionChangingAndEnding( | 84 ModelTypeSet WriteTransaction::NotifyTransactionChangingAndEnding( |
85 const ImmutableEntryKernelMutationMap& mutations) { | 85 const ImmutableEntryKernelMutationMap& mutations) { |
86 directory_->kernel_->transaction_mutex.AssertAcquired(); | 86 directory_->kernel()->transaction_mutex.AssertAcquired(); |
87 DCHECK(!mutations.Get().empty()); | 87 DCHECK(!mutations.Get().empty()); |
88 | 88 |
89 WriteTransactionInfo write_transaction_info( | 89 WriteTransactionInfo write_transaction_info( |
90 directory_->kernel_->next_write_transaction_id, | 90 directory_->kernel()->next_write_transaction_id, |
91 from_here_, writer_, mutations); | 91 from_here_, writer_, mutations); |
92 ++directory_->kernel_->next_write_transaction_id; | 92 ++directory_->kernel()->next_write_transaction_id; |
93 | 93 |
94 ImmutableWriteTransactionInfo immutable_write_transaction_info( | 94 ImmutableWriteTransactionInfo immutable_write_transaction_info( |
95 &write_transaction_info); | 95 &write_transaction_info); |
96 DirectoryChangeDelegate* const delegate = directory_->kernel_->delegate; | 96 DirectoryChangeDelegate* const delegate = directory_->kernel()->delegate; |
97 std::vector<int64> entry_changed; | 97 std::vector<int64> entry_changed; |
98 if (writer_ == syncable::SYNCAPI) { | 98 if (writer_ == syncable::SYNCAPI) { |
99 delegate->HandleCalculateChangesChangeEventFromSyncApi( | 99 delegate->HandleCalculateChangesChangeEventFromSyncApi( |
100 immutable_write_transaction_info, this, &entry_changed); | 100 immutable_write_transaction_info, this, &entry_changed); |
101 } else { | 101 } else { |
102 delegate->HandleCalculateChangesChangeEventFromSyncer( | 102 delegate->HandleCalculateChangesChangeEventFromSyncer( |
103 immutable_write_transaction_info, this, &entry_changed); | 103 immutable_write_transaction_info, this, &entry_changed); |
104 } | 104 } |
105 UpdateTransactionVersion(entry_changed); | 105 UpdateTransactionVersion(entry_changed); |
106 | 106 |
107 ModelTypeSet models_with_changes = | 107 ModelTypeSet models_with_changes = |
108 delegate->HandleTransactionEndingChangeEvent( | 108 delegate->HandleTransactionEndingChangeEvent( |
109 immutable_write_transaction_info, this); | 109 immutable_write_transaction_info, this); |
110 | 110 |
111 directory_->kernel_->transaction_observer.Call(FROM_HERE, | 111 directory_->kernel()->transaction_observer.Call(FROM_HERE, |
112 &TransactionObserver::OnTransactionWrite, | 112 &TransactionObserver::OnTransactionWrite, |
113 immutable_write_transaction_info, models_with_changes); | 113 immutable_write_transaction_info, models_with_changes); |
114 | 114 |
115 return models_with_changes; | 115 return models_with_changes; |
116 } | 116 } |
117 | 117 |
118 void WriteTransaction::NotifyTransactionComplete( | 118 void WriteTransaction::NotifyTransactionComplete( |
119 ModelTypeSet models_with_changes) { | 119 ModelTypeSet models_with_changes) { |
120 directory_->kernel_->delegate->HandleTransactionCompleteChangeEvent( | 120 directory_->kernel()->delegate->HandleTransactionCompleteChangeEvent( |
121 models_with_changes); | 121 models_with_changes); |
122 } | 122 } |
123 | 123 |
124 void WriteTransaction::UpdateTransactionVersion( | 124 void WriteTransaction::UpdateTransactionVersion( |
125 const std::vector<int64>& entry_changed) { | 125 const std::vector<int64>& entry_changed) { |
126 syncer::ModelTypeSet type_seen; | 126 syncer::ModelTypeSet type_seen; |
127 for (uint32 i = 0; i < entry_changed.size(); ++i) { | 127 for (uint32 i = 0; i < entry_changed.size(); ++i) { |
128 MutableEntry entry(this, GET_BY_HANDLE, entry_changed[i]); | 128 MutableEntry entry(this, GET_BY_HANDLE, entry_changed[i]); |
129 if (entry.good()) { | 129 if (entry.good()) { |
130 ModelType type = GetModelTypeFromSpecifics(entry.GetSpecifics()); | 130 ModelType type = GetModelTypeFromSpecifics(entry.GetSpecifics()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 ENUM_CASE(SYNCAPI); | 179 ENUM_CASE(SYNCAPI); |
180 }; | 180 }; |
181 NOTREACHED(); | 181 NOTREACHED(); |
182 return std::string(); | 182 return std::string(); |
183 } | 183 } |
184 | 184 |
185 #undef ENUM_CASE | 185 #undef ENUM_CASE |
186 | 186 |
187 } // namespace syncable | 187 } // namespace syncable |
188 } // namespace syncer | 188 } // namespace syncer |
OLD | NEW |