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 3 // found in the LICENSE file. 4 5 #ifndef SYNC_SYNCABLE_MODEL_NEUTRAL_MUTABLE_ENTRY_H_ 6 #define SYNC_SYNCABLE_MODEL_NEUTRAL_MUTABLE_ENTRY_H_ 7 8 #include "sync/base/sync_export.h" 9 #include "sync/internal_api/public/base/model_type.h" 10 #include "sync/syncable/entry.h" 11 12 namespace syncer { 13 class WriteNode; 14 15 namespace syncable { 16 17 class BaseWriteTransaction; 18 19 enum CreateNewUpdateItem { 20 CREATE_NEW_UPDATE_ITEM 21 }; 22 23 // This Entry includes all the operations one can safely perform on the sync 24 // thread. In particular, it does not expose setters to make changes that need 25 // to be communicated to the model (and the model's thread). It is not possible 26 // to change an entry's SPECIFICS or UNIQUE_POSITION fields with this kind of 27 // entry. 28 class SYNC_EXPORT_PRIVATE ModelNeutralMutableEntry : public Entry { 29 public: 30 ModelNeutralMutableEntry(BaseWriteTransaction* trans, 31 CreateNewUpdateItem, 32 const Id& id); 33 ModelNeutralMutableEntry(BaseWriteTransaction* trans, GetByHandle, int64); 34 ModelNeutralMutableEntry(BaseWriteTransaction* trans, GetById, const Id&); 35 ModelNeutralMutableEntry( 36 BaseWriteTransaction* trans, 37 GetByClientTag, 38 const std::string& tag); 39 ModelNeutralMutableEntry( 40 BaseWriteTransaction* trans, 41 GetByServerTag, 42 const std::string& tag); 43 44 inline BaseWriteTransaction* base_write_transaction() const { 45 return base_write_transaction_; 46 } 47 48 // Non-model-changing setters. These setters will change properties internal 49 // to the node. These fields are important for bookkeeping in the sync 50 // internals, but it is not necessary to communicate changes in these fields 51 // to the local models. 52 // 53 // Some of them trigger the re-indexing of the entry. They return true on 54 // success and false on failure, which occurs when putting the value would 55 // have caused a duplicate in the index. The setters that never fail return 56 // void. 57 void PutBaseVersion(int64 value); 58 void PutServerVersion(int64 value); 59 void PutServerMtime(base::Time value); 60 void PutServerCtime(base::Time value); 61 bool PutId(const Id& value); 62 void PutServerParentId(const Id& value); 63 bool PutIsUnsynced(bool value); 64 bool PutIsUnappliedUpdate(bool value); 65 void PutServerIsDir(bool value); 66 void PutServerIsDel(bool value); 67 void PutServerNonUniqueName(const std::string& value); 68 bool PutUniqueServerTag(const std::string& value); 69 bool PutUniqueClientTag(const std::string& value); 70 void PutUniqueBookmarkTag(const std::string& tag); 71 void PutServerSpecifics(const sync_pb::EntitySpecifics& value); 72 void PutBaseServerSpecifics(const sync_pb::EntitySpecifics& value); 73 void PutServerUniquePosition(const UniquePosition& value); 74 void PutSyncing(bool value); 75 76 // Do a simple property-only update of the PARENT_ID field. Use with caution. 77 // 78 // The normal Put(IS_PARENT) call will move the item to the front of the 79 // sibling order to maintain the linked list invariants when the parent 80 // changes. That's usually what you want to do, but it's inappropriate 81 // when the caller is trying to change the parent ID of a the whole set 82 // of children (e.g. because the ID changed during a commit). For those 83 // cases, there's this function. It will corrupt the sibling ordering 84 // if you're not careful. 85 void PutParentIdPropertyOnly(const Id& parent_id); 86 87 // This is similar to what one would expect from Put(TRANSACTION_VERSION), 88 // except that it doesn't bother to invoke 'SaveOriginals'. Calling that 89 // function is at best unnecessary, since the transaction will have already 90 // used its list of mutations by the time this function is called. 91 void UpdateTransactionVersion(int64 version); 92 93 protected: 94 explicit ModelNeutralMutableEntry(BaseWriteTransaction* trans); 95 96 syncable::MetahandleSet* GetDirtyIndexHelper(); 97 98 private: 99 friend class syncer::WriteNode; 100 friend class Directory; 101 102 // Don't allow creation on heap, except by sync API wrappers. 103 void* operator new(size_t size) { return (::operator new)(size); } 104 105 // Kind of redundant. We should reduce the number of pointers 106 // floating around if at all possible. Could we store this in Directory? 107 // Scope: Set on construction, never changed after that. 108 BaseWriteTransaction* const base_write_transaction_; 109 110 DISALLOW_COPY_AND_ASSIGN(ModelNeutralMutableEntry); 111 }; 112 113 } // namespace syncable 114 } // namespace syncer 115 116 #endif // SYNC_SYNCABLE_MODEL_NEUTRAL_MUTABLE_ENTRY_H_ 117