| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #ifndef SYNC_ENGINE_GET_UPDATES_DELEGATE_H_ | |
| 6 #define SYNC_ENGINE_GET_UPDATES_DELEGATE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "sync/internal_api/public/events/protocol_event.h" | |
| 12 #include "sync/protocol/sync.pb.h" | |
| 13 #include "sync/sessions/model_type_registry.h" | |
| 14 #include "sync/sessions/nudge_tracker.h" | |
| 15 #include "sync/sessions/status_controller.h" | |
| 16 | |
| 17 namespace syncer { | |
| 18 | |
| 19 class GetUpdatesProcessor; | |
| 20 | |
| 21 // Interface for GetUpdates functionality that dependends on the requested | |
| 22 // GetUpdate type (normal, configuration, poll). The GetUpdatesProcessor is | |
| 23 // given an appropriate GetUpdatesDelegate to handle type specific functionality | |
| 24 // on construction. | |
| 25 class SYNC_EXPORT GetUpdatesDelegate { | |
| 26 public: | |
| 27 GetUpdatesDelegate(); | |
| 28 virtual ~GetUpdatesDelegate() = 0; | |
| 29 | |
| 30 // Populates GetUpdate message fields that depende on GetUpdates request type. | |
| 31 virtual void HelpPopulateGuMessage( | |
| 32 sync_pb::GetUpdatesMessage* get_updates) const = 0; | |
| 33 | |
| 34 // Applies pending updates to non-control types. | |
| 35 virtual void ApplyUpdates( | |
| 36 ModelTypeSet gu_types, | |
| 37 sessions::StatusController* status, | |
| 38 UpdateHandlerMap* update_handler_map) const = 0; | |
| 39 | |
| 40 virtual std::unique_ptr<ProtocolEvent> GetNetworkRequestEvent( | |
| 41 base::Time timestamp, | |
| 42 const sync_pb::ClientToServerMessage& request) const = 0; | |
| 43 }; | |
| 44 | |
| 45 // Functionality specific to the normal GetUpdate request. | |
| 46 class SYNC_EXPORT NormalGetUpdatesDelegate : public GetUpdatesDelegate { | |
| 47 public: | |
| 48 explicit NormalGetUpdatesDelegate( | |
| 49 const sessions::NudgeTracker& nudge_tracker); | |
| 50 ~NormalGetUpdatesDelegate() override; | |
| 51 | |
| 52 // Uses the member NudgeTracker to populate some fields of this GU message. | |
| 53 void HelpPopulateGuMessage( | |
| 54 sync_pb::GetUpdatesMessage* get_updates) const override; | |
| 55 | |
| 56 // Applies pending updates on the appropriate data type threads. | |
| 57 void ApplyUpdates(ModelTypeSet gu_types, | |
| 58 sessions::StatusController* status, | |
| 59 UpdateHandlerMap* update_handler_map) const override; | |
| 60 | |
| 61 std::unique_ptr<ProtocolEvent> GetNetworkRequestEvent( | |
| 62 base::Time timestamp, | |
| 63 const sync_pb::ClientToServerMessage& request) const override; | |
| 64 | |
| 65 private: | |
| 66 const sessions::NudgeTracker& nudge_tracker_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(NormalGetUpdatesDelegate); | |
| 69 }; | |
| 70 | |
| 71 // Functionality specific to the configure GetUpdate request. | |
| 72 class SYNC_EXPORT ConfigureGetUpdatesDelegate : public GetUpdatesDelegate { | |
| 73 public: | |
| 74 ConfigureGetUpdatesDelegate( | |
| 75 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | |
| 76 ~ConfigureGetUpdatesDelegate() override; | |
| 77 | |
| 78 // Sets the 'source' and 'origin' fields for this request. | |
| 79 void HelpPopulateGuMessage( | |
| 80 sync_pb::GetUpdatesMessage* get_updates) const override; | |
| 81 | |
| 82 // Applies updates passively (ie. on the sync thread). | |
| 83 // | |
| 84 // This is safe only if the ChangeProcessor is not listening to changes at | |
| 85 // this time. | |
| 86 void ApplyUpdates(ModelTypeSet gu_types, | |
| 87 sessions::StatusController* status, | |
| 88 UpdateHandlerMap* update_handler_map) const override; | |
| 89 | |
| 90 std::unique_ptr<ProtocolEvent> GetNetworkRequestEvent( | |
| 91 base::Time timestamp, | |
| 92 const sync_pb::ClientToServerMessage& request) const override; | |
| 93 | |
| 94 private: | |
| 95 static sync_pb::SyncEnums::GetUpdatesOrigin ConvertConfigureSourceToOrigin( | |
| 96 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | |
| 97 | |
| 98 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(ConfigureGetUpdatesDelegate); | |
| 101 }; | |
| 102 | |
| 103 // Functionality specific to the poll GetUpdate request. | |
| 104 class SYNC_EXPORT PollGetUpdatesDelegate : public GetUpdatesDelegate { | |
| 105 public: | |
| 106 PollGetUpdatesDelegate(); | |
| 107 ~PollGetUpdatesDelegate() override; | |
| 108 | |
| 109 // Sets the 'source' and 'origin' to indicate this is a poll request. | |
| 110 void HelpPopulateGuMessage( | |
| 111 sync_pb::GetUpdatesMessage* get_updates) const override; | |
| 112 | |
| 113 // Applies updates on the appropriate data type thread. | |
| 114 void ApplyUpdates(ModelTypeSet gu_types, | |
| 115 sessions::StatusController* status, | |
| 116 UpdateHandlerMap* update_handler_map) const override; | |
| 117 | |
| 118 std::unique_ptr<ProtocolEvent> GetNetworkRequestEvent( | |
| 119 base::Time timestamp, | |
| 120 const sync_pb::ClientToServerMessage& request) const override; | |
| 121 | |
| 122 private: | |
| 123 DISALLOW_COPY_AND_ASSIGN(PollGetUpdatesDelegate); | |
| 124 }; | |
| 125 | |
| 126 } // namespace syncer | |
| 127 | |
| 128 #endif // SYNC_ENGINE_GET_UPDATES_DELEGATE_H_ | |
| OLD | NEW |