blob: 8ae7f9bb0c7b90c1c368624c7bf6ee654de82cf7 [file] [log] [blame]
[email protected]c9ce60b2012-12-19 23:16:081// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]67192b42011-08-17 23:38:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]406203d2012-06-17 01:07:195#include "sync/internal_api/public/write_transaction.h"
[email protected]67192b42011-08-17 23:38:306
avi4856ced02015-12-22 03:14:107#include <stdint.h>
8
[email protected]d7f9c932014-04-04 21:10:219#include "sync/syncable/directory.h"
[email protected]0ae5be32014-05-20 06:14:5410#include "sync/syncable/mutable_entry.h"
[email protected]c9ce60b2012-12-19 23:16:0811#include "sync/syncable/syncable_write_transaction.h"
[email protected]67192b42011-08-17 23:38:3012
[email protected]65f173552012-06-28 22:43:5813namespace syncer {
[email protected]67192b42011-08-17 23:38:3014
15//////////////////////////////////////////////////////////////////////////
16// WriteTransaction member definitions
17WriteTransaction::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,
[email protected]30aebeb92012-02-28 05:27:1522 share->directory.get());
[email protected]67192b42011-08-17 23:38:3023}
24
[email protected]fc290d62012-11-10 05:20:1125WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
26 UserShare* share,
avi4856ced02015-12-22 03:14:1027 int64_t* new_model_version)
28 : BaseTransaction(share), transaction_(NULL) {
[email protected]fc290d62012-11-10 05:20:1129 transaction_ = new syncable::WriteTransaction(from_here,
30 share->directory.get(),
31 new_model_version);
32}
33
[email protected]67192b42011-08-17 23:38:3034WriteTransaction::~WriteTransaction() {
35 delete transaction_;
36}
37
38syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const {
39 return transaction_;
40}
41
[email protected]694ffab82014-04-09 00:17:3642void 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);
[email protected]d7f9c932014-04-04 21:10:2148 sync_pb::DataTypeContext local_context;
49 GetDirectory()->GetDataTypeContext(transaction_,
50 type,
51 &local_context);
52 if (local_context.context() == context)
53 return;
54
[email protected]694ffab82014-04-09 00:17:3655 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());
[email protected]d7f9c932014-04-04 21:10:2159 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);
[email protected]694ffab82014-04-09 00:17:3665 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
[email protected]d7f9c932014-04-04 21:10:2183}
84
[email protected]8ac09b212014-07-17 06:47:4485void WriteTransaction::UpdateEntriesMarkAttachmentAsOnServer(
[email protected]0ae5be32014-05-20 06:14:5486 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);
[email protected]8ac09b212014-07-17 06:47:4494 entry.MarkAttachmentAsOnServer(attachment_id.GetProto());
[email protected]0ae5be32014-05-20 06:14:5495 }
96}
97
[email protected]65f173552012-06-28 22:43:5898} // namespace syncer