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.
5 #include "sync/internal_api/public/write_transaction.h"
7 #include "sync/syncable/directory.h"
8 #include "sync/syncable/syncable_write_transaction.h"
12 //////////////////////////////////////////////////////////////////////////
13 // WriteTransaction member definitions
14 WriteTransaction::WriteTransaction(const tracked_objects::Location
& from_here
,
16 : BaseTransaction(share
),
18 transaction_
= new syncable::WriteTransaction(from_here
, syncable::SYNCAPI
,
19 share
->directory
.get());
22 WriteTransaction::WriteTransaction(const tracked_objects::Location
& from_here
,
24 int64
* new_model_version
)
25 : BaseTransaction(share
),
27 transaction_
= new syncable::WriteTransaction(from_here
,
28 share
->directory
.get(),
32 WriteTransaction::~WriteTransaction() {
36 syncable::BaseTransaction
* WriteTransaction::GetWrappedTrans() const {
40 void WriteTransaction::SetDataTypeContext(
42 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status
,
43 const std::string
& context
) {
44 DCHECK(ProtocolTypes().Has(type
));
45 int field_number
= GetSpecificsFieldNumberFromModelType(type
);
46 sync_pb::DataTypeContext local_context
;
47 GetDirectory()->GetDataTypeContext(transaction_
,
50 if (local_context
.context() == context
)
53 if (!local_context
.has_data_type_id())
54 local_context
.set_data_type_id(field_number
);
56 DCHECK_EQ(field_number
, local_context
.data_type_id());
57 DCHECK_GE(local_context
.version(), 0);
58 local_context
.set_version(local_context
.version() + 1);
59 local_context
.set_context(context
);
60 GetDirectory()->SetDataTypeContext(transaction_
,
63 if (refresh_status
== syncer::SyncChangeProcessor::REFRESH_NEEDED
) {
64 DVLOG(1) << "Forcing refresh of type " << ModelTypeToString(type
);
65 // Clear the progress token from the progress markers. Preserve all other
66 // state, in case a GC directive was present.
67 sync_pb::DataTypeProgressMarker progress_marker
;
68 GetDirectory()->GetDownloadProgress(type
, &progress_marker
);
69 progress_marker
.clear_token();
70 GetDirectory()->SetDownloadProgress(type
, progress_marker
);
72 // Go through and reset the versions for all the synced entities of this
74 GetDirectory()->ResetVersionsForType(transaction_
, type
);
77 // Note that it's possible for a GetUpdatesResponse that arrives immediately
78 // after the context update to override the cleared progress markers.
79 // TODO(zea): add a flag in the directory to prevent this from happening.
80 // See crbug.com/360280