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 <string> | 7 #include <string> |
8 | 8 |
9 #include "sync/internal_api/public/base/unique_position.h" | 9 #include "sync/internal_api/public/base/unique_position.h" |
10 #include "sync/syncable/directory.h" | 10 #include "sync/syncable/directory.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
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, | |
48 CreateNewTypeRoot, | |
49 ModelType type) | |
50 : Entry(trans), base_write_transaction_(trans) { | |
51 Entry same_type_root(trans, GET_TYPE_ROOT, type); | |
52 kernel_ = NULL; | |
53 if (same_type_root.good()) { | |
54 return; // already have a type root for the given type | |
55 } | |
56 | |
Nicolas Zea
2015/01/26 23:21:53
CHECK that type isn't BOOKMARKS or NIGORI?
stanisc
2015/01/29 00:27:37
Done.
| |
57 scoped_ptr<EntryKernel> kernel(new EntryKernel()); | |
58 | |
59 sync_pb::EntitySpecifics specifics; | |
60 AddDefaultFieldValue(type, &specifics); | |
61 kernel->put(SPECIFICS, specifics); | |
62 | |
63 kernel->put(ID, | |
64 syncable::Id::CreateFromClientString(ModelTypeToString(type))); | |
65 kernel->put(META_HANDLE, trans->directory()->NextMetahandle()); | |
66 kernel->put(PARENT_ID, syncable::Id::GetRoot()); | |
67 kernel->put(BASE_VERSION, CHANGES_VERSION); | |
68 kernel->put(NON_UNIQUE_NAME, ModelTypeToString(type)); | |
69 kernel->put(IS_DIR, true); | |
70 | |
71 kernel->mark_dirty(&trans->directory()->kernel_->dirty_metahandles); | |
72 | |
73 if (!trans->directory()->InsertEntry(trans, kernel.get())) { | |
74 return; // Failed inserting. | |
75 } | |
76 | |
77 trans->TrackChangesTo(kernel.get()); | |
78 | |
79 kernel_ = kernel.release(); | |
80 } | |
81 | |
47 ModelNeutralMutableEntry::ModelNeutralMutableEntry( | 82 ModelNeutralMutableEntry::ModelNeutralMutableEntry( |
48 BaseWriteTransaction* trans, GetById, const Id& id) | 83 BaseWriteTransaction* trans, GetById, const Id& id) |
49 : Entry(trans, GET_BY_ID, id), base_write_transaction_(trans) { | 84 : Entry(trans, GET_BY_ID, id), base_write_transaction_(trans) { |
50 } | 85 } |
51 | 86 |
52 ModelNeutralMutableEntry::ModelNeutralMutableEntry( | 87 ModelNeutralMutableEntry::ModelNeutralMutableEntry( |
53 BaseWriteTransaction* trans, GetByHandle, int64 metahandle) | 88 BaseWriteTransaction* trans, GetByHandle, int64 metahandle) |
54 : Entry(trans, GET_BY_HANDLE, metahandle), base_write_transaction_(trans) { | 89 : Entry(trans, GET_BY_HANDLE, metahandle), base_write_transaction_(trans) { |
55 } | 90 } |
56 | 91 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) | 419 ModelNeutralMutableEntry::ModelNeutralMutableEntry(BaseWriteTransaction* trans) |
385 : Entry(trans), base_write_transaction_(trans) {} | 420 : Entry(trans), base_write_transaction_(trans) {} |
386 | 421 |
387 MetahandleSet* ModelNeutralMutableEntry::GetDirtyIndexHelper() { | 422 MetahandleSet* ModelNeutralMutableEntry::GetDirtyIndexHelper() { |
388 return &dir()->kernel_->dirty_metahandles; | 423 return &dir()->kernel_->dirty_metahandles; |
389 } | 424 } |
390 | 425 |
391 } // namespace syncable | 426 } // namespace syncable |
392 | 427 |
393 } // namespace syncer | 428 } // namespace syncer |
OLD | NEW |