Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / sync / internal_api / write_transaction.cc
blobb2dfe87da1785038367047bd1f0bb05b0f7d5eef
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"
10 namespace syncer {
12 //////////////////////////////////////////////////////////////////////////
13 // WriteTransaction member definitions
14 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
15 UserShare* share)
16 : BaseTransaction(share),
17 transaction_(NULL) {
18 transaction_ = new syncable::WriteTransaction(from_here, syncable::SYNCAPI,
19 share->directory.get());
22 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
23 UserShare* share,
24 int64* new_model_version)
25 : BaseTransaction(share),
26 transaction_(NULL) {
27 transaction_ = new syncable::WriteTransaction(from_here,
28 share->directory.get(),
29 new_model_version);
32 WriteTransaction::~WriteTransaction() {
33 delete transaction_;
36 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const {
37 return transaction_;
40 void WriteTransaction::SetDataTypeContext(
41 ModelType type,
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_,
48 type,
49 &local_context);
50 if (local_context.context() == context)
51 return;
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_,
61 type,
62 local_context);
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
73 // data type.
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
83 } // namespace syncer