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.
4
5#ifndef SYNC_SYNCABLE_MUTABLE_ENTRY_H_
6#define SYNC_SYNCABLE_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#include "sync/syncable/metahandle_set.h"
12#include "sync/syncable/model_neutral_mutable_entry.h"
13
14namespace syncer {
15class WriteNode;
16
17namespace syncable {
18
19enum Create {
20  CREATE
21};
22
23class WriteTransaction;
24
25// A mutable meta entry.  Changes get committed to the database when the
26// WriteTransaction is destroyed.
27class SYNC_EXPORT_PRIVATE MutableEntry : public ModelNeutralMutableEntry {
28  void Init(WriteTransaction* trans, ModelType model_type,
29            const Id& parent_id, const std::string& name);
30
31 public:
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, GetTypeRoot, ModelType type);
39
40  inline WriteTransaction* write_transaction() const {
41    return write_transaction_;
42  }
43
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);
55
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);
61
62  void PutAttachmentMetadata(
63      const sync_pb::AttachmentMetadata& attachment_metadata);
64
65  // Update attachment metadata for |attachment_id| to indicate that this
66  // attachment has been uploaded to the sync server.
67  void MarkAttachmentAsOnServer(
68      const sync_pb::AttachmentIdProto& attachment_id);
69
70 private:
71  // Kind of redundant. We should reduce the number of pointers
72  // floating around if at all possible. Could we store this in Directory?
73  // Scope: Set on construction, never changed after that.
74  WriteTransaction* const write_transaction_;
75
76  DISALLOW_COPY_AND_ASSIGN(MutableEntry);
77};
78
79// This function sets only the flags needed to get this entry to sync.
80bool MarkForSyncing(syncable::MutableEntry* e);
81
82}  // namespace syncable
83}  // namespace syncer
84
85#endif  // SYNC_SYNCABLE_MUTABLE_ENTRY_H_
86