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/mutable_entry.h" | 5 #include "sync/syncable/mutable_entry.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "sync/syncable/directory.h" | 8 #include "sync/syncable/directory.h" |
9 #include "sync/syncable/scoped_index_updater.h" | 9 #include "sync/syncable/scoped_index_updater.h" |
10 #include "sync/syncable/scoped_kernel_lock.h" | 10 #include "sync/syncable/scoped_kernel_lock.h" |
11 #include "sync/syncable/syncable-inl.h" | 11 #include "sync/syncable/syncable-inl.h" |
12 #include "sync/syncable/syncable_changes_version.h" | 12 #include "sync/syncable/syncable_changes_version.h" |
13 #include "sync/syncable/syncable_util.h" | 13 #include "sync/syncable/syncable_util.h" |
14 #include "sync/syncable/write_transaction.h" | 14 #include "sync/syncable/write_transaction.h" |
15 | 15 |
16 using std::string; | 16 using std::string; |
17 | 17 |
18 namespace syncer { | 18 namespace syncer { |
19 namespace syncable { | 19 namespace syncable { |
20 | 20 |
21 MutableEntry::MutableEntry(WriteTransaction* trans, Create, | 21 MutableEntry::MutableEntry(WriteTransaction* trans, Create, |
22 const Id& parent_id, const string& name) | 22 const Id& parent_id, const string& name) |
23 : Entry(trans), | 23 : Entry(trans), |
24 write_transaction_(trans) { | 24 write_transaction_(trans) { |
25 Init(trans, parent_id, name); | 25 Init(trans, parent_id, name); |
26 } | 26 } |
27 | 27 |
28 | 28 |
29 void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id, | 29 void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id, |
rlarocque
2012/10/05 19:02:55
If we decide that the NodeOrdinal's default constr
| |
30 const string& name) { | 30 const string& name) { |
31 scoped_ptr<EntryKernel> kernel(new EntryKernel); | 31 scoped_ptr<EntryKernel> kernel(new EntryKernel); |
32 kernel_ = NULL; | 32 kernel_ = NULL; |
33 | 33 |
34 kernel->put(ID, trans->directory_->NextId()); | 34 kernel->put(ID, trans->directory_->NextId()); |
35 kernel->put(META_HANDLE, trans->directory_->NextMetahandle()); | 35 kernel->put(META_HANDLE, trans->directory_->NextMetahandle()); |
36 kernel->mark_dirty(trans->directory_->kernel_->dirty_metahandles); | 36 kernel->mark_dirty(trans->directory_->kernel_->dirty_metahandles); |
37 kernel->put(PARENT_ID, parent_id); | 37 kernel->put(PARENT_ID, parent_id); |
38 kernel->put(NON_UNIQUE_NAME, name); | 38 kernel->put(NON_UNIQUE_NAME, name); |
39 const base::Time& now = base::Time::Now(); | 39 const base::Time& now = base::Time::Now(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 if (!is_del) | 134 if (!is_del) |
135 // Restores position to the 0th index. | 135 // Restores position to the 0th index. |
136 if (!PutPredecessor(Id())) { | 136 if (!PutPredecessor(Id())) { |
137 // TODO(lipalani) : Propagate the error to caller. crbug.com/100444. | 137 // TODO(lipalani) : Propagate the error to caller. crbug.com/100444. |
138 NOTREACHED(); | 138 NOTREACHED(); |
139 } | 139 } |
140 | 140 |
141 return true; | 141 return true; |
142 } | 142 } |
143 | 143 |
144 bool MutableEntry::Put(Int64Field field, const int64& value) { | 144 bool MutableEntry::Put(OrdinalField field, const NodeOrdinal& value) { |
145 DCHECK(kernel_); | 145 DCHECK(kernel_); |
146 write_transaction_->SaveOriginal(kernel_); | 146 write_transaction_->SaveOriginal(kernel_); |
147 if (kernel_->ref(field) != value) { | 147 if(!kernel_->ref(field).Equals(value)) { |
148 ScopedKernelLock lock(dir()); | 148 ScopedKernelLock lock(dir()); |
149 if (SERVER_POSITION_IN_PARENT == field) { | 149 if (SERVER_ORDINAL_IN_PARENT == field) { |
150 ScopedIndexUpdater<ParentIdAndHandleIndexer> updater(lock, kernel_, | 150 ScopedIndexUpdater<ParentIdAndHandleIndexer> updater( |
151 dir()->kernel_->parent_id_child_index); | 151 lock, kernel_, dir()->kernel_->parent_id_child_index); |
152 kernel_->put(field, value); | 152 kernel_->put(field, value); |
153 } else { | 153 } else { |
154 kernel_->put(field, value); | 154 kernel_->put(field, value); |
155 } | 155 } |
156 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 156 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
157 } | 157 } |
158 return true; | 158 return true; |
159 } | 159 } |
160 | 160 |
161 bool MutableEntry::Put(Int64Field field, const int64& value) { | |
162 DCHECK(kernel_); | |
163 write_transaction_->SaveOriginal(kernel_); | |
164 if (kernel_->ref(field) != value) { | |
165 ScopedKernelLock lock(dir()); | |
166 kernel_->put(field, value); | |
167 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | |
168 } | |
169 return true; | |
170 } | |
171 | |
161 bool MutableEntry::Put(TimeField field, const base::Time& value) { | 172 bool MutableEntry::Put(TimeField field, const base::Time& value) { |
162 DCHECK(kernel_); | 173 DCHECK(kernel_); |
163 write_transaction_->SaveOriginal(kernel_); | 174 write_transaction_->SaveOriginal(kernel_); |
164 if (kernel_->ref(field) != value) { | 175 if (kernel_->ref(field) != value) { |
165 kernel_->put(field, value); | 176 kernel_->put(field, value); |
166 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); | 177 kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
167 } | 178 } |
168 return true; | 179 return true; |
169 } | 180 } |
170 | 181 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 DCHECK_NE(static_cast<MutableEntry*>(NULL), e); | 422 DCHECK_NE(static_cast<MutableEntry*>(NULL), e); |
412 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; | 423 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; |
413 if (!(e->Put(IS_UNSYNCED, true))) | 424 if (!(e->Put(IS_UNSYNCED, true))) |
414 return false; | 425 return false; |
415 e->Put(SYNCING, false); | 426 e->Put(SYNCING, false); |
416 return true; | 427 return true; |
417 } | 428 } |
418 | 429 |
419 } // namespace syncable | 430 } // namespace syncable |
420 } // namespace syncer | 431 } // namespace syncer |
OLD | NEW |