client_tag_based_remote_update_handler.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2020 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. #ifndef COMPONENTS_SYNC_MODEL_CLIENT_TAG_BASED_REMOTE_UPDATE_HANDLER_H_
  5. #define COMPONENTS_SYNC_MODEL_CLIENT_TAG_BASED_REMOTE_UPDATE_HANDLER_H_
  6. #include <memory>
  7. #include <string>
  8. #include <unordered_set>
  9. #include "base/memory/raw_ptr.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "components/sync/engine/commit_and_get_updates_types.h"
  12. #include "components/sync/model/conflict_resolution.h"
  13. #include "components/sync/model/entity_change.h"
  14. #include "components/sync/model/model_error.h"
  15. namespace sync_pb {
  16. class ModelTypeState;
  17. } // namespace sync_pb
  18. namespace syncer {
  19. class ModelTypeSyncBridge;
  20. class ProcessorEntityTracker;
  21. class ProcessorEntity;
  22. // A sync component that performs updates from sync server.
  23. class ClientTagBasedRemoteUpdateHandler {
  24. public:
  25. // All parameters must not be nullptr and they must outlive this object.
  26. ClientTagBasedRemoteUpdateHandler(ModelType type,
  27. ModelTypeSyncBridge* bridge,
  28. ProcessorEntityTracker* entities);
  29. // Processes incremental updates from the sync server.
  30. absl::optional<ModelError> ProcessIncrementalUpdate(
  31. const sync_pb::ModelTypeState& model_type_state,
  32. UpdateResponseDataList updates);
  33. ClientTagBasedRemoteUpdateHandler(const ClientTagBasedRemoteUpdateHandler&) =
  34. delete;
  35. ClientTagBasedRemoteUpdateHandler& operator=(
  36. const ClientTagBasedRemoteUpdateHandler&) = delete;
  37. private:
  38. // Helper function to process the update for a single entity. If a local data
  39. // change is required, it will be added to |entity_changes|. The return value
  40. // is the tracked entity, or nullptr if the update should be ignored.
  41. // |storage_key_to_clear| must not be null and allows the implementation to
  42. // indicate that a certain storage key is now obsolete and should be cleared,
  43. // which is leveraged in certain conflict resolution scenarios.
  44. ProcessorEntity* ProcessUpdate(UpdateResponseData update,
  45. EntityChangeList* entity_changes,
  46. std::string* storage_key_to_clear);
  47. // Resolve a conflict between |update| and the pending commit in |entity|.
  48. void ResolveConflict(UpdateResponseData update,
  49. ProcessorEntity* entity,
  50. EntityChangeList* changes,
  51. std::string* storage_key_to_clear);
  52. // Gets the entity for the given tag hash, or null if there isn't one.
  53. ProcessorEntity* GetEntityForTagHash(const ClientTagHash& tag_hash);
  54. // Creates an entity in the entity tracker for |storage_key| queried from the
  55. // bridge for the given |update|. Provided |storage_key| (if any, i.e. if
  56. // non-empty) must not exist in the entity tracker.
  57. ProcessorEntity* CreateEntity(const UpdateResponseData& update);
  58. // The model type this object syncs.
  59. const ModelType type_;
  60. // ModelTypeSyncBridge linked to associated processor.
  61. const raw_ptr<ModelTypeSyncBridge> bridge_;
  62. // A map of client tag hash to sync entities known to the processor.
  63. // Should be replaced with new interface.
  64. const raw_ptr<ProcessorEntityTracker> entity_tracker_;
  65. };
  66. } // namespace syncer
  67. #endif // COMPONENTS_SYNC_MODEL_CLIENT_TAG_BASED_REMOTE_UPDATE_HANDLER_H_