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/model_type.h"
10 #include "sync/syncable/entry.h"
11 #include "sync/syncable/metahandle_set.h"
12 #include "sync/syncable/model_neutral_mutable_entry.h"
23 class WriteTransaction;
25 // A mutable meta entry. Changes get committed to the database when the
26 // WriteTransaction is destroyed.
27 class SYNC_EXPORT_PRIVATE MutableEntry : public ModelNeutralMutableEntry {
28 void Init(WriteTransaction* trans, ModelType model_type,
29 const Id& parent_id, const std::string& name);
32 MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id);
33 MutableEntry(WriteTransaction* trans, Create, ModelType model_type,
34 const Id& parent_id, const std::string& name);
35 MutableEntry(WriteTransaction* trans, GetByHandle, int64);
36 MutableEntry(WriteTransaction* trans, GetById, const Id&);
37 MutableEntry(WriteTransaction* trans, GetByClientTag, const std::string& tag);
38 MutableEntry(WriteTransaction* trans, GetByServerTag, const std::string& tag);
40 inline WriteTransaction* write_transaction() const {
41 return write_transaction_;
44 // Model-changing setters. These setters make user-visible changes that will
45 // need to be communicated either to the local model or the sync server.
46 void PutLocalExternalId(int64 value);
47 void PutMtime(base::Time value);
48 void PutCtime(base::Time value);
49 void PutParentId(const Id& value);
50 void PutIsDir(bool value);
51 void PutIsDel(bool value);
52 void PutNonUniqueName(const std::string& value);
53 void PutSpecifics(const sync_pb::EntitySpecifics& value);
54 void PutUniquePosition(const UniquePosition& value);
56 // Sets the position of this item, and updates the entry kernels of the
57 // adjacent siblings so that list invariants are maintained. Returns false
58 // and fails if |predecessor_id| does not identify a sibling. Pass the root
59 // ID to put the node in first position.
60 bool PutPredecessor(const Id& predecessor_id);
62 void PutAttachmentMetadata(
63 const sync_pb::AttachmentMetadata& attachment_metadata);
66 // Kind of redundant. We should reduce the number of pointers
67 // floating around if at all possible. Could we store this in Directory?
68 // Scope: Set on construction, never changed after that.
69 WriteTransaction* const write_transaction_;
71 DISALLOW_COPY_AND_ASSIGN(MutableEntry);
74 // This function sets only the flags needed to get this entry to sync.
75 bool MarkForSyncing(syncable::MutableEntry* e);
77 } // namespace syncable
80 #endif // SYNC_SYNCABLE_MUTABLE_ENTRY_H_