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