| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_SYNCABLE_WRITE_TRANSACTION_H_ | 5 #ifndef SYNC_SYNCABLE_WRITE_TRANSACTION_H_ |
| 6 #define SYNC_SYNCABLE_WRITE_TRANSACTION_H_ | 6 #define SYNC_SYNCABLE_WRITE_TRANSACTION_H_ |
| 7 | 7 |
| 8 #include "sync/syncable/base_transaction.h" | 8 #include "sync/syncable/base_transaction.h" |
| 9 #include "sync/syncable/entry_kernel.h" | 9 #include "sync/syncable/entry_kernel.h" |
| 10 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 namespace syncable { | 12 namespace syncable { |
| 13 | 13 |
| 14 extern const int64 kInvalidTransactionVersion; |
| 15 |
| 14 // Locks db in constructor, unlocks in destructor. | 16 // Locks db in constructor, unlocks in destructor. |
| 15 class WriteTransaction : public BaseTransaction { | 17 class WriteTransaction : public BaseTransaction { |
| 16 public: | 18 public: |
| 17 WriteTransaction(const tracked_objects::Location& from_here, | 19 WriteTransaction(const tracked_objects::Location& from_here, |
| 18 WriterTag writer, Directory* directory); | 20 WriterTag writer, Directory* directory); |
| 19 | 21 |
| 22 // Constructor used for getting back transaction version after making sync |
| 23 // API changes to one model. If model is changed by the transaction, |
| 24 // the new transaction version of the model and modified nodes will be saved |
| 25 // in |transaction_version| upon destruction of the transaction. If model is |
| 26 // not changed, |transaction_version| will be kInvalidTransactionVersion. |
| 27 WriteTransaction(const tracked_objects::Location& from_here, |
| 28 Directory* directory, int64* transaction_version); |
| 29 |
| 20 virtual ~WriteTransaction(); | 30 virtual ~WriteTransaction(); |
| 21 | 31 |
| 22 void SaveOriginal(const EntryKernel* entry); | 32 void SaveOriginal(const EntryKernel* entry); |
| 23 | 33 |
| 24 protected: | 34 protected: |
| 25 // Overridden by tests. | 35 // Overridden by tests. |
| 26 virtual void NotifyTransactionComplete(ModelTypeSet models_with_changes); | 36 virtual void NotifyTransactionComplete(ModelTypeSet models_with_changes); |
| 27 | 37 |
| 28 private: | 38 private: |
| 29 friend class MutableEntry; | 39 friend class MutableEntry; |
| 30 | 40 |
| 31 // Clears |mutations_|. | 41 // Clears |mutations_|. |
| 32 ImmutableEntryKernelMutationMap RecordMutations(); | 42 ImmutableEntryKernelMutationMap RecordMutations(); |
| 33 | 43 |
| 34 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations); | 44 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations); |
| 35 | 45 |
| 36 ModelTypeSet NotifyTransactionChangingAndEnding( | 46 ModelTypeSet NotifyTransactionChangingAndEnding( |
| 37 const ImmutableEntryKernelMutationMap& mutations); | 47 const ImmutableEntryKernelMutationMap& mutations); |
| 38 | 48 |
| 49 // Increment versions of the models whose entries are modified and set the |
| 50 // version on the changed entries. |
| 51 void UpdateTransactionVersion(const std::vector<int64>& entry_changed); |
| 52 |
| 39 // Only the original fields are filled in until |RecordMutations()|. | 53 // Only the original fields are filled in until |RecordMutations()|. |
| 40 // We use a mutation map instead of a kernel set to avoid copying. | 54 // We use a mutation map instead of a kernel set to avoid copying. |
| 41 EntryKernelMutationMap mutations_; | 55 EntryKernelMutationMap mutations_; |
| 42 | 56 |
| 57 // Stores new transaction version of changed model and nodes if model is |
| 58 // indeed changed. kInvalidTransactionVersion otherwise. Not owned. |
| 59 int64* transaction_version_; |
| 60 |
| 43 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); | 61 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); |
| 44 }; | 62 }; |
| 45 | 63 |
| 46 } // namespace syncable | 64 } // namespace syncable |
| 47 } // namespace syncer | 65 } // namespace syncer |
| 48 | 66 |
| 49 #endif // SYNC_SYNCABLE_WRITE_TRANSACTION_H_ | 67 #endif // SYNC_SYNCABLE_WRITE_TRANSACTION_H_ |
| OLD | NEW |