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. During destruction, |new_model_version| stores | |
22 // the new model version if model is changed, or -1 if model is not changed. | |
tim (not reviewing)
2012/11/08 17:38:49
Note that we don't technically scope a write trans
haitaol1
2012/11/08 19:06:53
If the transaction is for processing syncer change
| |
23 WriteTransaction(const tracked_objects::Location& from_here, | |
24 Directory* directory, int64* new_model_version); | |
25 | |
20 virtual ~WriteTransaction(); | 26 virtual ~WriteTransaction(); |
21 | 27 |
22 void SaveOriginal(const EntryKernel* entry); | 28 void SaveOriginal(const EntryKernel* entry); |
23 | 29 |
24 protected: | 30 protected: |
25 // Overridden by tests. | 31 // Overridden by tests. |
26 virtual void NotifyTransactionComplete(ModelTypeSet models_with_changes); | 32 virtual void NotifyTransactionComplete(ModelTypeSet models_with_changes); |
27 | 33 |
28 private: | 34 private: |
29 friend class MutableEntry; | 35 friend class MutableEntry; |
30 | 36 |
31 // Clears |mutations_|. | 37 // Clears |mutations_|. |
32 ImmutableEntryKernelMutationMap RecordMutations(); | 38 ImmutableEntryKernelMutationMap RecordMutations(); |
33 | 39 |
34 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations); | 40 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations); |
35 | 41 |
36 ModelTypeSet NotifyTransactionChangingAndEnding( | 42 ModelTypeSet NotifyTransactionChangingAndEnding( |
37 const ImmutableEntryKernelMutationMap& mutations); | 43 const ImmutableEntryKernelMutationMap& mutations); |
38 | 44 |
45 // Increment versions of the models whose entries are modified and set the | |
46 // version on the changed entries. | |
47 void UpdateTransactionVersion(const std::vector<int64>& entry_changed); | |
48 | |
39 // Only the original fields are filled in until |RecordMutations()|. | 49 // Only the original fields are filled in until |RecordMutations()|. |
40 // We use a mutation map instead of a kernel set to avoid copying. | 50 // We use a mutation map instead of a kernel set to avoid copying. |
41 EntryKernelMutationMap mutations_; | 51 EntryKernelMutationMap mutations_; |
42 | 52 |
53 // Not owned. | |
tim (not reviewing)
2012/11/08 17:38:49
Can you explain more what this is for? Why is it
haitaol1
2012/11/08 19:06:53
Done. transaction_version seems better than model
| |
54 int64* new_model_version_; | |
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 |