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.
5 #ifndef SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
6 #define SYNC_ENGINE_GET_UPDATES_DELEGATE_H_
8 #include "sync/protocol/sync.pb.h"
9 #include "sync/sessions/model_type_registry.h"
10 #include "sync/sessions/nudge_tracker.h"
11 #include "sync/sessions/status_controller.h"
15 class GetUpdatesProcessor;
17 // Interface for GetUpdates functionality that dependends on the requested
18 // GetUpdate type (normal, configuration, poll). The GetUpdatesProcessor is
19 // given an appropriate GetUpdatesDelegate to handle type specific functionality
21 class SYNC_EXPORT_PRIVATE GetUpdatesDelegate {
24 virtual ~GetUpdatesDelegate() = 0;
26 // Populates GetUpdate message fields that depende on GetUpdates request type.
27 virtual void HelpPopulateGuMessage(
28 sync_pb::GetUpdatesMessage* get_updates) const = 0;
30 // Applies pending updates to non-control types.
31 virtual void ApplyUpdates(
32 sessions::StatusController* session,
33 UpdateHandlerMap* update_handler_map) const = 0;
36 // Functionality specific to the normal GetUpdate request.
37 class SYNC_EXPORT_PRIVATE NormalGetUpdatesDelegate : public GetUpdatesDelegate {
39 NormalGetUpdatesDelegate(const sessions::NudgeTracker& nudge_tracker);
40 virtual ~NormalGetUpdatesDelegate();
42 // Uses the member NudgeTracker to populate some fields of this GU message.
43 virtual void HelpPopulateGuMessage(
44 sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
46 // Applies pending updates on the appropriate data type threads.
47 virtual void ApplyUpdates(
48 sessions::StatusController* status,
49 UpdateHandlerMap* update_handler_map) const OVERRIDE;
52 DISALLOW_COPY_AND_ASSIGN(NormalGetUpdatesDelegate);
54 const sessions::NudgeTracker& nudge_tracker_;
57 // Functionality specific to the retry GetUpdate request.
58 class SYNC_EXPORT_PRIVATE RetryGetUpdatesDelegate : public GetUpdatesDelegate {
60 RetryGetUpdatesDelegate();
61 virtual ~RetryGetUpdatesDelegate();
63 virtual void HelpPopulateGuMessage(
64 sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
66 virtual void ApplyUpdates(
67 sessions::StatusController* status,
68 UpdateHandlerMap* update_handler_map) const OVERRIDE;
71 DISALLOW_COPY_AND_ASSIGN(RetryGetUpdatesDelegate);
74 // Functionality specific to the configure GetUpdate request.
75 class SYNC_EXPORT_PRIVATE ConfigureGetUpdatesDelegate
76 : public GetUpdatesDelegate {
78 ConfigureGetUpdatesDelegate(
79 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
80 virtual ~ConfigureGetUpdatesDelegate();
82 // Sets the 'source' and 'origin' fields for this request.
83 virtual void HelpPopulateGuMessage(
84 sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
86 // Applies updates passively (ie. on the sync thread).
88 // This is safe only if the ChangeProcessor is not listening to changes at
90 virtual void ApplyUpdates(
91 sessions::StatusController* status,
92 UpdateHandlerMap* update_handler_map) const OVERRIDE;
95 DISALLOW_COPY_AND_ASSIGN(ConfigureGetUpdatesDelegate);
97 static sync_pb::SyncEnums::GetUpdatesOrigin ConvertConfigureSourceToOrigin(
98 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
100 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source_;
103 // Functionality specific to the poll GetUpdate request.
104 class SYNC_EXPORT_PRIVATE PollGetUpdatesDelegate : public GetUpdatesDelegate {
106 PollGetUpdatesDelegate();
107 virtual ~PollGetUpdatesDelegate();
109 // Sets the 'source' and 'origin' to indicate this is a poll request.
110 virtual void HelpPopulateGuMessage(
111 sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
113 // Applies updates on the appropriate data type thread.
114 virtual void ApplyUpdates(
115 sessions::StatusController* status,
116 UpdateHandlerMap* update_handler_map) const OVERRIDE;
119 DISALLOW_COPY_AND_ASSIGN(PollGetUpdatesDelegate);
122 } // namespace syncer
124 #endif // SYNC_ENGINE_GET_UPDATES_DELEGATE_H_