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