Chromium Code Reviews| 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 // Locks db in constructor, unlocks in destructor. | 14 // Locks db in constructor, unlocks in destructor. |
| 15 class WriteTransaction : public BaseTransaction { | 15 class WriteTransaction : public BaseTransaction { |
| 16 public: | 16 public: |
| 17 WriteTransaction(const tracked_objects::Location& from_here, | 17 WriteTransaction(const tracked_objects::Location& from_here, |
| 18 WriterTag writer, Directory* directory); | 18 WriterTag writer, Directory* directory); |
| 19 | 19 |
| 20 // Constructor used for getting back model version after making sync | |
| 21 // API changes to one model. After the transaction is destroyed, | |
|
Nicolas Zea
2012/11/02 21:02:25
nit: "After the transaction is destroyed" -> "Duri
haitaol1
2012/11/02 22:58:18
Done.
| |
| 22 // |new_model_version| stores the new model version if model is changed, | |
| 23 // or -1 if model is not changed. | |
| 24 WriteTransaction(const tracked_objects::Location& from_here, | |
| 25 Directory* directory, int64* new_model_version); | |
| 26 | |
| 20 virtual ~WriteTransaction(); | 27 virtual ~WriteTransaction(); |
| 21 | 28 |
| 22 void SaveOriginal(const EntryKernel* entry); | 29 void SaveOriginal(const EntryKernel* entry); |
| 23 | 30 |
| 24 protected: | 31 protected: |
| 25 // Overridden by tests. | 32 // Overridden by tests. |
| 26 virtual void NotifyTransactionComplete(ModelTypeSet models_with_changes); | 33 virtual void NotifyTransactionComplete(ModelTypeSet models_with_changes); |
| 27 | 34 |
| 28 private: | 35 private: |
| 29 friend class MutableEntry; | 36 friend class MutableEntry; |
| 30 | 37 |
| 31 // Clears |mutations_|. | 38 // Clears |mutations_|. |
| 32 ImmutableEntryKernelMutationMap RecordMutations(); | 39 ImmutableEntryKernelMutationMap RecordMutations(); |
| 33 | 40 |
| 34 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations); | 41 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations); |
| 35 | 42 |
| 36 ModelTypeSet NotifyTransactionChangingAndEnding( | 43 ModelTypeSet NotifyTransactionChangingAndEnding( |
| 37 const ImmutableEntryKernelMutationMap& mutations); | 44 const ImmutableEntryKernelMutationMap& mutations); |
| 38 | 45 |
| 46 // Increment versions of the models whose entries are modified and set the | |
| 47 // version on the changed entries. | |
| 48 void UpdateTransactionVersion(const std::vector<int64>& entry_changed); | |
| 49 | |
| 39 // Only the original fields are filled in until |RecordMutations()|. | 50 // Only the original fields are filled in until |RecordMutations()|. |
| 40 // We use a mutation map instead of a kernel set to avoid copying. | 51 // We use a mutation map instead of a kernel set to avoid copying. |
| 41 EntryKernelMutationMap mutations_; | 52 EntryKernelMutationMap mutations_; |
| 42 | 53 |
| 54 int64* new_model_version_; | |
|
Nicolas Zea
2012/11/02 21:02:25
Comment that you don't have ownership of this.
haitaol1
2012/11/02 22:58:18
Done.
| |
| 55 | |
| 43 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); | 56 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); |
| 44 }; | 57 }; |
| 45 | 58 |
| 46 } // namespace syncable | 59 } // namespace syncable |
| 47 } // namespace syncer | 60 } // namespace syncer |
| 48 | 61 |
| 49 #endif // SYNC_SYNCABLE_WRITE_TRANSACTION_H_ | 62 #endif // SYNC_SYNCABLE_WRITE_TRANSACTION_H_ |
| OLD | NEW |