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 #include "sync/internal_api/public/write_transaction.h" | 5 #include "components/sync/core/write_transaction.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "sync/syncable/directory.h" | 9 #include "components/sync/syncable/directory.h" |
10 #include "sync/syncable/mutable_entry.h" | 10 #include "components/sync/syncable/mutable_entry.h" |
11 #include "sync/syncable/syncable_write_transaction.h" | 11 #include "components/sync/syncable/syncable_write_transaction.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 ////////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////////// |
16 // WriteTransaction member definitions | 16 // WriteTransaction member definitions |
17 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here, | 17 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here, |
18 UserShare* share) | 18 UserShare* share) |
19 : BaseTransaction(share), | 19 : BaseTransaction(share), transaction_(NULL) { |
20 transaction_(NULL) { | |
21 transaction_ = new syncable::WriteTransaction(from_here, syncable::SYNCAPI, | 20 transaction_ = new syncable::WriteTransaction(from_here, syncable::SYNCAPI, |
22 share->directory.get()); | 21 share->directory.get()); |
23 } | 22 } |
24 | 23 |
25 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here, | 24 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here, |
26 UserShare* share, | 25 UserShare* share, |
27 int64_t* new_model_version) | 26 int64_t* new_model_version) |
28 : BaseTransaction(share), transaction_(NULL) { | 27 : BaseTransaction(share), transaction_(NULL) { |
29 transaction_ = new syncable::WriteTransaction(from_here, | 28 transaction_ = new syncable::WriteTransaction( |
30 share->directory.get(), | 29 from_here, share->directory.get(), new_model_version); |
31 new_model_version); | |
32 } | 30 } |
33 | 31 |
34 WriteTransaction::~WriteTransaction() { | 32 WriteTransaction::~WriteTransaction() { |
35 delete transaction_; | 33 delete transaction_; |
36 } | 34 } |
37 | 35 |
38 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { | 36 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { |
39 return transaction_; | 37 return transaction_; |
40 } | 38 } |
41 | 39 |
42 void WriteTransaction::SetDataTypeContext( | 40 void WriteTransaction::SetDataTypeContext( |
43 ModelType type, | 41 ModelType type, |
44 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status, | 42 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status, |
45 const std::string& context) { | 43 const std::string& context) { |
46 DCHECK(ProtocolTypes().Has(type)); | 44 DCHECK(ProtocolTypes().Has(type)); |
47 int field_number = GetSpecificsFieldNumberFromModelType(type); | 45 int field_number = GetSpecificsFieldNumberFromModelType(type); |
48 sync_pb::DataTypeContext local_context; | 46 sync_pb::DataTypeContext local_context; |
49 GetDirectory()->GetDataTypeContext(transaction_, | 47 GetDirectory()->GetDataTypeContext(transaction_, type, &local_context); |
50 type, | |
51 &local_context); | |
52 if (local_context.context() == context) | 48 if (local_context.context() == context) |
53 return; | 49 return; |
54 | 50 |
55 if (!local_context.has_data_type_id()) | 51 if (!local_context.has_data_type_id()) |
56 local_context.set_data_type_id(field_number); | 52 local_context.set_data_type_id(field_number); |
57 | 53 |
58 DCHECK_EQ(field_number, local_context.data_type_id()); | 54 DCHECK_EQ(field_number, local_context.data_type_id()); |
59 DCHECK_GE(local_context.version(), 0); | 55 DCHECK_GE(local_context.version(), 0); |
60 local_context.set_version(local_context.version() + 1); | 56 local_context.set_version(local_context.version() + 1); |
61 local_context.set_context(context); | 57 local_context.set_context(context); |
62 GetDirectory()->SetDataTypeContext(transaction_, | 58 GetDirectory()->SetDataTypeContext(transaction_, type, local_context); |
63 type, | |
64 local_context); | |
65 if (refresh_status == syncer::SyncChangeProcessor::REFRESH_NEEDED) { | 59 if (refresh_status == syncer::SyncChangeProcessor::REFRESH_NEEDED) { |
66 DVLOG(1) << "Forcing refresh of type " << ModelTypeToString(type); | 60 DVLOG(1) << "Forcing refresh of type " << ModelTypeToString(type); |
67 // Clear the progress token from the progress markers. Preserve all other | 61 // Clear the progress token from the progress markers. Preserve all other |
68 // state, in case a GC directive was present. | 62 // state, in case a GC directive was present. |
69 sync_pb::DataTypeProgressMarker progress_marker; | 63 sync_pb::DataTypeProgressMarker progress_marker; |
70 GetDirectory()->GetDownloadProgress(type, &progress_marker); | 64 GetDirectory()->GetDownloadProgress(type, &progress_marker); |
71 progress_marker.clear_token(); | 65 progress_marker.clear_token(); |
72 GetDirectory()->SetDownloadProgress(type, progress_marker); | 66 GetDirectory()->SetDownloadProgress(type, progress_marker); |
73 | 67 |
74 // Go through and reset the versions for all the synced entities of this | 68 // Go through and reset the versions for all the synced entities of this |
75 // data type. | 69 // data type. |
76 GetDirectory()->ResetVersionsForType(transaction_, type); | 70 GetDirectory()->ResetVersionsForType(transaction_, type); |
77 } | 71 } |
78 | 72 |
79 // Note that it's possible for a GetUpdatesResponse that arrives immediately | 73 // Note that it's possible for a GetUpdatesResponse that arrives immediately |
80 // after the context update to override the cleared progress markers. | 74 // after the context update to override the cleared progress markers. |
81 // TODO(zea): add a flag in the directory to prevent this from happening. | 75 // TODO(zea): add a flag in the directory to prevent this from happening. |
82 // See crbug.com/360280 | 76 // See crbug.com/360280 |
83 } | 77 } |
84 | 78 |
85 void WriteTransaction::UpdateEntriesMarkAttachmentAsOnServer( | 79 void WriteTransaction::UpdateEntriesMarkAttachmentAsOnServer( |
86 const AttachmentId& attachment_id) { | 80 const AttachmentId& attachment_id) { |
87 syncable::Directory::Metahandles handles; | 81 syncable::Directory::Metahandles handles; |
88 GetDirectory()->GetMetahandlesByAttachmentId( | 82 GetDirectory()->GetMetahandlesByAttachmentId( |
89 transaction_, attachment_id.GetProto(), &handles); | 83 transaction_, attachment_id.GetProto(), &handles); |
90 for (syncable::Directory::Metahandles::iterator iter = handles.begin(); | 84 for (syncable::Directory::Metahandles::iterator iter = handles.begin(); |
91 iter != handles.end(); | 85 iter != handles.end(); ++iter) { |
92 ++iter) { | |
93 syncable::MutableEntry entry(transaction_, syncable::GET_BY_HANDLE, *iter); | 86 syncable::MutableEntry entry(transaction_, syncable::GET_BY_HANDLE, *iter); |
94 entry.MarkAttachmentAsOnServer(attachment_id.GetProto()); | 87 entry.MarkAttachmentAsOnServer(attachment_id.GetProto()); |
95 } | 88 } |
96 } | 89 } |
97 | 90 |
98 } // namespace syncer | 91 } // namespace syncer |
OLD | NEW |