| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/model_neutral_mutable_entry.h" | 5 #include "components/sync/syncable/model_neutral_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/syncable_changes_version.h" | 12 #include "components/sync/syncable/syncable_changes_version.h" |
| 13 #include "components/sync/syncable/syncable_util.h" | 13 #include "components/sync/syncable/syncable_util.h" |
| 14 #include "components/sync/syncable/syncable_write_transaction.h" | 14 #include "components/sync/syncable/syncable_write_transaction.h" |
| 15 | 15 |
| 16 using std::string; | 16 using std::string; |
| 17 | 17 |
| 18 namespace syncer { | 18 namespace syncer { |
| 19 | 19 |
| 20 namespace syncable { | 20 namespace syncable { |
| 21 | 21 |
| 22 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, | 22 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, |
| 23 CreateNewUpdateItem, | 23 CreateNewUpdateItem, |
| 24 const Id& id) | 24 const Id& id) |
| 25 : Entry(trans), base_write_transaction_(trans) { | 25 : Entry(trans), base_write_transaction_(trans) { |
| 26 Entry same_id(trans, GET_BY_ID, id); | 26 Entry same_id(trans, GET_BY_ID, id); |
| 27 kernel_ = NULL; | 27 kernel_ = nullptr; |
| 28 if (same_id.good()) { | 28 if (same_id.good()) { |
| 29 return; // already have an item with this ID. | 29 return; // already have an item with this ID. |
| 30 } | 30 } |
| 31 std::unique_ptr<EntryKernel> kernel(new EntryKernel()); | 31 std::unique_ptr<EntryKernel> kernel(new EntryKernel()); |
| 32 | 32 |
| 33 kernel->put(ID, id); | 33 kernel->put(ID, id); |
| 34 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); | 34 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); |
| 35 kernel->mark_dirty(&trans->directory()->kernel()->dirty_metahandles); | 35 kernel->mark_dirty(&trans->directory()->kernel()->dirty_metahandles); |
| 36 kernel->put(IS_DEL, true); | 36 kernel->put(IS_DEL, true); |
| 37 // We match the database defaults here | 37 // We match the database defaults here |
| 38 kernel->put(BASE_VERSION, CHANGES_VERSION); | 38 kernel->put(BASE_VERSION, CHANGES_VERSION); |
| 39 if (!trans->directory()->InsertEntry(trans, kernel.get())) { | 39 if (!trans->directory()->InsertEntry(trans, kernel.get())) { |
| 40 return; // Failed inserting. | 40 return; // Failed inserting. |
| 41 } | 41 } |
| 42 trans->TrackChangesTo(kernel.get()); | 42 trans->TrackChangesTo(kernel.get()); |
| 43 | 43 |
| 44 kernel_ = kernel.release(); | 44 kernel_ = kernel.release(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, | 47 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, |
| 48 CreateNewTypeRoot, | 48 CreateNewTypeRoot, |
| 49 ModelType type) | 49 ModelType type) |
| 50 : Entry(trans), base_write_transaction_(trans) { | 50 : Entry(trans), base_write_transaction_(trans) { |
| 51 // We allow NIGORI because we allow SyncEncryptionHandler to restore a nigori | 51 // We allow NIGORI because we allow SyncEncryptionHandler to restore a nigori |
| 52 // across Directory instances (see SyncEncryptionHandler::RestoreNigori). | 52 // across Directory instances (see SyncEncryptionHandler::RestoreNigori). |
| 53 if (type != NIGORI) | 53 if (type != NIGORI) |
| 54 DCHECK(IsTypeWithClientGeneratedRoot(type)); | 54 DCHECK(IsTypeWithClientGeneratedRoot(type)); |
| 55 Entry same_type_root(trans, GET_TYPE_ROOT, type); | 55 Entry same_type_root(trans, GET_TYPE_ROOT, type); |
| 56 kernel_ = NULL; | 56 kernel_ = nullptr; |
| 57 if (same_type_root.good()) { | 57 if (same_type_root.good()) { |
| 58 return; // already have a type root for the given type | 58 return; // already have a type root for the given type |
| 59 } | 59 } |
| 60 | 60 |
| 61 std::unique_ptr<EntryKernel> kernel(new EntryKernel()); | 61 std::unique_ptr<EntryKernel> kernel(new EntryKernel()); |
| 62 | 62 |
| 63 sync_pb::EntitySpecifics specifics; | 63 sync_pb::EntitySpecifics specifics; |
| 64 AddDefaultFieldValue(type, &specifics); | 64 AddDefaultFieldValue(type, &specifics); |
| 65 kernel->put(SPECIFICS, specifics); | 65 kernel->put(SPECIFICS, specifics); |
| 66 | 66 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) | 449 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) |
| 450 : Entry(trans), base_write_transaction_(trans) {} | 450 : Entry(trans), base_write_transaction_(trans) {} |
| 451 | 451 |
| 452 void ModelNeutralMutableEntry::MarkDirty() { | 452 void ModelNeutralMutableEntry::MarkDirty() { |
| 453 kernel_->mark_dirty(&dir()->kernel()->dirty_metahandles); | 453 kernel_->mark_dirty(&dir()->kernel()->dirty_metahandles); |
| 454 } | 454 } |
| 455 | 455 |
| 456 } // namespace syncable | 456 } // namespace syncable |
| 457 | 457 |
| 458 } // namespace syncer | 458 } // namespace syncer |
| OLD | NEW |