summaryrefslogtreecommitdiffstats
path: root/sync/engine/get_updates_processor.h
blob: 13a9c83277dfbb892d2061145f6f21d60c7c9fd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SYNC_ENGINE_GET_UPDATES_PROCESSOR_H
#define SYNC_ENGINE_GET_UPDATES_PROCESSOR_H

#include <map>
#include <vector>

#include "base/basictypes.h"
#include "sync/base/sync_export.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/sessions/model_type_registry.h"

namespace sync_pb {
class GetUpdatesMessage;
class GetUpdatesResponse;
}  // namespace sync_pb

namespace syncer {

namespace sessions {
class StatusController;
}  // namespace sessions

namespace syncable {
class Directory;
}  // namespace syncable

class GetUpdatesDelegate;

// This class manages the set of per-type syncer objects.
//
// It owns these types and hides the details of iterating over all of them.
// Most methods allow the caller to specify a subset of types on which the
// operation is to be applied.  It is a logic error if the supplied set of types
// contains a type which was not previously registered with the manager.
class SYNC_EXPORT_PRIVATE GetUpdatesProcessor {
 public:
  explicit GetUpdatesProcessor(UpdateHandlerMap* update_handler_map,
                               const GetUpdatesDelegate& delegate);
  ~GetUpdatesProcessor();

  // Populates a GetUpdates request message with per-type information.
  void PrepareGetUpdates(ModelTypeSet gu_types,
                         sync_pb::GetUpdatesMessage* get_updates);

  // Processes a GetUpdates responses for each type.
  bool ProcessGetUpdatesResponse(
      ModelTypeSet gu_types,
      const sync_pb::GetUpdatesResponse& gu_response,
      sessions::StatusController* status_controller);

  // Hands off control to the delegate so it can apply updates.
  void ApplyUpdates(sessions::StatusController* status_controller);

 private:
  // A map of 'update handlers', one for each enabled type.
  // This must be kept in sync with the routing info.  Our temporary solution to
  // that problem is to initialize this map in set_routing_info().
  UpdateHandlerMap* update_handler_map_;

  const GetUpdatesDelegate& delegate_;

  DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessor);
};

}  // namespace syncer

#endif  // SYNC_ENGINE_GET_UPDATES_PROCESSOR_H_