model_type_sync_bridge.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/sync/model/model_type_sync_bridge.h"
  5. #include <utility>
  6. #include "components/sync/model/conflict_resolution.h"
  7. #include "components/sync/model/metadata_batch.h"
  8. #include "components/sync/model/metadata_change_list.h"
  9. namespace syncer {
  10. ModelTypeSyncBridge::ModelTypeSyncBridge(
  11. std::unique_ptr<ModelTypeChangeProcessor> change_processor)
  12. : change_processor_(std::move(change_processor)) {
  13. DCHECK(change_processor_);
  14. change_processor_->OnModelStarting(this);
  15. }
  16. ModelTypeSyncBridge::~ModelTypeSyncBridge() = default;
  17. void ModelTypeSyncBridge::OnSyncStarting(
  18. const DataTypeActivationRequest& request) {}
  19. bool ModelTypeSyncBridge::SupportsGetClientTag() const {
  20. return true;
  21. }
  22. bool ModelTypeSyncBridge::SupportsGetStorageKey() const {
  23. return true;
  24. }
  25. bool ModelTypeSyncBridge::SupportsIncrementalUpdates() const {
  26. return true;
  27. }
  28. ConflictResolution ModelTypeSyncBridge::ResolveConflict(
  29. const std::string& storage_key,
  30. const EntityData& remote_data) const {
  31. if (remote_data.is_deleted()) {
  32. return ConflictResolution::kUseLocal;
  33. }
  34. return ConflictResolution::kUseRemote;
  35. }
  36. void ModelTypeSyncBridge::ApplyStopSyncChanges(
  37. std::unique_ptr<MetadataChangeList> delete_metadata_change_list) {
  38. if (delete_metadata_change_list) {
  39. // Nothing to do if this fails, so just ignore the error it might return.
  40. ApplySyncChanges(std::move(delete_metadata_change_list),
  41. EntityChangeList());
  42. }
  43. }
  44. void ModelTypeSyncBridge::OnCommitAttemptErrors(
  45. const syncer::FailedCommitResponseDataList& error_response_list) {
  46. // By default the bridge just ignores failed commit items.
  47. }
  48. ModelTypeSyncBridge::CommitAttemptFailedBehavior
  49. ModelTypeSyncBridge::OnCommitAttemptFailed(SyncCommitError commit_error) {
  50. return CommitAttemptFailedBehavior::kDontRetryOnNextCycle;
  51. }
  52. size_t ModelTypeSyncBridge::EstimateSyncOverheadMemoryUsage() const {
  53. return 0U;
  54. }
  55. sync_pb::EntitySpecifics ModelTypeSyncBridge::TrimRemoteSpecificsForCaching(
  56. const sync_pb::EntitySpecifics& entity_specifics) const {
  57. // Clears all fields by default to avoid the memory and I/O overhead of an
  58. // additional copy of the data.
  59. return sync_pb::EntitySpecifics();
  60. }
  61. ModelTypeChangeProcessor* ModelTypeSyncBridge::change_processor() {
  62. return change_processor_.get();
  63. }
  64. const ModelTypeChangeProcessor* ModelTypeSyncBridge::change_processor() const {
  65. return change_processor_.get();
  66. }
  67. } // namespace syncer