| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/engine/directory_commit_contribution.h" | 5 #include "sync/engine/directory_commit_contribution.h" |
| 6 | 6 |
| 7 #include "sync/engine/commit_util.h" | 7 #include "sync/engine/commit_util.h" |
| 8 #include "sync/engine/get_commit_ids.h" | 8 #include "sync/engine/get_commit_ids.h" |
| 9 #include "sync/engine/syncer_util.h" | 9 #include "sync/engine/syncer_util.h" |
| 10 #include "sync/syncable/model_neutral_mutable_entry.h" | 10 #include "sync/syncable/model_neutral_mutable_entry.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities; | 35 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities; |
| 36 for (std::vector<int64>::iterator it = metahandles.begin(); | 36 for (std::vector<int64>::iterator it = metahandles.begin(); |
| 37 it != metahandles.end(); ++it) { | 37 it != metahandles.end(); ++it) { |
| 38 sync_pb::SyncEntity* entity = entities.Add(); | 38 sync_pb::SyncEntity* entity = entities.Add(); |
| 39 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 39 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
| 40 commit_util::BuildCommitItem(entry, entity); | 40 commit_util::BuildCommitItem(entry, entity); |
| 41 entry.PutSyncing(true); | 41 entry.PutSyncing(true); |
| 42 } | 42 } |
| 43 | 43 |
| 44 sync_pb::DataTypeContext context; |
| 45 dir->GetDataTypeContext(&trans, type, &context); |
| 46 |
| 44 return scoped_ptr<DirectoryCommitContribution>( | 47 return scoped_ptr<DirectoryCommitContribution>( |
| 45 new DirectoryCommitContribution(metahandles, entities, dir)); | 48 new DirectoryCommitContribution(metahandles, entities, context, dir)); |
| 46 } | 49 } |
| 47 | 50 |
| 48 void DirectoryCommitContribution::AddToCommitMessage( | 51 void DirectoryCommitContribution::AddToCommitMessage( |
| 49 sync_pb::ClientToServerMessage* msg) { | 52 sync_pb::ClientToServerMessage* msg) { |
| 50 DCHECK(syncing_bits_set_); | 53 DCHECK(syncing_bits_set_); |
| 51 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); | 54 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); |
| 52 entries_start_index_ = commit_message->entries_size(); | 55 entries_start_index_ = commit_message->entries_size(); |
| 53 std::copy(entities_.begin(), | 56 std::copy(entities_.begin(), |
| 54 entities_.end(), | 57 entities_.end(), |
| 55 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); | 58 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); |
| 59 if (!context_.context().empty()) |
| 60 commit_message->add_client_contexts()->Swap(&context_); |
| 56 } | 61 } |
| 57 | 62 |
| 58 SyncerError DirectoryCommitContribution::ProcessCommitResponse( | 63 SyncerError DirectoryCommitContribution::ProcessCommitResponse( |
| 59 const sync_pb::ClientToServerResponse& response, | 64 const sync_pb::ClientToServerResponse& response, |
| 60 sessions::StatusController* status) { | 65 sessions::StatusController* status) { |
| 61 DCHECK(syncing_bits_set_); | 66 DCHECK(syncing_bits_set_); |
| 62 const sync_pb::CommitResponse& commit_response = response.commit(); | 67 const sync_pb::CommitResponse& commit_response = response.commit(); |
| 63 | 68 |
| 64 int transient_error_commits = 0; | 69 int transient_error_commits = 0; |
| 65 int conflicting_commits = 0; | 70 int conflicting_commits = 0; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 UnsetSyncingBits(); | 142 UnsetSyncingBits(); |
| 138 } | 143 } |
| 139 | 144 |
| 140 size_t DirectoryCommitContribution::GetNumEntries() const { | 145 size_t DirectoryCommitContribution::GetNumEntries() const { |
| 141 return metahandles_.size(); | 146 return metahandles_.size(); |
| 142 } | 147 } |
| 143 | 148 |
| 144 DirectoryCommitContribution::DirectoryCommitContribution( | 149 DirectoryCommitContribution::DirectoryCommitContribution( |
| 145 const std::vector<int64>& metahandles, | 150 const std::vector<int64>& metahandles, |
| 146 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | 151 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
| 152 const sync_pb::DataTypeContext& context, |
| 147 syncable::Directory* dir) | 153 syncable::Directory* dir) |
| 148 : dir_(dir), | 154 : dir_(dir), |
| 149 metahandles_(metahandles), | 155 metahandles_(metahandles), |
| 150 entities_(entities), | 156 entities_(entities), |
| 151 entries_start_index_(0xDEADBEEF), | 157 context_(context), |
| 152 syncing_bits_set_(true) { | 158 entries_start_index_(0xDEADBEEF), |
| 153 } | 159 syncing_bits_set_(true) {} |
| 154 | 160 |
| 155 void DirectoryCommitContribution::UnsetSyncingBits() { | 161 void DirectoryCommitContribution::UnsetSyncingBits() { |
| 156 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); | 162 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); |
| 157 for (std::vector<int64>::const_iterator it = metahandles_.begin(); | 163 for (std::vector<int64>::const_iterator it = metahandles_.begin(); |
| 158 it != metahandles_.end(); ++it) { | 164 it != metahandles_.end(); ++it) { |
| 159 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 165 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
| 160 entry.PutSyncing(false); | 166 entry.PutSyncing(false); |
| 161 } | 167 } |
| 162 syncing_bits_set_ = false; | 168 syncing_bits_set_ = false; |
| 163 } | 169 } |
| 164 | 170 |
| 165 } // namespace syncer | 171 } // namespace syncer |
| OLD | NEW |