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