| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync_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" |
| 11 #include "sync/syncable/syncable_model_neutral_write_transaction.h" | 11 #include "sync/syncable/syncable_model_neutral_write_transaction.h" |
| 12 | 12 |
| 13 namespace syncer { | 13 namespace syncer { |
| 14 | 14 |
| 15 using syncable::GET_BY_HANDLE; | 15 using syncable::GET_BY_HANDLE; |
| 16 using syncable::SYNCER; | 16 using syncable::SYNCER; |
| 17 | 17 |
| 18 SyncDirectoryCommitContribution::~SyncDirectoryCommitContribution() { | 18 DirectoryCommitContribution::~DirectoryCommitContribution() { |
| 19 DCHECK(!syncing_bits_set_); | 19 DCHECK(!syncing_bits_set_); |
| 20 } | 20 } |
| 21 | 21 |
| 22 // static. | 22 // static. |
| 23 SyncDirectoryCommitContribution* SyncDirectoryCommitContribution::Build( | 23 DirectoryCommitContribution* DirectoryCommitContribution::Build( |
| 24 syncable::Directory* dir, | 24 syncable::Directory* dir, |
| 25 ModelType type, | 25 ModelType type, |
| 26 size_t max_entries) { | 26 size_t max_entries) { |
| 27 std::vector<int64> metahandles; | 27 std::vector<int64> metahandles; |
| 28 | 28 |
| 29 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); | 29 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); |
| 30 GetCommitIdsForType(&trans, type, max_entries, &metahandles); | 30 GetCommitIdsForType(&trans, type, max_entries, &metahandles); |
| 31 | 31 |
| 32 if (metahandles.empty()) | 32 if (metahandles.empty()) |
| 33 return NULL; | 33 return NULL; |
| 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 return new SyncDirectoryCommitContribution(metahandles, entities, dir); | 44 return new DirectoryCommitContribution(metahandles, entities, dir); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SyncDirectoryCommitContribution::AddToCommitMessage( | 47 void DirectoryCommitContribution::AddToCommitMessage( |
| 48 sync_pb::ClientToServerMessage* msg) { | 48 sync_pb::ClientToServerMessage* msg) { |
| 49 DCHECK(syncing_bits_set_); | 49 DCHECK(syncing_bits_set_); |
| 50 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); | 50 sync_pb::CommitMessage* commit_message = msg->mutable_commit(); |
| 51 entries_start_index_ = commit_message->entries_size(); | 51 entries_start_index_ = commit_message->entries_size(); |
| 52 std::copy(entities_.begin(), | 52 std::copy(entities_.begin(), |
| 53 entities_.end(), | 53 entities_.end(), |
| 54 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); | 54 RepeatedPtrFieldBackInserter(commit_message->mutable_entries())); |
| 55 } | 55 } |
| 56 | 56 |
| 57 SyncerError SyncDirectoryCommitContribution::ProcessCommitResponse( | 57 SyncerError DirectoryCommitContribution::ProcessCommitResponse( |
| 58 const sync_pb::ClientToServerResponse& response, | 58 const sync_pb::ClientToServerResponse& response, |
| 59 sessions::StatusController* status) { | 59 sessions::StatusController* status) { |
| 60 DCHECK(syncing_bits_set_); | 60 DCHECK(syncing_bits_set_); |
| 61 const sync_pb::CommitResponse& commit_response = response.commit(); | 61 const sync_pb::CommitResponse& commit_response = response.commit(); |
| 62 | 62 |
| 63 int transient_error_commits = 0; | 63 int transient_error_commits = 0; |
| 64 int conflicting_commits = 0; | 64 int conflicting_commits = 0; |
| 65 int error_commits = 0; | 65 int error_commits = 0; |
| 66 int successes = 0; | 66 int successes = 0; |
| 67 | 67 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // We don't currently have any code to support that exceptional control | 124 // We don't currently have any code to support that exceptional control |
| 125 // flow. Instead, we abort the current sync cycle and start a new one. The | 125 // flow. Instead, we abort the current sync cycle and start a new one. The |
| 126 // end result is the same. | 126 // end result is the same. |
| 127 return SERVER_RETURN_CONFLICT; | 127 return SERVER_RETURN_CONFLICT; |
| 128 } else { | 128 } else { |
| 129 LOG(FATAL) << "Inconsistent counts when processing commit response"; | 129 LOG(FATAL) << "Inconsistent counts when processing commit response"; |
| 130 return SYNCER_OK; | 130 return SYNCER_OK; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 void SyncDirectoryCommitContribution::CleanUp() { | 134 void DirectoryCommitContribution::CleanUp() { |
| 135 DCHECK(syncing_bits_set_); | 135 DCHECK(syncing_bits_set_); |
| 136 UnsetSyncingBits(); | 136 UnsetSyncingBits(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 size_t SyncDirectoryCommitContribution::GetNumEntries() const { | 139 size_t DirectoryCommitContribution::GetNumEntries() const { |
| 140 return metahandles_.size(); | 140 return metahandles_.size(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 SyncDirectoryCommitContribution::SyncDirectoryCommitContribution( | 143 DirectoryCommitContribution::DirectoryCommitContribution( |
| 144 const std::vector<int64>& metahandles, | 144 const std::vector<int64>& metahandles, |
| 145 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | 145 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
| 146 syncable::Directory* dir) | 146 syncable::Directory* dir) |
| 147 : dir_(dir), | 147 : dir_(dir), |
| 148 metahandles_(metahandles), | 148 metahandles_(metahandles), |
| 149 entities_(entities), | 149 entities_(entities), |
| 150 entries_start_index_(0xDEADBEEF), | 150 entries_start_index_(0xDEADBEEF), |
| 151 syncing_bits_set_(true) { | 151 syncing_bits_set_(true) { |
| 152 } | 152 } |
| 153 | 153 |
| 154 void SyncDirectoryCommitContribution::UnsetSyncingBits() { | 154 void DirectoryCommitContribution::UnsetSyncingBits() { |
| 155 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); | 155 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); |
| 156 for (std::vector<int64>::const_iterator it = metahandles_.begin(); | 156 for (std::vector<int64>::const_iterator it = metahandles_.begin(); |
| 157 it != metahandles_.end(); ++it) { | 157 it != metahandles_.end(); ++it) { |
| 158 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 158 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
| 159 entry.PutSyncing(false); | 159 entry.PutSyncing(false); |
| 160 } | 160 } |
| 161 syncing_bits_set_ = false; | 161 syncing_bits_set_ = false; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace syncer | 164 } // namespace syncer |
| OLD | NEW |