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
3 // found in the LICENSE file.
5 #ifndef SYNC_SYNCABLE_MUTABLE_ENTRY_H_
6 #define SYNC_SYNCABLE_MUTABLE_ENTRY_H_
8 #include "sync/internal_api/public/base/node_ordinal.h"
9 #include "sync/syncable/entry.h"
10 #include "sync/syncable/metahandle_set.h"
17 class WriteTransaction
;
23 enum CreateNewUpdateItem
{
24 CREATE_NEW_UPDATE_ITEM
27 // A mutable meta entry. Changes get committed to the database when the
28 // WriteTransaction is destroyed.
29 class MutableEntry
: public Entry
{
30 void Init(WriteTransaction
* trans
, const Id
& parent_id
,
31 const std::string
& name
);
34 MutableEntry(WriteTransaction
* trans
, Create
, const Id
& parent_id
,
35 const std::string
& name
);
36 MutableEntry(WriteTransaction
* trans
, CreateNewUpdateItem
, const Id
& id
);
37 MutableEntry(WriteTransaction
* trans
, GetByHandle
, int64
);
38 MutableEntry(WriteTransaction
* trans
, GetById
, const Id
&);
39 MutableEntry(WriteTransaction
* trans
, GetByClientTag
, const std::string
& tag
);
40 MutableEntry(WriteTransaction
* trans
, GetByServerTag
, const std::string
& tag
);
42 inline WriteTransaction
* write_transaction() const {
43 return write_transaction_
;
46 // Field Accessors. Some of them trigger the re-indexing of the entry.
47 // Return true on success, return false on failure, which means
48 // that putting the value would have caused a duplicate in the index.
49 // TODO(chron): Remove some of these unecessary return values.
50 bool Put(Int64Field field
, const int64
& value
);
51 bool Put(TimeField field
, const base::Time
& value
);
52 bool Put(IdField field
, const Id
& value
);
53 bool Put(OrdinalField field
, const NodeOrdinal
& value
);
55 // Do a simple property-only update if the PARENT_ID field. Use with caution.
57 // 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
59 // 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
61 // 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
63 // if you're not careful.
64 void PutParentIdPropertyOnly(const Id
& parent_id
);
66 bool Put(StringField field
, const std::string
& value
);
67 bool Put(BaseVersion field
, int64 value
);
69 bool Put(ProtoField field
, const sync_pb::EntitySpecifics
& value
);
70 bool Put(BitField field
, bool value
);
71 inline bool Put(IsDelField field
, bool value
) {
72 return PutIsDel(value
);
74 bool Put(IndexedBitField field
, bool value
);
76 // Sets the position of this item, and updates the entry kernels of the
77 // adjacent siblings so that list invariants are maintained. Returns false
78 // and fails if |predecessor_id| does not identify a sibling. Pass the root
79 // ID to put the node in first position.
80 bool PutPredecessor(const Id
& predecessor_id
);
82 bool Put(BitTemp field
, bool value
);
85 syncable::MetahandleSet
* GetDirtyIndexHelper();
87 bool PutIsDel(bool value
);
90 friend class Directory
;
91 friend class WriteTransaction
;
92 friend class syncer::WriteNode
;
94 // Don't allow creation on heap, except by sync API wrappers.
95 void* operator new(size_t size
) { return (::operator new)(size
); }
97 bool PutUniqueClientTag(const std::string
& value
);
99 // Adjusts the successor and predecessor entries so that they no longer
100 // refer to this entry.
101 bool UnlinkFromOrder();
103 // Kind of redundant. We should reduce the number of pointers
104 // floating around if at all possible. Could we store this in Directory?
105 // Scope: Set on construction, never changed after that.
106 WriteTransaction
* const write_transaction_
;
111 DISALLOW_COPY_AND_ASSIGN(MutableEntry
);
114 // This function sets only the flags needed to get this entry to sync.
115 bool MarkForSyncing(syncable::MutableEntry
* e
);
117 } // namespace syncable
118 } // namespace syncer
120 #endif // SYNC_SYNCABLE_MUTABLE_ENTRY_H_