Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / sync / engine / get_updates_delegate.h
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 "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"
12
13 namespace syncer {
14
15 class GetUpdatesProcessor;
16
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
20 // on construction.
21 class SYNC_EXPORT_PRIVATE GetUpdatesDelegate {
22  public:
23   GetUpdatesDelegate();
24   virtual ~GetUpdatesDelegate() = 0;
25
26   // Populates GetUpdate message fields that depende on GetUpdates request type.
27   virtual void HelpPopulateGuMessage(
28       sync_pb::GetUpdatesMessage* get_updates) const = 0;
29
30   // Applies pending updates to non-control types.
31   virtual void ApplyUpdates(
32       sessions::StatusController* session,
33       UpdateHandlerMap* update_handler_map) const = 0;
34 };
35
36 // Functionality specific to the normal GetUpdate request.
37 class SYNC_EXPORT_PRIVATE NormalGetUpdatesDelegate : public GetUpdatesDelegate {
38  public:
39   NormalGetUpdatesDelegate(const sessions::NudgeTracker& nudge_tracker);
40   virtual ~NormalGetUpdatesDelegate();
41
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;
45
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;
50
51  private:
52   DISALLOW_COPY_AND_ASSIGN(NormalGetUpdatesDelegate);
53
54   const sessions::NudgeTracker& nudge_tracker_;
55 };
56
57 // Functionality specific to the retry GetUpdate request.
58 class SYNC_EXPORT_PRIVATE RetryGetUpdatesDelegate : public GetUpdatesDelegate {
59  public:
60   RetryGetUpdatesDelegate();
61   virtual ~RetryGetUpdatesDelegate();
62
63   virtual void HelpPopulateGuMessage(
64       sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
65
66   virtual void ApplyUpdates(
67       sessions::StatusController* status,
68       UpdateHandlerMap* update_handler_map) const OVERRIDE;
69
70  private:
71   DISALLOW_COPY_AND_ASSIGN(RetryGetUpdatesDelegate);
72 };
73
74 // Functionality specific to the configure GetUpdate request.
75 class SYNC_EXPORT_PRIVATE ConfigureGetUpdatesDelegate
76     : public GetUpdatesDelegate {
77  public:
78   ConfigureGetUpdatesDelegate(
79       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
80   virtual ~ConfigureGetUpdatesDelegate();
81
82   // Sets the 'source' and 'origin' fields for this request.
83   virtual void HelpPopulateGuMessage(
84       sync_pb::GetUpdatesMessage* get_updates) const OVERRIDE;
85
86   // Applies updates passively (ie. on the sync thread).
87   //
88   // This is safe only if the ChangeProcessor is not listening to changes at
89   // this time.
90   virtual void ApplyUpdates(
91       sessions::StatusController* status,
92       UpdateHandlerMap* update_handler_map) const OVERRIDE;
93
94  private:
95   DISALLOW_COPY_AND_ASSIGN(ConfigureGetUpdatesDelegate);
96
97   static sync_pb::SyncEnums::GetUpdatesOrigin ConvertConfigureSourceToOrigin(
98       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
99
100   const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source_;
101 };
102
103 // Functionality specific to the poll GetUpdate request.
104 class SYNC_EXPORT_PRIVATE PollGetUpdatesDelegate : public GetUpdatesDelegate {
105  public:
106   PollGetUpdatesDelegate();
107   virtual ~PollGetUpdatesDelegate();
108
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;
112
113   // Applies updates on the appropriate data type thread.
114   virtual void ApplyUpdates(
115       sessions::StatusController* status,
116       UpdateHandlerMap* update_handler_map) const OVERRIDE;
117
118  private:
119   DISALLOW_COPY_AND_ASSIGN(PollGetUpdatesDelegate);
120 };
121
122 }  // namespace syncer
123
124 #endif   // SYNC_ENGINE_GET_UPDATES_DELEGATE_H_