Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 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 return scoped_ptr<DirectoryCommitContribution>( | 44 return scoped_ptr<DirectoryCommitContribution>( |
| 45 new DirectoryCommitContribution(metahandles, entities, dir)); | 45 new DirectoryCommitContribution(type, metahandles, entities, dir)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void DirectoryCommitContribution::AddToCommitMessage( | 48 void DirectoryCommitContribution::AddToCommitMessage( |
| 49 sync_pb::ClientToServerMessage* msg) { | 49 sync_pb::ClientToServerMessage* msg) { |
| 50 DCHECK(syncing_bits_set_); | 50 DCHECK(syncing_bits_set_); |
| 51 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); | 51 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); |
| 52 entries_start_index_ = commit_message->entries_size(); | 52 entries_start_index_ = commit_message->entries_size(); |
| 53 std::copy(entities_.begin(), | 53 std::copy(entities_.begin(), |
| 54 entities_.end(), | 54 entities_.end(), |
| 55 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); | 55 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); |
| 56 sync_pb::DataTypeContext context; | |
|
rlarocque
2014/04/03 17:31:58
The entities were grabbed out of the directory whi
Nicolas Zea
2014/04/03 22:56:47
Done.
| |
| 57 dir_->GetDataTypeContext(type_, &context); | |
| 58 if (!context.context().empty()) | |
| 59 commit_message->add_client_contexts()->Swap(&context); | |
| 56 } | 60 } |
| 57 | 61 |
| 58 SyncerError DirectoryCommitContribution::ProcessCommitResponse( | 62 SyncerError DirectoryCommitContribution::ProcessCommitResponse( |
| 59 const sync_pb::ClientToServerResponse& response, | 63 const sync_pb::ClientToServerResponse& response, |
| 60 sessions::StatusController* status) { | 64 sessions::StatusController* status) { |
| 61 DCHECK(syncing_bits_set_); | 65 DCHECK(syncing_bits_set_); |
| 62 const sync_pb::CommitResponse& commit_response = response.commit(); | 66 const sync_pb::CommitResponse& commit_response = response.commit(); |
| 63 | 67 |
| 64 int transient_error_commits = 0; | 68 int transient_error_commits = 0; |
| 65 int conflicting_commits = 0; | 69 int conflicting_commits = 0; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 void DirectoryCommitContribution::CleanUp() { | 139 void DirectoryCommitContribution::CleanUp() { |
| 136 DCHECK(syncing_bits_set_); | 140 DCHECK(syncing_bits_set_); |
| 137 UnsetSyncingBits(); | 141 UnsetSyncingBits(); |
| 138 } | 142 } |
| 139 | 143 |
| 140 size_t DirectoryCommitContribution::GetNumEntries() const { | 144 size_t DirectoryCommitContribution::GetNumEntries() const { |
| 141 return metahandles_.size(); | 145 return metahandles_.size(); |
| 142 } | 146 } |
| 143 | 147 |
| 144 DirectoryCommitContribution::DirectoryCommitContribution( | 148 DirectoryCommitContribution::DirectoryCommitContribution( |
| 149 ModelType type, | |
| 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, |
| 147 syncable::Directory* dir) | 152 syncable::Directory* dir) |
| 148 : dir_(dir), | 153 : dir_(dir), |
| 154 type_(type), | |
| 149 metahandles_(metahandles), | 155 metahandles_(metahandles), |
| 150 entities_(entities), | 156 entities_(entities), |
| 151 entries_start_index_(0xDEADBEEF), | 157 entries_start_index_(0xDEADBEEF), |
| 152 syncing_bits_set_(true) { | 158 syncing_bits_set_(true) { |
| 153 } | 159 } |
| 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 |