get_updates_processor.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef COMPONENTS_SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_
  5. #define COMPONENTS_SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_
  6. #include "base/gtest_prod_util.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/sync/base/model_type.h"
  9. #include "components/sync/base/syncer_error.h"
  10. #include "components/sync/engine/model_type_registry.h"
  11. namespace sync_pb {
  12. class GetUpdatesResponse;
  13. class ClientToServerMessage;
  14. } // namespace sync_pb
  15. namespace syncer {
  16. class GetUpdatesDelegate;
  17. class StatusController;
  18. class SyncCycle;
  19. // This class manages the set of per-type syncer objects.
  20. //
  21. // It owns these types and hides the details of iterating over all of them.
  22. // Most methods allow the caller to specify a subset of types on which the
  23. // operation is to be applied. It is a logic error if the supplied set of types
  24. // contains a type which was not previously registered with the manager.
  25. class GetUpdatesProcessor {
  26. public:
  27. explicit GetUpdatesProcessor(UpdateHandlerMap* update_handler_map,
  28. const GetUpdatesDelegate& delegate);
  29. GetUpdatesProcessor(const GetUpdatesProcessor&) = delete;
  30. GetUpdatesProcessor& operator=(const GetUpdatesProcessor&) = delete;
  31. ~GetUpdatesProcessor();
  32. // Downloads and processes a batch of updates for the specified types.
  33. //
  34. // Returns SYNCER_OK if the download succeeds, SERVER_MORE_TO_DOWNLOAD if the
  35. // download succeeded but there are still some updates left to fetch on the
  36. // server, or an appropriate error value in case of failure.
  37. SyncerError DownloadUpdates(ModelTypeSet* request_types, SyncCycle* cycle);
  38. // Applies any downloaded and processed updates.
  39. void ApplyUpdates(const ModelTypeSet& gu_types,
  40. StatusController* status_controller);
  41. private:
  42. // Populates a GetUpdates request message with per-type information.
  43. void PrepareGetUpdates(const ModelTypeSet& gu_types,
  44. sync_pb::ClientToServerMessage* message);
  45. // Sends the specified message to the server and stores the response in a
  46. // member of the |cycle|'s StatusController.
  47. SyncerError ExecuteDownloadUpdates(ModelTypeSet* request_types,
  48. SyncCycle* cycle,
  49. sync_pb::ClientToServerMessage* msg);
  50. // Processes a GetUpdates response for each type.
  51. SyncerError ProcessResponse(const sync_pb::GetUpdatesResponse& gu_response,
  52. const ModelTypeSet& gu_types,
  53. StatusController* status_controller);
  54. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, BookmarkNudge);
  55. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NotifyMany);
  56. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, InitialSyncRequest);
  57. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, ConfigureTest);
  58. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, PollTest);
  59. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, RetryTest);
  60. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NudgeWithRetryTest);
  61. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, InvalidResponse);
  62. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, MoreToDownloadResponse);
  63. FRIEND_TEST_ALL_PREFIXES(GetUpdatesProcessorTest, NormalResponseTest);
  64. FRIEND_TEST_ALL_PREFIXES(DownloadUpdatesDebugInfoTest,
  65. VerifyCopyClientDebugInfo_Empty);
  66. FRIEND_TEST_ALL_PREFIXES(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites);
  67. // A map of 'update handlers', one for each enabled type.
  68. // This must be kept in sync with the routing info. Our temporary solution to
  69. // that problem is to initialize this map in set_routing_info().
  70. raw_ptr<UpdateHandlerMap> update_handler_map_;
  71. const GetUpdatesDelegate& delegate_;
  72. };
  73. } // namespace syncer
  74. #endif // COMPONENTS_SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_