• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
6 #define SYNC_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
7 
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "sync/api/sync_change_processor.h"
11 #include "sync/base/sync_export.h"
12 #include "sync/internal_api/public/base_transaction.h"
13 
14 namespace tracked_objects {
15 class Location;
16 }  // namespace tracked_objects
17 
18 namespace syncer {
19 
20 namespace syncable {
21 class BaseTransaction;
22 class WriteTransaction;
23 }  // namespace syncable
24 
25 // Sync API's WriteTransaction is a read/write BaseTransaction.  It wraps
26 // a syncable::WriteTransaction.
27 //
28 // NOTE: Only a single model type can be mutated for a given
29 // WriteTransaction.
30 class SYNC_EXPORT WriteTransaction : public BaseTransaction {
31  public:
32   // Start a new read/write transaction.
33   WriteTransaction(const tracked_objects::Location& from_here,
34                    UserShare* share);
35   // |transaction_version| stores updated model and nodes version if model
36   // is changed by the transaction, or syncer::syncable::kInvalidTransaction
37   // if not after transaction is closed. This constructor is used for model
38   // types that support embassy data.
39   WriteTransaction(const tracked_objects::Location& from_here,
40                    UserShare* share, int64* transaction_version);
41   virtual ~WriteTransaction();
42 
43   // Provide access to the syncable transaction from the API WriteNode.
44   virtual syncable::BaseTransaction* GetWrappedTrans() const OVERRIDE;
GetWrappedWriteTrans()45   syncable::WriteTransaction* GetWrappedWriteTrans() { return transaction_; }
46 
47   // Set's a |type|'s local context. |refresh_status| controls whether
48   // a datatype refresh is performed (clearing the progress marker token and
49   // setting the version of all synced entities to 1).
50   void SetDataTypeContext(
51       ModelType type,
52       syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status,
53       const std::string& context);
54 
55   // Attachment id was just updated. Propagate this change to all entries that
56   // refer this attachment id and set is_on_server for corresponding records.
57   void UpdateEntriesWithAttachmentId(const AttachmentId& attachment_id);
58 
59  protected:
WriteTransaction()60   WriteTransaction() {}
61 
SetTransaction(syncable::WriteTransaction * trans)62   void SetTransaction(syncable::WriteTransaction* trans) {
63     transaction_ = trans;
64   }
65 
66  private:
67   void* operator new(size_t size);  // Transaction is meant for stack use only.
68 
69   // The underlying syncable object which this class wraps.
70   syncable::WriteTransaction* transaction_;
71 
72   DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
73 };
74 
75 }  // namespace syncer
76 
77 #endif  // SYNC_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
78