• 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/base/sync_export.h"
11 #include "sync/internal_api/public/base_transaction.h"
12 
13 namespace tracked_objects {
14 class Location;
15 }  // namespace tracked_objects
16 
17 namespace syncer {
18 
19 namespace syncable {
20 class BaseTransaction;
21 class WriteTransaction;
22 }  // namespace syncable
23 
24 // Sync API's WriteTransaction is a read/write BaseTransaction.  It wraps
25 // a syncable::WriteTransaction.
26 //
27 // NOTE: Only a single model type can be mutated for a given
28 // WriteTransaction.
29 class SYNC_EXPORT WriteTransaction : public BaseTransaction {
30  public:
31   // Start a new read/write transaction.
32   WriteTransaction(const tracked_objects::Location& from_here,
33                    UserShare* share);
34   // |transaction_version| stores updated model and nodes version if model
35   // is changed by the transaction, or syncer::syncable::kInvalidTransaction
36   // if not after transaction is closed. This constructor is used for model
37   // types that support embassy data.
38   WriteTransaction(const tracked_objects::Location& from_here,
39                    UserShare* share, int64* transaction_version);
40   virtual ~WriteTransaction();
41 
42   // Provide access to the syncable transaction from the API WriteNode.
43   virtual syncable::BaseTransaction* GetWrappedTrans() const OVERRIDE;
GetWrappedWriteTrans()44   syncable::WriteTransaction* GetWrappedWriteTrans() { return transaction_; }
45 
46  protected:
WriteTransaction()47   WriteTransaction() {}
48 
SetTransaction(syncable::WriteTransaction * trans)49   void SetTransaction(syncable::WriteTransaction* trans) {
50     transaction_ = trans;
51   }
52 
53  private:
54   void* operator new(size_t size);  // Transaction is meant for stack use only.
55 
56   // The underlying syncable object which this class wraps.
57   syncable::WriteTransaction* transaction_;
58 
59   DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
60 };
61 
62 }  // namespace syncer
63 
64 #endif  // SYNC_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
65