| 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 #ifndef SYNC_SYNCABLE_MUTABLE_ENTRY_H_ | 5 #ifndef SYNC_SYNCABLE_MUTABLE_ENTRY_H_ |
| 6 #define SYNC_SYNCABLE_MUTABLE_ENTRY_H_ | 6 #define SYNC_SYNCABLE_MUTABLE_ENTRY_H_ |
| 7 | 7 |
| 8 #include "sync/internal_api/public/base/node_ordinal.h" | 8 #include "sync/internal_api/public/base/model_type.h" |
| 9 #include "sync/syncable/entry.h" | 9 #include "sync/syncable/entry.h" |
| 10 #include "sync/syncable/metahandle_set.h" | 10 #include "sync/syncable/metahandle_set.h" |
| 11 | 11 |
| 12 namespace syncer { | 12 namespace syncer { |
| 13 class WriteNode; | 13 class WriteNode; |
| 14 | 14 |
| 15 namespace syncable { | 15 namespace syncable { |
| 16 | 16 |
| 17 class WriteTransaction; | 17 class WriteTransaction; |
| 18 | 18 |
| 19 enum Create { | 19 enum CreateBookmark { |
| 20 CREATE | 20 CREATE_BOOKMARK |
| 21 }; |
| 22 |
| 23 enum CreateUnique { |
| 24 CREATE_UNIQUE |
| 21 }; | 25 }; |
| 22 | 26 |
| 23 enum CreateNewUpdateItem { | 27 enum CreateNewUpdateItem { |
| 24 CREATE_NEW_UPDATE_ITEM | 28 CREATE_NEW_UPDATE_ITEM |
| 25 }; | 29 }; |
| 26 | 30 |
| 27 // A mutable meta entry. Changes get committed to the database when the | 31 // A mutable meta entry. Changes get committed to the database when the |
| 28 // WriteTransaction is destroyed. | 32 // WriteTransaction is destroyed. |
| 29 class MutableEntry : public Entry { | 33 class MutableEntry : public Entry { |
| 30 void Init(WriteTransaction* trans, const Id& parent_id, | 34 void Init(WriteTransaction* trans, ModelType model_type, |
| 31 const std::string& name); | 35 const Id& parent_id, const std::string& name); |
| 32 | |
| 33 public: | 36 public: |
| 34 MutableEntry(WriteTransaction* trans, Create, const Id& parent_id, | 37 MutableEntry(WriteTransaction* trans, CreateBookmark, |
| 35 const std::string& name); | 38 const Id& parent_id, const std::string& name); |
| 39 MutableEntry(WriteTransaction* trans, CreateUnique, ModelType model_type, |
| 40 const Id& parent_id, const std::string& name); |
| 36 MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id); | 41 MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id); |
| 37 MutableEntry(WriteTransaction* trans, GetByHandle, int64); | 42 MutableEntry(WriteTransaction* trans, GetByHandle, int64); |
| 38 MutableEntry(WriteTransaction* trans, GetById, const Id&); | 43 MutableEntry(WriteTransaction* trans, GetById, const Id&); |
| 39 MutableEntry(WriteTransaction* trans, GetByClientTag, const std::string& tag); | 44 MutableEntry(WriteTransaction* trans, GetByClientTag, const std::string& tag); |
| 40 MutableEntry(WriteTransaction* trans, GetByServerTag, const std::string& tag); | 45 MutableEntry(WriteTransaction* trans, GetByServerTag, const std::string& tag); |
| 41 | 46 |
| 42 inline WriteTransaction* write_transaction() const { | 47 inline WriteTransaction* write_transaction() const { |
| 43 return write_transaction_; | 48 return write_transaction_; |
| 44 } | 49 } |
| 45 | 50 |
| 46 // Field Accessors. Some of them trigger the re-indexing of the entry. | 51 // Field Accessors. Some of them trigger the re-indexing of the entry. |
| 47 // Return true on success, return false on failure, which means | 52 // Return true on success, return false on failure, which means |
| 48 // that putting the value would have caused a duplicate in the index. | 53 // that putting the value would have caused a duplicate in the index. |
| 49 // TODO(chron): Remove some of these unecessary return values. | 54 // TODO(chron): Remove some of these unecessary return values. |
| 50 bool Put(Int64Field field, const int64& value); | 55 bool Put(Int64Field field, const int64& value); |
| 51 bool Put(TimeField field, const base::Time& value); | 56 bool Put(TimeField field, const base::Time& value); |
| 52 bool Put(IdField field, const Id& value); | 57 bool Put(IdField field, const Id& value); |
| 53 bool Put(OrdinalField field, const NodeOrdinal& value); | 58 bool Put(UniquePositionField field, const UniquePosition& value); |
| 54 | 59 |
| 55 // Do a simple property-only update if the PARENT_ID field. Use with caution. | 60 // Do a simple property-only update if the PARENT_ID field. Use with caution. |
| 56 // | 61 // |
| 57 // The normal Put(IS_PARENT) call will move the item to the front of the | 62 // The normal Put(IS_PARENT) call will move the item to the front of the |
| 58 // sibling order to maintain the linked list invariants when the parent | 63 // sibling order to maintain the linked list invariants when the parent |
| 59 // changes. That's usually what you want to do, but it's inappropriate | 64 // changes. That's usually what you want to do, but it's inappropriate |
| 60 // when the caller is trying to change the parent ID of a the whole set | 65 // when the caller is trying to change the parent ID of a the whole set |
| 61 // of children (e.g. because the ID changed during a commit). For those | 66 // of children (e.g. because the ID changed during a commit). For those |
| 62 // cases, there's this function. It will corrupt the sibling ordering | 67 // cases, there's this function. It will corrupt the sibling ordering |
| 63 // if you're not careful. | 68 // if you're not careful. |
| 64 void PutParentIdPropertyOnly(const Id& parent_id); | 69 void PutParentIdPropertyOnly(const Id& parent_id); |
| 65 | 70 |
| 66 bool Put(StringField field, const std::string& value); | 71 bool Put(StringField field, const std::string& value); |
| 67 bool Put(BaseVersion field, int64 value); | 72 bool Put(BaseVersion field, int64 value); |
| 68 | 73 |
| 69 bool Put(ProtoField field, const sync_pb::EntitySpecifics& value); | 74 bool Put(ProtoField field, const sync_pb::EntitySpecifics& value); |
| 70 bool Put(BitField field, bool value); | 75 bool Put(BitField field, bool value); |
| 71 inline bool Put(IsDelField field, bool value) { | 76 inline bool Put(IsDelField field, bool value) { |
| 72 return PutIsDel(value); | 77 return PutIsDel(value); |
| 73 } | 78 } |
| 74 bool Put(IndexedBitField field, bool value); | 79 bool Put(IndexedBitField field, bool value); |
| 75 | 80 |
| 81 void PutUniqueBookmarkTag(const std::string& tag); |
| 82 |
| 76 // Sets the position of this item, and updates the entry kernels of the | 83 // Sets the position of this item, and updates the entry kernels of the |
| 77 // adjacent siblings so that list invariants are maintained. Returns false | 84 // adjacent siblings so that list invariants are maintained. Returns false |
| 78 // and fails if |predecessor_id| does not identify a sibling. Pass the root | 85 // and fails if |predecessor_id| does not identify a sibling. Pass the root |
| 79 // ID to put the node in first position. | 86 // ID to put the node in first position. |
| 80 bool PutPredecessor(const Id& predecessor_id); | 87 bool PutPredecessor(const Id& predecessor_id); |
| 81 | 88 |
| 82 bool Put(BitTemp field, bool value); | 89 bool Put(BitTemp field, bool value); |
| 83 | 90 |
| 84 protected: | 91 protected: |
| 85 syncable::MetahandleSet* GetDirtyIndexHelper(); | 92 syncable::MetahandleSet* GetDirtyIndexHelper(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 111 DISALLOW_COPY_AND_ASSIGN(MutableEntry); | 118 DISALLOW_COPY_AND_ASSIGN(MutableEntry); |
| 112 }; | 119 }; |
| 113 | 120 |
| 114 // This function sets only the flags needed to get this entry to sync. | 121 // This function sets only the flags needed to get this entry to sync. |
| 115 bool MarkForSyncing(syncable::MutableEntry* e); | 122 bool MarkForSyncing(syncable::MutableEntry* e); |
| 116 | 123 |
| 117 } // namespace syncable | 124 } // namespace syncable |
| 118 } // namespace syncer | 125 } // namespace syncer |
| 119 | 126 |
| 120 #endif // SYNC_SYNCABLE_MUTABLE_ENTRY_H_ | 127 #endif // SYNC_SYNCABLE_MUTABLE_ENTRY_H_ |
| OLD | NEW |