Add tests to verify accelerators properly work on constrained window.
[chromium-blink-merge.git] / sync / syncable / mutable_entry.h
blobcf7768af703a896c2efc514489235da56f74c22a
1 // Copyright 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/base/sync_export.h"
9 #include "sync/internal_api/public/base/node_ordinal.h"
10 #include "sync/syncable/entry.h"
11 #include "sync/syncable/metahandle_set.h"
13 namespace syncer {
14 class WriteNode;
16 namespace syncable {
18 class WriteTransaction;
20 enum Create {
21 CREATE
24 enum CreateNewUpdateItem {
25 CREATE_NEW_UPDATE_ITEM
28 // A mutable meta entry. Changes get committed to the database when the
29 // WriteTransaction is destroyed.
30 class SYNC_EXPORT_PRIVATE MutableEntry : public Entry {
31 void Init(WriteTransaction* trans, const Id& parent_id,
32 const std::string& name);
34 public:
35 MutableEntry(WriteTransaction* trans, Create, const Id& parent_id,
36 const std::string& name);
37 MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id);
38 MutableEntry(WriteTransaction* trans, GetByHandle, int64);
39 MutableEntry(WriteTransaction* trans, GetById, const Id&);
40 MutableEntry(WriteTransaction* trans, GetByClientTag, const std::string& tag);
41 MutableEntry(WriteTransaction* trans, GetByServerTag, const std::string& tag);
43 inline WriteTransaction* write_transaction() const {
44 return write_transaction_;
47 // Field Accessors. Some of them trigger the re-indexing of the entry.
48 // Return true on success, return false on failure, which means
49 // that putting the value would have caused a duplicate in the index.
50 // TODO(chron): Remove some of these unecessary return values.
51 bool Put(Int64Field field, const int64& value);
52 bool Put(TimeField field, const base::Time& value);
53 bool Put(IdField field, const Id& value);
54 bool Put(OrdinalField field, const NodeOrdinal& value);
56 // Do a simple property-only update if the PARENT_ID field. Use with caution.
58 // The normal Put(IS_PARENT) call will move the item to the front of the
59 // sibling order to maintain the linked list invariants when the parent
60 // changes. That's usually what you want to do, but it's inappropriate
61 // when the caller is trying to change the parent ID of a the whole set
62 // of children (e.g. because the ID changed during a commit). For those
63 // cases, there's this function. It will corrupt the sibling ordering
64 // if you're not careful.
65 void PutParentIdPropertyOnly(const Id& parent_id);
67 bool Put(StringField field, const std::string& value);
68 bool Put(BaseVersion field, int64 value);
70 bool Put(ProtoField field, const sync_pb::EntitySpecifics& value);
71 bool Put(BitField field, bool value);
72 inline bool Put(IsDelField field, bool value) {
73 return PutIsDel(value);
75 bool Put(IndexedBitField field, bool value);
77 // Sets the position of this item, and updates the entry kernels of the
78 // adjacent siblings so that list invariants are maintained. Returns false
79 // and fails if |predecessor_id| does not identify a sibling. Pass the root
80 // ID to put the node in first position.
81 bool PutPredecessor(const Id& predecessor_id);
83 bool Put(BitTemp field, bool value);
85 protected:
86 syncable::MetahandleSet* GetDirtyIndexHelper();
88 bool PutIsDel(bool value);
90 private:
91 friend class Directory;
92 friend class WriteTransaction;
93 friend class syncer::WriteNode;
95 // Don't allow creation on heap, except by sync API wrappers.
96 void* operator new(size_t size) { return (::operator new)(size); }
98 bool PutUniqueClientTag(const std::string& value);
100 // Adjusts the successor and predecessor entries so that they no longer
101 // refer to this entry.
102 bool UnlinkFromOrder();
104 // Kind of redundant. We should reduce the number of pointers
105 // floating around if at all possible. Could we store this in Directory?
106 // Scope: Set on construction, never changed after that.
107 WriteTransaction* const write_transaction_;
109 protected:
110 MutableEntry();
112 DISALLOW_COPY_AND_ASSIGN(MutableEntry);
115 // This function sets only the flags needed to get this entry to sync.
116 bool MarkForSyncing(syncable::MutableEntry* e);
118 } // namespace syncable
119 } // namespace syncer
121 #endif // SYNC_SYNCABLE_MUTABLE_ENTRY_H_