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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <algorithm> | 10 #include <algorithm> |
8 #include <set> | 11 #include <set> |
9 | 12 |
10 #include "sync/engine/commit_util.h" | 13 #include "sync/engine/commit_util.h" |
11 #include "sync/engine/get_commit_ids.h" | 14 #include "sync/engine/get_commit_ids.h" |
12 #include "sync/engine/syncer_util.h" | 15 #include "sync/engine/syncer_util.h" |
13 #include "sync/internal_api/public/sessions/commit_counters.h" | 16 #include "sync/internal_api/public/sessions/commit_counters.h" |
14 #include "sync/syncable/model_neutral_mutable_entry.h" | 17 #include "sync/syncable/model_neutral_mutable_entry.h" |
15 #include "sync/syncable/syncable_model_neutral_write_transaction.h" | 18 #include "sync/syncable/syncable_model_neutral_write_transaction.h" |
16 | 19 |
17 namespace syncer { | 20 namespace syncer { |
18 | 21 |
19 using syncable::GET_BY_HANDLE; | 22 using syncable::GET_BY_HANDLE; |
20 using syncable::SYNCER; | 23 using syncable::SYNCER; |
21 | 24 |
22 DirectoryCommitContribution::~DirectoryCommitContribution() { | 25 DirectoryCommitContribution::~DirectoryCommitContribution() { |
23 DCHECK(!syncing_bits_set_); | 26 DCHECK(!syncing_bits_set_); |
24 } | 27 } |
25 | 28 |
26 // static. | 29 // static. |
27 scoped_ptr<DirectoryCommitContribution> DirectoryCommitContribution::Build( | 30 scoped_ptr<DirectoryCommitContribution> DirectoryCommitContribution::Build( |
28 syncable::Directory* dir, | 31 syncable::Directory* dir, |
29 ModelType type, | 32 ModelType type, |
30 size_t max_entries, | 33 size_t max_entries, |
31 DirectoryTypeDebugInfoEmitter* debug_info_emitter) { | 34 DirectoryTypeDebugInfoEmitter* debug_info_emitter) { |
32 DCHECK(debug_info_emitter); | 35 DCHECK(debug_info_emitter); |
33 | 36 |
34 std::vector<int64> metahandles; | 37 std::vector<int64_t> metahandles; |
35 | 38 |
36 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); | 39 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir); |
37 GetCommitIdsForType(&trans, type, max_entries, &metahandles); | 40 GetCommitIdsForType(&trans, type, max_entries, &metahandles); |
38 | 41 |
39 if (metahandles.empty()) | 42 if (metahandles.empty()) |
40 return scoped_ptr<DirectoryCommitContribution>(); | 43 return scoped_ptr<DirectoryCommitContribution>(); |
41 | 44 |
42 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities; | 45 google::protobuf::RepeatedPtrField<sync_pb::SyncEntity> entities; |
43 for (std::vector<int64>::iterator it = metahandles.begin(); | 46 for (std::vector<int64_t>::iterator it = metahandles.begin(); |
44 it != metahandles.end(); ++it) { | 47 it != metahandles.end(); ++it) { |
45 sync_pb::SyncEntity* entity = entities.Add(); | 48 sync_pb::SyncEntity* entity = entities.Add(); |
46 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 49 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
47 commit_util::BuildCommitItem(entry, entity); | 50 commit_util::BuildCommitItem(entry, entity); |
48 entry.PutSyncing(true); | 51 entry.PutSyncing(true); |
49 } | 52 } |
50 | 53 |
51 sync_pb::DataTypeContext context; | 54 sync_pb::DataTypeContext context; |
52 dir->GetDataTypeContext(&trans, type, &context); | 55 dir->GetDataTypeContext(&trans, type, &context); |
53 | 56 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 UnsetSyncingBits(); | 165 UnsetSyncingBits(); |
163 debug_info_emitter_->EmitCommitCountersUpdate(); | 166 debug_info_emitter_->EmitCommitCountersUpdate(); |
164 debug_info_emitter_->EmitStatusCountersUpdate(); | 167 debug_info_emitter_->EmitStatusCountersUpdate(); |
165 } | 168 } |
166 | 169 |
167 size_t DirectoryCommitContribution::GetNumEntries() const { | 170 size_t DirectoryCommitContribution::GetNumEntries() const { |
168 return metahandles_.size(); | 171 return metahandles_.size(); |
169 } | 172 } |
170 | 173 |
171 DirectoryCommitContribution::DirectoryCommitContribution( | 174 DirectoryCommitContribution::DirectoryCommitContribution( |
172 const std::vector<int64>& metahandles, | 175 const std::vector<int64_t>& metahandles, |
173 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, | 176 const google::protobuf::RepeatedPtrField<sync_pb::SyncEntity>& entities, |
174 const sync_pb::DataTypeContext& context, | 177 const sync_pb::DataTypeContext& context, |
175 syncable::Directory* dir, | 178 syncable::Directory* dir, |
176 DirectoryTypeDebugInfoEmitter* debug_info_emitter) | 179 DirectoryTypeDebugInfoEmitter* debug_info_emitter) |
177 : dir_(dir), | 180 : dir_(dir), |
178 metahandles_(metahandles), | 181 metahandles_(metahandles), |
179 entities_(entities), | 182 entities_(entities), |
180 context_(context), | 183 context_(context), |
181 entries_start_index_(0xDEADBEEF), | 184 entries_start_index_(0xDEADBEEF), |
182 syncing_bits_set_(true), | 185 syncing_bits_set_(true), |
183 debug_info_emitter_(debug_info_emitter) {} | 186 debug_info_emitter_(debug_info_emitter) {} |
184 | 187 |
185 void DirectoryCommitContribution::UnsetSyncingBits() { | 188 void DirectoryCommitContribution::UnsetSyncingBits() { |
186 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); | 189 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); |
187 for (std::vector<int64>::const_iterator it = metahandles_.begin(); | 190 for (std::vector<int64_t>::const_iterator it = metahandles_.begin(); |
188 it != metahandles_.end(); ++it) { | 191 it != metahandles_.end(); ++it) { |
189 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); | 192 syncable::ModelNeutralMutableEntry entry(&trans, GET_BY_HANDLE, *it); |
190 // TODO(sync): this seems like it could be harmful if a sync cycle doesn't | 193 // TODO(sync): this seems like it could be harmful if a sync cycle doesn't |
191 // complete but the Cleanup method is called anyways. It appears these are | 194 // complete but the Cleanup method is called anyways. It appears these are |
192 // unset on the assumption that the sync cycle must have finished properly, | 195 // unset on the assumption that the sync cycle must have finished properly, |
193 // although that's actually up to the commit response handling logic. | 196 // although that's actually up to the commit response handling logic. |
194 entry.PutDirtySync(false); | 197 entry.PutDirtySync(false); |
195 entry.PutSyncing(false); | 198 entry.PutSyncing(false); |
196 } | 199 } |
197 syncing_bits_set_ = false; | 200 syncing_bits_set_ = false; |
198 } | 201 } |
199 | 202 |
200 } // namespace syncer | 203 } // namespace syncer |
OLD | NEW |