get_updates_delegate.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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
  3. // found in the LICENSE file.
  4. #include "components/sync/engine/get_updates_delegate.h"
  5. #include "components/sync/engine/events/configure_get_updates_request_event.h"
  6. #include "components/sync/engine/events/normal_get_updates_request_event.h"
  7. #include "components/sync/engine/events/poll_get_updates_request_event.h"
  8. #include "components/sync/engine/get_updates_processor.h"
  9. #include "components/sync/engine/update_handler.h"
  10. #include "components/sync/protocol/data_type_progress_marker.pb.h"
  11. #include "components/sync/protocol/get_updates_caller_info.pb.h"
  12. #include "components/sync/protocol/sync.pb.h"
  13. namespace syncer {
  14. NormalGetUpdatesDelegate::NormalGetUpdatesDelegate(
  15. const NudgeTracker& nudge_tracker)
  16. : nudge_tracker_(nudge_tracker) {}
  17. NormalGetUpdatesDelegate::~NormalGetUpdatesDelegate() = default;
  18. // This function assumes the progress markers have already been populated.
  19. void NormalGetUpdatesDelegate::HelpPopulateGuMessage(
  20. sync_pb::GetUpdatesMessage* get_updates) const {
  21. // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information. It's not
  22. // used anymore, but |source| is a required field so we have to set it anyway.
  23. get_updates->mutable_caller_info()->set_source(
  24. sync_pb::GetUpdatesCallerInfo::UNKNOWN);
  25. // Set the origin.
  26. get_updates->set_get_updates_origin(sync_pb::SyncEnums::GU_TRIGGER);
  27. get_updates->set_is_retry(nudge_tracker_.IsRetryRequired());
  28. // Special case: A GU performed for no other reason than retry will have its
  29. // origin set to RETRY.
  30. if (nudge_tracker_.GetOrigin() == sync_pb::SyncEnums::RETRY)
  31. get_updates->set_get_updates_origin(sync_pb::SyncEnums::RETRY);
  32. // Fill in the notification hints.
  33. for (int i = 0; i < get_updates->from_progress_marker_size(); ++i) {
  34. sync_pb::DataTypeProgressMarker* progress_marker =
  35. get_updates->mutable_from_progress_marker(i);
  36. ModelType type =
  37. GetModelTypeFromSpecificsFieldNumber(progress_marker->data_type_id());
  38. DCHECK(!nudge_tracker_.IsTypeBlocked(type))
  39. << "Throttled types should have been removed from the request_types.";
  40. nudge_tracker_.FillProtoMessage(
  41. type, progress_marker->mutable_get_update_triggers());
  42. }
  43. }
  44. std::unique_ptr<ProtocolEvent> NormalGetUpdatesDelegate::GetNetworkRequestEvent(
  45. base::Time timestamp,
  46. const sync_pb::ClientToServerMessage& request) const {
  47. return std::unique_ptr<ProtocolEvent>(
  48. new NormalGetUpdatesRequestEvent(timestamp, nudge_tracker_, request));
  49. }
  50. ConfigureGetUpdatesDelegate::ConfigureGetUpdatesDelegate(
  51. sync_pb::SyncEnums::GetUpdatesOrigin origin)
  52. : origin_(origin) {}
  53. ConfigureGetUpdatesDelegate::~ConfigureGetUpdatesDelegate() = default;
  54. void ConfigureGetUpdatesDelegate::HelpPopulateGuMessage(
  55. sync_pb::GetUpdatesMessage* get_updates) const {
  56. // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information. It's not
  57. // used anymore, but |source| is a required field so we have to set it anyway.
  58. get_updates->mutable_caller_info()->set_source(
  59. sync_pb::GetUpdatesCallerInfo::UNKNOWN);
  60. get_updates->set_get_updates_origin(origin_);
  61. }
  62. std::unique_ptr<ProtocolEvent>
  63. ConfigureGetUpdatesDelegate::GetNetworkRequestEvent(
  64. base::Time timestamp,
  65. const sync_pb::ClientToServerMessage& request) const {
  66. return std::make_unique<ConfigureGetUpdatesRequestEvent>(timestamp, origin_,
  67. request);
  68. }
  69. PollGetUpdatesDelegate::PollGetUpdatesDelegate() = default;
  70. PollGetUpdatesDelegate::~PollGetUpdatesDelegate() = default;
  71. void PollGetUpdatesDelegate::HelpPopulateGuMessage(
  72. sync_pb::GetUpdatesMessage* get_updates) const {
  73. // Set legacy GetUpdatesMessage.GetUpdatesCallerInfo information. It's not
  74. // used anymore, but |source| is a required field so we have to set it anyway.
  75. get_updates->mutable_caller_info()->set_source(
  76. sync_pb::GetUpdatesCallerInfo::UNKNOWN);
  77. get_updates->set_get_updates_origin(sync_pb::SyncEnums::PERIODIC);
  78. }
  79. std::unique_ptr<ProtocolEvent> PollGetUpdatesDelegate::GetNetworkRequestEvent(
  80. base::Time timestamp,
  81. const sync_pb::ClientToServerMessage& request) const {
  82. return std::unique_ptr<ProtocolEvent>(
  83. new PollGetUpdatesRequestEvent(timestamp, request));
  84. }
  85. } // namespace syncer