| 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_update_handler.h" | 5 #include "components/sync/engine_impl/directory_update_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "sync/engine/conflict_resolver.h" | 11 #include "components/sync/base/data_type_histogram.h" |
| 12 #include "sync/engine/process_updates_util.h" | 12 #include "components/sync/engine_impl/conflict_resolver.h" |
| 13 #include "sync/engine/update_applicator.h" | 13 #include "components/sync/engine_impl/process_updates_util.h" |
| 14 #include "sync/sessions/directory_type_debug_info_emitter.h" | 14 #include "components/sync/engine_impl/update_applicator.h" |
| 15 #include "sync/syncable/directory.h" | 15 #include "components/sync/sessions_impl/directory_type_debug_info_emitter.h" |
| 16 #include "sync/syncable/model_neutral_mutable_entry.h" | 16 #include "components/sync/syncable/directory.h" |
| 17 #include "sync/syncable/syncable_changes_version.h" | 17 #include "components/sync/syncable/model_neutral_mutable_entry.h" |
| 18 #include "sync/syncable/syncable_model_neutral_write_transaction.h" | 18 #include "components/sync/syncable/syncable_changes_version.h" |
| 19 #include "sync/syncable/syncable_write_transaction.h" | 19 #include "components/sync/syncable/syncable_model_neutral_write_transaction.h" |
| 20 #include "sync/util/data_type_histogram.h" | 20 #include "components/sync/syncable/syncable_write_transaction.h" |
| 21 | 21 |
| 22 namespace syncer { | 22 namespace syncer { |
| 23 | 23 |
| 24 using syncable::SYNCER; | 24 using syncable::SYNCER; |
| 25 | 25 |
| 26 DirectoryUpdateHandler::DirectoryUpdateHandler( | 26 DirectoryUpdateHandler::DirectoryUpdateHandler( |
| 27 syncable::Directory* dir, | 27 syncable::Directory* dir, |
| 28 ModelType type, | 28 ModelType type, |
| 29 scoped_refptr<ModelSafeWorker> worker, | 29 scoped_refptr<ModelSafeWorker> worker, |
| 30 DirectoryTypeDebugInfoEmitter* debug_info_emitter) | 30 DirectoryTypeDebugInfoEmitter* debug_info_emitter) |
| 31 : dir_(dir), | 31 : dir_(dir), |
| 32 type_(type), | 32 type_(type), |
| 33 worker_(worker), | 33 worker_(worker), |
| 34 debug_info_emitter_(debug_info_emitter) {} | 34 debug_info_emitter_(debug_info_emitter) {} |
| 35 | 35 |
| 36 DirectoryUpdateHandler::~DirectoryUpdateHandler() {} | 36 DirectoryUpdateHandler::~DirectoryUpdateHandler() {} |
| 37 | 37 |
| 38 bool DirectoryUpdateHandler::IsInitialSyncEnded() const { | 38 bool DirectoryUpdateHandler::IsInitialSyncEnded() const { |
| 39 return dir_->InitialSyncEndedForType(type_); | 39 return dir_->InitialSyncEndedForType(type_); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void DirectoryUpdateHandler::GetDownloadProgress( | 42 void DirectoryUpdateHandler::GetDownloadProgress( |
| 43 sync_pb::DataTypeProgressMarker* progress_marker) const { | 43 sync_pb::DataTypeProgressMarker* progress_marker) const { |
| 44 dir_->GetDownloadProgress(type_, progress_marker); | 44 dir_->GetDownloadProgress(type_, progress_marker); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 146 } |
| 147 | 147 |
| 148 PostApplyUpdates(); | 148 PostApplyUpdates(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl( | 151 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl( |
| 152 sessions::StatusController* status) { | 152 sessions::StatusController* status) { |
| 153 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_); | 153 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_); |
| 154 | 154 |
| 155 std::vector<int64_t> handles; | 155 std::vector<int64_t> handles; |
| 156 dir_->GetUnappliedUpdateMetaHandles( | 156 dir_->GetUnappliedUpdateMetaHandles(&trans, FullModelTypeSet(type_), |
| 157 &trans, | 157 &handles); |
| 158 FullModelTypeSet(type_), | |
| 159 &handles); | |
| 160 | 158 |
| 161 // First set of update application passes. | 159 // First set of update application passes. |
| 162 UpdateApplicator applicator(dir_->GetCryptographer(&trans)); | 160 UpdateApplicator applicator(dir_->GetCryptographer(&trans)); |
| 163 applicator.AttemptApplications(&trans, handles); | 161 applicator.AttemptApplications(&trans, handles); |
| 164 | 162 |
| 165 // The old StatusController counters. | 163 // The old StatusController counters. |
| 166 status->increment_num_updates_applied_by(applicator.updates_applied()); | 164 status->increment_num_updates_applied_by(applicator.updates_applied()); |
| 167 status->increment_num_hierarchy_conflicts_by( | 165 status->increment_num_hierarchy_conflicts_by( |
| 168 applicator.hierarchy_conflicts()); | 166 applicator.hierarchy_conflicts()); |
| 169 status->increment_num_encryption_conflicts_by( | 167 status->increment_num_encryption_conflicts_by( |
| 170 applicator.encryption_conflicts()); | 168 applicator.encryption_conflicts()); |
| 171 | 169 |
| 172 // The new UpdateCounter counters. | 170 // The new UpdateCounter counters. |
| 173 UpdateCounters* counters = debug_info_emitter_->GetMutableUpdateCounters(); | 171 UpdateCounters* counters = debug_info_emitter_->GetMutableUpdateCounters(); |
| 174 counters->num_updates_applied += applicator.updates_applied(); | 172 counters->num_updates_applied += applicator.updates_applied(); |
| 175 counters->num_hierarchy_conflict_application_failures = | 173 counters->num_hierarchy_conflict_application_failures = |
| 176 applicator.hierarchy_conflicts(); | 174 applicator.hierarchy_conflicts(); |
| 177 counters->num_encryption_conflict_application_failures += | 175 counters->num_encryption_conflict_application_failures += |
| 178 applicator.encryption_conflicts(); | 176 applicator.encryption_conflicts(); |
| 179 | 177 |
| 180 if (applicator.simple_conflict_ids().size() != 0) { | 178 if (applicator.simple_conflict_ids().size() != 0) { |
| 181 // Resolve the simple conflicts we just detected. | 179 // Resolve the simple conflicts we just detected. |
| 182 ConflictResolver resolver; | 180 ConflictResolver resolver; |
| 183 resolver.ResolveConflicts(&trans, | 181 resolver.ResolveConflicts(&trans, dir_->GetCryptographer(&trans), |
| 184 dir_->GetCryptographer(&trans), | 182 applicator.simple_conflict_ids(), status, |
| 185 applicator.simple_conflict_ids(), | |
| 186 status, | |
| 187 counters); | 183 counters); |
| 188 | 184 |
| 189 // Conflict resolution sometimes results in more updates to apply. | 185 // Conflict resolution sometimes results in more updates to apply. |
| 190 handles.clear(); | 186 handles.clear(); |
| 191 dir_->GetUnappliedUpdateMetaHandles( | 187 dir_->GetUnappliedUpdateMetaHandles(&trans, FullModelTypeSet(type_), |
| 192 &trans, | 188 &handles); |
| 193 FullModelTypeSet(type_), | |
| 194 &handles); | |
| 195 | 189 |
| 196 UpdateApplicator conflict_applicator(dir_->GetCryptographer(&trans)); | 190 UpdateApplicator conflict_applicator(dir_->GetCryptographer(&trans)); |
| 197 conflict_applicator.AttemptApplications(&trans, handles); | 191 conflict_applicator.AttemptApplications(&trans, handles); |
| 198 | 192 |
| 199 // We count the number of updates from both applicator passes. | 193 // We count the number of updates from both applicator passes. |
| 200 status->increment_num_updates_applied_by( | 194 status->increment_num_updates_applied_by( |
| 201 conflict_applicator.updates_applied()); | 195 conflict_applicator.updates_applied()); |
| 202 counters->num_updates_applied += conflict_applicator.updates_applied(); | 196 counters->num_updates_applied += conflict_applicator.updates_applied(); |
| 203 | 197 |
| 204 // Encryption conflicts should remain unchanged by the resolution of simple | 198 // Encryption conflicts should remain unchanged by the resolution of simple |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 242 |
| 249 return dir_->TypeHasUnappliedUpdates(type_); | 243 return dir_->TypeHasUnappliedUpdates(type_); |
| 250 } | 244 } |
| 251 | 245 |
| 252 void DirectoryUpdateHandler::UpdateSyncEntities( | 246 void DirectoryUpdateHandler::UpdateSyncEntities( |
| 253 syncable::ModelNeutralWriteTransaction* trans, | 247 syncable::ModelNeutralWriteTransaction* trans, |
| 254 const SyncEntityList& applicable_updates, | 248 const SyncEntityList& applicable_updates, |
| 255 sessions::StatusController* status) { | 249 sessions::StatusController* status) { |
| 256 UpdateCounters* counters = debug_info_emitter_->GetMutableUpdateCounters(); | 250 UpdateCounters* counters = debug_info_emitter_->GetMutableUpdateCounters(); |
| 257 counters->num_updates_received += applicable_updates.size(); | 251 counters->num_updates_received += applicable_updates.size(); |
| 258 ProcessDownloadedUpdates(dir_, trans, type_, | 252 ProcessDownloadedUpdates(dir_, trans, type_, applicable_updates, status, |
| 259 applicable_updates, status, counters); | 253 counters); |
| 260 } | 254 } |
| 261 | 255 |
| 262 bool DirectoryUpdateHandler::IsValidProgressMarker( | 256 bool DirectoryUpdateHandler::IsValidProgressMarker( |
| 263 const sync_pb::DataTypeProgressMarker& progress_marker) const { | 257 const sync_pb::DataTypeProgressMarker& progress_marker) const { |
| 264 if (progress_marker.token().empty()) { | 258 if (progress_marker.token().empty()) { |
| 265 return false; | 259 return false; |
| 266 } | 260 } |
| 267 int field_number = progress_marker.data_type_id(); | 261 int field_number = progress_marker.data_type_id(); |
| 268 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); | 262 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); |
| 269 if (!IsRealDataType(model_type) || type_ != model_type) { | 263 if (!IsRealDataType(model_type) || type_ != model_type) { |
| 270 NOTREACHED() | 264 NOTREACHED() << "Update handler of type " << ModelTypeToString(type_) |
| 271 << "Update handler of type " << ModelTypeToString(type_) | 265 << " asked to process progress marker with invalid type " |
| 272 << " asked to process progress marker with invalid type " | 266 << field_number; |
| 273 << field_number; | |
| 274 return false; | 267 return false; |
| 275 } | 268 } |
| 276 return true; | 269 return true; |
| 277 } | 270 } |
| 278 | 271 |
| 279 void DirectoryUpdateHandler::UpdateProgressMarker( | 272 void DirectoryUpdateHandler::UpdateProgressMarker( |
| 280 const sync_pb::DataTypeProgressMarker& progress_marker) { | 273 const sync_pb::DataTypeProgressMarker& progress_marker) { |
| 281 if (progress_marker.has_gc_directive() || !cached_gc_directive_) { | 274 if (progress_marker.has_gc_directive() || !cached_gc_directive_) { |
| 282 dir_->SetDownloadProgress(type_, progress_marker); | 275 dir_->SetDownloadProgress(type_, progress_marker); |
| 283 } else { | 276 } else { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 300 } | 293 } |
| 301 | 294 |
| 302 if (!progress_marker.has_gc_directive()) | 295 if (!progress_marker.has_gc_directive()) |
| 303 return; | 296 return; |
| 304 | 297 |
| 305 const sync_pb::GarbageCollectionDirective& new_gc_directive = | 298 const sync_pb::GarbageCollectionDirective& new_gc_directive = |
| 306 progress_marker.gc_directive(); | 299 progress_marker.gc_directive(); |
| 307 | 300 |
| 308 if (new_gc_directive.has_version_watermark() && | 301 if (new_gc_directive.has_version_watermark() && |
| 309 (!cached_gc_directive_ || | 302 (!cached_gc_directive_ || |
| 310 cached_gc_directive_->version_watermark() < | 303 cached_gc_directive_->version_watermark() < |
| 311 new_gc_directive.version_watermark())) { | 304 new_gc_directive.version_watermark())) { |
| 312 ExpireEntriesByVersion(dir_, trans, type_, | 305 ExpireEntriesByVersion(dir_, trans, type_, |
| 313 new_gc_directive.version_watermark()); | 306 new_gc_directive.version_watermark()); |
| 314 } | 307 } |
| 315 | 308 |
| 316 cached_gc_directive_.reset( | 309 cached_gc_directive_.reset( |
| 317 new sync_pb::GarbageCollectionDirective(new_gc_directive)); | 310 new sync_pb::GarbageCollectionDirective(new_gc_directive)); |
| 318 } | 311 } |
| 319 | 312 |
| 320 } // namespace syncer | 313 } // namespace syncer |
| OLD | NEW |