summaryrefslogtreecommitdiffstats
path: root/sync/engine/process_updates_util.h
blob: 6e8bc71b859670ce3012a046584b73a6448abf51 (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
73
// Copyright 2013 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_PROCESS_UPDATES_UTIL_H_
#define SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_

#include <map>
#include <vector>

#include "base/compiler_specific.h"
#include "sync/base/sync_export.h"
#include "sync/engine/syncer_types.h"
#include "sync/internal_api/public/base/model_type.h"

namespace sync_pb {
class GetUpdatesResponse;
class SyncEntity;
}

namespace syncer {

namespace sessions {
class StatusController;
}

namespace syncable {
class ModelNeutralWriteTransaction;
class Directory;
}

class Cryptographer;

// TODO(rlarocque): Move these definitions somewhere else?
typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList;
typedef std::map<ModelType, SyncEntityList> TypeSyncEntityMap;

// Given a GetUpdates response, iterates over all the returned items and
// divides them according to their type.  Outputs a map from model types to
// received SyncEntities.  The output map will have entries (possibly empty)
// for all types in |requested_types|.
void PartitionUpdatesByType(
    const sync_pb::GetUpdatesResponse& updates,
    ModelTypeSet requested_types,
    TypeSyncEntityMap* updates_by_type);

// Processes all the updates associated with a single ModelType.
void ProcessDownloadedUpdates(
    syncable::Directory* dir,
    syncable::ModelNeutralWriteTransaction* trans,
    ModelType type,
    const SyncEntityList& applicable_updates,
    sessions::StatusController* status);

// Checks whether or not an update is fit for processing.
//
// The answer may be "no" if the update appears invalid, or it's not releveant
// (ie. a delete for an item we've never heard of), or other reasons.
VerifyResult VerifyUpdate(
    syncable::ModelNeutralWriteTransaction* trans,
    const sync_pb::SyncEntity& entry,
    ModelType requested_type);

// If the update passes a series of checks, this function will copy
// the SyncEntity's data into the SERVER side of the syncable::Directory.
void ProcessUpdate(
    const sync_pb::SyncEntity& proto_update,
    const Cryptographer* cryptographer,
    syncable::ModelNeutralWriteTransaction* const trans);

}  // namespace syncer

#endif  // SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_