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.
5 #ifndef SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_
6 #define SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_
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"
16 class DataTypeProgressMarker;
17 class GetUpdatesResponse;
23 class StatusController;
30 // This class represents the syncable::Directory's processes for requesting and
31 // processing updates from the sync server.
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 {
38 SyncDirectoryUpdateHandler(syncable::Directory* dir, ModelType type);
39 ~SyncDirectoryUpdateHandler();
41 // Fills the given parameter with the stored progress marker for this type.
42 void GetDownloadProgress(
43 sync_pb::DataTypeProgressMarker* progress_marker) const;
45 // Processes the contents of a GetUpdates response message.
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);
57 friend class SyncDirectoryUpdateHandlerTest;
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);
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);
71 syncable::Directory* dir_;
74 DISALLOW_COPY_AND_ASSIGN(SyncDirectoryUpdateHandler);
77 // TODO(rlarocque): Find a better place to define this.
78 typedef std::map<ModelType, SyncDirectoryUpdateHandler*> UpdateHandlerMap;
82 #endif // SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_