| 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 "components/sync/syncable/mutable_entry.h" | 5 #include "components/sync/syncable/mutable_entry.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "components/sync/base/unique_position.h" | 9 #include "components/sync/base/unique_position.h" |
| 10 #include "components/sync/syncable/directory.h" | 10 #include "components/sync/syncable/directory.h" |
| 11 #include "components/sync/syncable/scoped_kernel_lock.h" | 11 #include "components/sync/syncable/scoped_kernel_lock.h" |
| 12 #include "components/sync/syncable/scoped_parent_child_index_updater.h" | 12 #include "components/sync/syncable/scoped_parent_child_index_updater.h" |
| 13 #include "components/sync/syncable/syncable_changes_version.h" | 13 #include "components/sync/syncable/syncable_changes_version.h" |
| 14 #include "components/sync/syncable/syncable_util.h" | 14 #include "components/sync/syncable/syncable_util.h" |
| 15 #include "components/sync/syncable/syncable_write_transaction.h" | 15 #include "components/sync/syncable/syncable_write_transaction.h" |
| 16 | 16 |
| 17 using std::string; | 17 using std::string; |
| 18 | 18 |
| 19 namespace syncer { | 19 namespace syncer { |
| 20 namespace syncable { | 20 namespace syncable { |
| 21 | 21 |
| 22 void MutableEntry::Init(WriteTransaction* trans, | 22 void MutableEntry::Init(WriteTransaction* trans, |
| 23 ModelType model_type, | 23 ModelType model_type, |
| 24 const Id& parent_id, | 24 const Id& parent_id, |
| 25 const string& name) { | 25 const string& name) { |
| 26 std::unique_ptr<EntryKernel> kernel(new EntryKernel); | 26 std::unique_ptr<EntryKernel> kernel(new EntryKernel); |
| 27 kernel_ = NULL; | 27 kernel_ = nullptr; |
| 28 | 28 |
| 29 kernel->put(ID, trans->directory_->NextId()); | 29 kernel->put(ID, trans->directory_->NextId()); |
| 30 kernel->put(META_HANDLE, trans->directory_->NextMetahandle()); | 30 kernel->put(META_HANDLE, trans->directory_->NextMetahandle()); |
| 31 kernel->mark_dirty(&trans->directory_->kernel()->dirty_metahandles); | 31 kernel->mark_dirty(&trans->directory_->kernel()->dirty_metahandles); |
| 32 kernel->put(NON_UNIQUE_NAME, name); | 32 kernel->put(NON_UNIQUE_NAME, name); |
| 33 const base::Time& now = base::Time::Now(); | 33 const base::Time& now = base::Time::Now(); |
| 34 kernel->put(CTIME, now); | 34 kernel->put(CTIME, now); |
| 35 kernel->put(MTIME, now); | 35 kernel->put(MTIME, now); |
| 36 // We match the database defaults here | 36 // We match the database defaults here |
| 37 kernel->put(BASE_VERSION, CHANGES_VERSION); | 37 kernel->put(BASE_VERSION, CHANGES_VERSION); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ScopedKernelLock lock(dir()); | 243 ScopedKernelLock lock(dir()); |
| 244 ScopedParentChildIndexUpdater updater(lock, kernel_, | 244 ScopedParentChildIndexUpdater updater(lock, kernel_, |
| 245 &dir()->kernel()->parent_child_index); | 245 &dir()->kernel()->parent_child_index); |
| 246 kernel_->put(UNIQUE_POSITION, value); | 246 kernel_->put(UNIQUE_POSITION, value); |
| 247 MarkDirty(); | 247 MarkDirty(); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool MutableEntry::PutPredecessor(const Id& predecessor_id) { | 251 bool MutableEntry::PutPredecessor(const Id& predecessor_id) { |
| 252 if (predecessor_id.IsNull()) { | 252 if (predecessor_id.IsNull()) { |
| 253 dir()->PutPredecessor(kernel_, NULL); | 253 dir()->PutPredecessor(kernel_, nullptr); |
| 254 } else { | 254 } else { |
| 255 MutableEntry predecessor(write_transaction(), GET_BY_ID, predecessor_id); | 255 MutableEntry predecessor(write_transaction(), GET_BY_ID, predecessor_id); |
| 256 if (!predecessor.good()) | 256 if (!predecessor.good()) |
| 257 return false; | 257 return false; |
| 258 dir()->PutPredecessor(kernel_, predecessor.kernel_); | 258 dir()->PutPredecessor(kernel_, predecessor.kernel_); |
| 259 // No need to make the entry dirty here because setting the predecessor | 259 // No need to make the entry dirty here because setting the predecessor |
| 260 // results in PutUniquePosition call (which might or might not make the | 260 // results in PutUniquePosition call (which might or might not make the |
| 261 // entry dirty). | 261 // entry dirty). |
| 262 } | 262 } |
| 263 return true; | 263 return true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 continue; | 298 continue; |
| 299 record->set_is_on_server(true); | 299 record->set_is_on_server(true); |
| 300 } | 300 } |
| 301 kernel_->put(ATTACHMENT_METADATA, attachment_metadata); | 301 kernel_->put(ATTACHMENT_METADATA, attachment_metadata); |
| 302 MarkDirty(); | 302 MarkDirty(); |
| 303 MarkForSyncing(this); | 303 MarkForSyncing(this); |
| 304 } | 304 } |
| 305 | 305 |
| 306 // This function sets only the flags needed to get this entry to sync. | 306 // This function sets only the flags needed to get this entry to sync. |
| 307 bool MarkForSyncing(MutableEntry* e) { | 307 bool MarkForSyncing(MutableEntry* e) { |
| 308 DCHECK_NE(static_cast<MutableEntry*>(NULL), e); | 308 DCHECK_NE(static_cast<MutableEntry*>(nullptr), e); |
| 309 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; | 309 DCHECK(!e->IsRoot()) << "We shouldn't mark a permanent object for syncing."; |
| 310 if (!(e->PutIsUnsynced(true))) | 310 if (!(e->PutIsUnsynced(true))) |
| 311 return false; | 311 return false; |
| 312 if (e->GetSyncing()) | 312 if (e->GetSyncing()) |
| 313 e->PutDirtySync(true); | 313 e->PutDirtySync(true); |
| 314 return true; | 314 return true; |
| 315 } | 315 } |
| 316 | 316 |
| 317 } // namespace syncable | 317 } // namespace syncable |
| 318 } // namespace syncer | 318 } // namespace syncer |
| OLD | NEW |