OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_ | 5 #ifndef SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_ |
6 #define SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_ | 6 #define SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_ |
7 | 7 |
8 #include <map> | |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "base/compiler_specific.h" | |
12 #include "sync/base/sync_export.h" | |
13 #include "sync/engine/syncer_types.h" | |
14 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
15 | 11 |
16 namespace sync_pb { | 12 namespace sync_pb { |
17 class GetUpdatesResponse; | |
18 class SyncEntity; | 13 class SyncEntity; |
19 } | 14 } |
20 | 15 |
21 namespace syncer { | 16 namespace syncer { |
22 | 17 |
23 namespace sessions { | 18 namespace sessions { |
24 class StatusController; | 19 class StatusController; |
25 } | 20 } |
26 | 21 |
27 namespace syncable { | 22 namespace syncable { |
28 class ModelNeutralWriteTransaction; | 23 class ModelNeutralWriteTransaction; |
29 class Directory; | 24 class Directory; |
30 } | 25 } |
31 | 26 |
32 class Cryptographer; | |
33 | |
34 // TODO(rlarocque): Move these definitions somewhere else? | |
35 typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList; | 27 typedef std::vector<const sync_pb::SyncEntity*> SyncEntityList; |
36 typedef std::map<ModelType, SyncEntityList> TypeSyncEntityMap; | |
37 | |
38 // Given a GetUpdates response, iterates over all the returned items and | |
39 // divides them according to their type. Outputs a map from model types to | |
40 // received SyncEntities. The output map will have entries (possibly empty) | |
41 // for all types in |requested_types|. | |
42 void PartitionUpdatesByType( | |
43 const sync_pb::GetUpdatesResponse& updates, | |
44 ModelTypeSet requested_types, | |
45 TypeSyncEntityMap* updates_by_type); | |
46 | 28 |
47 // Processes all the updates associated with a single ModelType. | 29 // Processes all the updates associated with a single ModelType. |
48 void ProcessDownloadedUpdates( | 30 void ProcessDownloadedUpdates( |
49 syncable::Directory* dir, | 31 syncable::Directory* dir, |
50 syncable::ModelNeutralWriteTransaction* trans, | 32 syncable::ModelNeutralWriteTransaction* trans, |
51 ModelType type, | 33 ModelType type, |
52 const SyncEntityList& applicable_updates, | 34 const SyncEntityList& applicable_updates, |
53 sessions::StatusController* status); | 35 sessions::StatusController* status); |
54 | 36 |
55 // Checks whether or not an update is fit for processing. | |
56 // | |
57 // The answer may be "no" if the update appears invalid, or it's not releveant | |
58 // (ie. a delete for an item we've never heard of), or other reasons. | |
59 VerifyResult VerifyUpdate( | |
60 syncable::ModelNeutralWriteTransaction* trans, | |
61 const sync_pb::SyncEntity& entry, | |
62 ModelType requested_type); | |
63 | |
64 // If the update passes a series of checks, this function will copy | |
65 // the SyncEntity's data into the SERVER side of the syncable::Directory. | |
66 void ProcessUpdate( | |
67 const sync_pb::SyncEntity& proto_update, | |
68 const Cryptographer* cryptographer, | |
69 syncable::ModelNeutralWriteTransaction* const trans); | |
70 | |
71 } // namespace syncer | 37 } // namespace syncer |
72 | 38 |
73 #endif // SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_ | 39 #endif // SYNC_ENGINE_PROCESS_UPDATES_UTIL_H_ |
OLD | NEW |