Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: components/sync/core/write_transaction.cc

Issue 2407163004: [Sync] Move some directory-related things from core/ to syncable/. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "components/sync/core/write_transaction.h"
6
7 #include "components/sync/syncable/directory.h"
8 #include "components/sync/syncable/mutable_entry.h"
9 #include "components/sync/syncable/syncable_write_transaction.h"
10
11 namespace syncer {
12
13 //////////////////////////////////////////////////////////////////////////
14 // WriteTransaction member definitions
15 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
16 UserShare* share)
17 : BaseTransaction(share), transaction_(NULL) {
18 transaction_ = new syncable::WriteTransaction(from_here, syncable::SYNCAPI,
19 share->directory.get());
20 }
21
22 WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
23 UserShare* share,
24 int64_t* new_model_version)
25 : BaseTransaction(share), transaction_(NULL) {
26 transaction_ = new syncable::WriteTransaction(
27 from_here, share->directory.get(), new_model_version);
28 }
29
30 WriteTransaction::~WriteTransaction() {
31 delete transaction_;
32 }
33
34 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const {
35 return transaction_;
36 }
37
38 void WriteTransaction::SetDataTypeContext(
39 ModelType type,
40 SyncChangeProcessor::ContextRefreshStatus refresh_status,
41 const std::string& context) {
42 DCHECK(ProtocolTypes().Has(type));
43 int field_number = GetSpecificsFieldNumberFromModelType(type);
44 sync_pb::DataTypeContext local_context;
45 GetDirectory()->GetDataTypeContext(transaction_, type, &local_context);
46 if (local_context.context() == context)
47 return;
48
49 if (!local_context.has_data_type_id())
50 local_context.set_data_type_id(field_number);
51
52 DCHECK_EQ(field_number, local_context.data_type_id());
53 DCHECK_GE(local_context.version(), 0);
54 local_context.set_version(local_context.version() + 1);
55 local_context.set_context(context);
56 GetDirectory()->SetDataTypeContext(transaction_, type, local_context);
57 if (refresh_status == SyncChangeProcessor::REFRESH_NEEDED) {
58 DVLOG(1) << "Forcing refresh of type " << ModelTypeToString(type);
59 // Clear the progress token from the progress markers. Preserve all other
60 // state, in case a GC directive was present.
61 sync_pb::DataTypeProgressMarker progress_marker;
62 GetDirectory()->GetDownloadProgress(type, &progress_marker);
63 progress_marker.clear_token();
64 GetDirectory()->SetDownloadProgress(type, progress_marker);
65
66 // Go through and reset the versions for all the synced entities of this
67 // data type.
68 GetDirectory()->ResetVersionsForType(transaction_, type);
69 }
70
71 // Note that it's possible for a GetUpdatesResponse that arrives immediately
72 // after the context update to override the cleared progress markers.
73 // TODO(zea): add a flag in the directory to prevent this from happening.
74 // See crbug.com/360280
75 }
76
77 void WriteTransaction::UpdateEntriesMarkAttachmentAsOnServer(
78 const AttachmentId& attachment_id) {
79 syncable::Directory::Metahandles handles;
80 GetDirectory()->GetMetahandlesByAttachmentId(
81 transaction_, attachment_id.GetProto(), &handles);
82 for (syncable::Directory::Metahandles::iterator iter = handles.begin();
83 iter != handles.end(); ++iter) {
84 syncable::MutableEntry entry(transaction_, syncable::GET_BY_HANDLE, *iter);
85 entry.MarkAttachmentAsOnServer(attachment_id.GetProto());
86 }
87 }
88
89 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core/write_transaction.h ('k') | components/sync/core_impl/change_reorder_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698