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