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