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 "sync/syncable/model_neutral_mutable_entry.h" | 5 #include "sync/syncable/model_neutral_mutable_entry.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, | 25 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, |
26 CreateNewUpdateItem, | 26 CreateNewUpdateItem, |
27 const Id& id) | 27 const Id& id) |
28 : Entry(trans), base_write_transaction_(trans) { | 28 : Entry(trans), base_write_transaction_(trans) { |
29 Entry same_id(trans, GET_BY_ID, id); | 29 Entry same_id(trans, GET_BY_ID, id); |
30 kernel_ = NULL; | 30 kernel_ = NULL; |
31 if (same_id.good()) { | 31 if (same_id.good()) { |
32 return; // already have an item with this ID. | 32 return; // already have an item with this ID. |
33 } | 33 } |
34 scoped_ptr<EntryKernel> kernel(new EntryKernel()); | 34 std::unique_ptr<EntryKernel> kernel(new EntryKernel()); |
35 | 35 |
36 kernel->put(ID, id); | 36 kernel->put(ID, id); |
37 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); | 37 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); |
38 kernel->mark_dirty(&trans->directory()->kernel()->dirty_metahandles); | 38 kernel->mark_dirty(&trans->directory()->kernel()->dirty_metahandles); |
39 kernel->put(IS_DEL, true); | 39 kernel->put(IS_DEL, true); |
40 // We match the database defaults here | 40 // We match the database defaults here |
41 kernel->put(BASE_VERSION, CHANGES_VERSION); | 41 kernel->put(BASE_VERSION, CHANGES_VERSION); |
42 if (!trans->directory()->InsertEntry(trans, kernel.get())) { | 42 if (!trans->directory()->InsertEntry(trans, kernel.get())) { |
43 return; // Failed inserting. | 43 return; // Failed inserting. |
44 } | 44 } |
45 trans->TrackChangesTo(kernel.get()); | 45 trans->TrackChangesTo(kernel.get()); |
46 | 46 |
47 kernel_ = kernel.release(); | 47 kernel_ = kernel.release(); |
48 } | 48 } |
49 | 49 |
50 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, | 50 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans, |
51 CreateNewTypeRoot, | 51 CreateNewTypeRoot, |
52 ModelType type) | 52 ModelType type) |
53 : Entry(trans), base_write_transaction_(trans) { | 53 : Entry(trans), base_write_transaction_(trans) { |
54 // We allow NIGORI because we allow SyncEncryptionHandler to restore a nigori | 54 // We allow NIGORI because we allow SyncEncryptionHandler to restore a nigori |
55 // across Directory instances (see SyncEncryptionHandler::RestoreNigori). | 55 // across Directory instances (see SyncEncryptionHandler::RestoreNigori). |
56 if (type != NIGORI) | 56 if (type != NIGORI) |
57 DCHECK(IsTypeWithClientGeneratedRoot(type)); | 57 DCHECK(IsTypeWithClientGeneratedRoot(type)); |
58 Entry same_type_root(trans, GET_TYPE_ROOT, type); | 58 Entry same_type_root(trans, GET_TYPE_ROOT, type); |
59 kernel_ = NULL; | 59 kernel_ = NULL; |
60 if (same_type_root.good()) { | 60 if (same_type_root.good()) { |
61 return; // already have a type root for the given type | 61 return; // already have a type root for the given type |
62 } | 62 } |
63 | 63 |
64 scoped_ptr<EntryKernel> kernel(new EntryKernel()); | 64 std::unique_ptr<EntryKernel> kernel(new EntryKernel()); |
65 | 65 |
66 sync_pb::EntitySpecifics specifics; | 66 sync_pb::EntitySpecifics specifics; |
67 AddDefaultFieldValue(type, &specifics); | 67 AddDefaultFieldValue(type, &specifics); |
68 kernel->put(SPECIFICS, specifics); | 68 kernel->put(SPECIFICS, specifics); |
69 | 69 |
70 kernel->put(ID, | 70 kernel->put(ID, |
71 syncable::Id::CreateFromClientString(ModelTypeToString(type))); | 71 syncable::Id::CreateFromClientString(ModelTypeToString(type))); |
72 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); | 72 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); |
73 kernel->put(PARENT_ID, syncable::Id::GetRoot()); | 73 kernel->put(PARENT_ID, syncable::Id::GetRoot()); |
74 kernel->put(BASE_VERSION, CHANGES_VERSION); | 74 kernel->put(BASE_VERSION, CHANGES_VERSION); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) | 457 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) |
458 : Entry(trans), base_write_transaction_(trans) {} | 458 : Entry(trans), base_write_transaction_(trans) {} |
459 | 459 |
460 void ModelNeutralMutableEntry::MarkDirty() { | 460 void ModelNeutralMutableEntry::MarkDirty() { |
461 kernel_->mark_dirty(&dir()->kernel()->dirty_metahandles); | 461 kernel_->mark_dirty(&dir()->kernel()->dirty_metahandles); |
462 } | 462 } |
463 | 463 |
464 } // namespace syncable | 464 } // namespace syncable |
465 | 465 |
466 } // namespace syncer | 466 } // namespace syncer |
OLD | NEW |