- add sources.
[platform/framework/web/crosswalk.git] / src / sync / engine / sync_directory_update_handler.h
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
3 // found in the LICENSE file.
4
5 #ifndef SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_
6 #define SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "sync/base/sync_export.h"
12 #include "sync/engine/process_updates_util.h"
13 #include "sync/internal_api/public/base/model_type.h"
14
15 namespace sync_pb {
16 class DataTypeProgressMarker;
17 class GetUpdatesResponse;
18 }
19
20 namespace syncer {
21
22 namespace sessions {
23 class StatusController;
24 }
25
26 namespace syncable {
27 class Directory;
28 }
29
30 // This class represents the syncable::Directory's processes for requesting and
31 // processing updates from the sync server.
32 //
33 // Each instance of this class represents a particular type in the
34 // syncable::Directory.  It can store and retreive that type's progress markers.
35 // It can also process a set of received SyncEntities and store their data.
36 class SYNC_EXPORT_PRIVATE SyncDirectoryUpdateHandler {
37  public:
38   SyncDirectoryUpdateHandler(syncable::Directory* dir, ModelType type);
39   ~SyncDirectoryUpdateHandler();
40
41   // Fills the given parameter with the stored progress marker for this type.
42   void GetDownloadProgress(
43       sync_pb::DataTypeProgressMarker* progress_marker) const;
44
45   // Processes the contents of a GetUpdates response message.
46   //
47   // Should be invoked with the progress marker and set of SyncEntities from a
48   // single GetUpdates response message.  The progress marker's type must match
49   // this update handler's type, and the set of SyncEntities must include all
50   // entities of this type found in the response message.
51   void ProcessGetUpdatesResponse(
52       const sync_pb::DataTypeProgressMarker& progress_marker,
53       const SyncEntityList& applicable_updates,
54       sessions::StatusController* status);
55
56  private:
57   friend class SyncDirectoryUpdateHandlerTest;
58
59   // Processes the given SyncEntities and stores their data in the directory.
60   // Their types must match this update handler's type.
61   void UpdateSyncEntities(
62       syncable::ModelNeutralWriteTransaction* trans,
63       const SyncEntityList& applicable_updates,
64       sessions::StatusController* status);
65
66   // Stores the given progress marker in the directory.
67   // Its type must match this update handler's type.
68   void UpdateProgressMarker(
69       const sync_pb::DataTypeProgressMarker& progress_marker);
70
71   syncable::Directory* dir_;
72   ModelType type_;
73
74   DISALLOW_COPY_AND_ASSIGN(SyncDirectoryUpdateHandler);
75 };
76
77 // TODO(rlarocque): Find a better place to define this.
78 typedef std::map<ModelType, SyncDirectoryUpdateHandler*> UpdateHandlerMap;
79
80 }  // namespace syncer
81
82 #endif  // SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_