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 "components/sync/engine_impl/directory_commit_contribution.h" | 5 #include "components/sync/engine_impl/directory_commit_contribution.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "components/sync/engine/cycle/commit_counters.h" | 10 #include "components/sync/engine/cycle/commit_counters.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 DirectoryCommitContribution::~DirectoryCommitContribution() { | 22 DirectoryCommitContribution::~DirectoryCommitContribution() { |
23 DCHECK(!syncing_bits_set_); | 23 DCHECK(!syncing_bits_set_); |
24 } | 24 } |
25 | 25 |
26 // static. | 26 // static. |
27 std::unique_ptr<DirectoryCommitContribution> DirectoryCommitContribution::Build( | 27 std::unique_ptr<DirectoryCommitContribution> DirectoryCommitContribution::Build( |
28 syncable::Directory* dir, | 28 syncable::Directory* dir, |
29 ModelType type, | 29 ModelType type, |
30 size_t max_entries, | 30 size_t max_entries, |
31 DirectoryTypeDebugInfoEmitter* debug_info_emitter) { | 31 DataTypeDebugInfoEmitter* debug_info_emitter) { |
32 DCHECK(debug_info_emitter); | 32 DCHECK(debug_info_emitter); |
33 | 33 |
34 std::vector<int64_t> metahandles; | 34 std::vector<int64_t> metahandles; |
35 | 35 |
36 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); | 36 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); |
37 GetCommitIdsForType(&trans, type, max_entries, &metahandles); | 37 GetCommitIdsForType(&trans, type, max_entries, &metahandles); |
38 | 38 |
39 if (metahandles.empty()) | 39 if (metahandles.empty()) |
40 return std::unique_ptr<DirectoryCommitContribution>(); | 40 return std::unique_ptr<DirectoryCommitContribution>(); |
41 | 41 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 break; | 114 break; |
115 default: | 115 default: |
116 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; | 116 LOG(FATAL) << "Bad return from ProcessSingleCommitResponse"; |
117 } | 117 } |
118 } | 118 } |
119 MarkDeletedChildrenSynced(dir_, &trans, &deleted_folders); | 119 MarkDeletedChildrenSynced(dir_, &trans, &deleted_folders); |
120 } | 120 } |
121 | 121 |
122 CommitCounters* counters = debug_info_emitter_->GetMutableCommitCounters(); | 122 CommitCounters* counters = debug_info_emitter_->GetMutableCommitCounters(); |
123 counters->num_commits_success += successes; | 123 counters->num_commits_success += successes; |
124 counters->num_commits_conflict += transient_error_commits; | 124 counters->num_commits_conflict += conflicting_commits; |
125 counters->num_commits_error += transient_error_commits; | 125 counters->num_commits_error += transient_error_commits; |
126 | 126 |
127 int commit_count = static_cast<int>(metahandles_.size()); | 127 int commit_count = static_cast<int>(metahandles_.size()); |
128 if (commit_count == successes) { | 128 if (commit_count == successes) { |
129 return SYNCER_OK; | 129 return SYNCER_OK; |
130 } else if (error_commits > 0) { | 130 } else if (error_commits > 0) { |
131 return SERVER_RETURN_UNKNOWN_ERROR; | 131 return SERVER_RETURN_UNKNOWN_ERROR; |
132 } else if (transient_error_commits > 0) { | 132 } else if (transient_error_commits > 0) { |
133 return SERVER_RETURN_TRANSIENT_ERROR; | 133 return SERVER_RETURN_TRANSIENT_ERROR; |
134 } else if (conflicting_commits > 0) { | 134 } else if (conflicting_commits > 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
158 | 158 |
159 size_t DirectoryCommitContribution::GetNumEntries() const { | 159 size_t DirectoryCommitContribution::GetNumEntries() const { |
160 return metahandles_.size(); | 160 return metahandles_.size(); |
161 } | 161 } |
162 | 162 |
163 DirectoryCommitContribution::DirectoryCommitContribution( | 163 DirectoryCommitContribution::DirectoryCommitContribution( |
164 const std::vector<int64_t>& metahandles, | 164 const std::vector<int64_t>& metahandles, |
165 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | 165 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
166 const sync_pb::DataTypeContext& context, | 166 const sync_pb::DataTypeContext& context, |
167 syncable::Directory* dir, | 167 syncable::Directory* dir, |
168 DirectoryTypeDebugInfoEmitter* debug_info_emitter) | 168 DataTypeDebugInfoEmitter* debug_info_emitter) |
169 : dir_(dir), | 169 : dir_(dir), |
170 metahandles_(metahandles), | 170 metahandles_(metahandles), |
171 entities_(entities), | 171 entities_(entities), |
172 context_(context), | 172 context_(context), |
173 entries_start_index_(0xDEADBEEF), | 173 entries_start_index_(0xDEADBEEF), |
174 syncing_bits_set_(true), | 174 syncing_bits_set_(true), |
175 debug_info_emitter_(debug_info_emitter) {} | 175 debug_info_emitter_(debug_info_emitter) {} |
176 | 176 |
177 void DirectoryCommitContribution::UnsetSyncingBits() { | 177 void DirectoryCommitContribution::UnsetSyncingBits() { |
178 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); | 178 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); |
179 for (std::vector<int64_t>::const_iterator it = metahandles_.begin(); | 179 for (std::vector<int64_t>::const_iterator it = metahandles_.begin(); |
180 it != metahandles_.end(); ++it) { | 180 it != metahandles_.end(); ++it) { |
181 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 181 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
182 // TODO(sync): this seems like it could be harmful if a sync cycle doesn't | 182 // TODO(sync): this seems like it could be harmful if a sync cycle doesn't |
183 // complete but the Cleanup method is called anyways. It appears these are | 183 // complete but the Cleanup method is called anyways. It appears these are |
184 // unset on the assumption that the sync cycle must have finished properly, | 184 // unset on the assumption that the sync cycle must have finished properly, |
185 // although that's actually up to the commit response handling logic. | 185 // although that's actually up to the commit response handling logic. |
186 entry.PutDirtySync(false); | 186 entry.PutDirtySync(false); |
187 entry.PutSyncing(false); | 187 entry.PutSyncing(false); |
188 } | 188 } |
189 syncing_bits_set_ = false; | 189 syncing_bits_set_ = false; |
190 } | 190 } |
191 | 191 |
192 } // namespace syncer | 192 } // namespace syncer |
OLD | NEW |