| OLD | NEW |
| (Empty) |
| 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 "base/memory/ref_counted.h" | |
| 12 #include "sync/base/sync_export.h" | |
| 13 #include "sync/engine/process_updates_util.h" | |
| 14 #include "sync/internal_api/public/base/model_type.h" | |
| 15 #include "sync/internal_api/public/util/syncer_error.h" | |
| 16 | |
| 17 namespace sync_pb { | |
| 18 class DataTypeProgressMarker; | |
| 19 class GetUpdatesResponse; | |
| 20 } | |
| 21 | |
| 22 namespace syncer { | |
| 23 | |
| 24 namespace sessions { | |
| 25 class StatusController; | |
| 26 } | |
| 27 | |
| 28 namespace syncable { | |
| 29 class Directory; | |
| 30 } | |
| 31 | |
| 32 class ModelSafeWorker; | |
| 33 | |
| 34 // This class represents the syncable::Directory's processes for requesting and | |
| 35 // processing updates from the sync server. | |
| 36 // | |
| 37 // Each instance of this class represents a particular type in the | |
| 38 // syncable::Directory. It can store and retreive that type's progress markers. | |
| 39 // It can also process a set of received SyncEntities and store their data. | |
| 40 class SYNC_EXPORT_PRIVATE SyncDirectoryUpdateHandler { | |
| 41 public: | |
| 42 SyncDirectoryUpdateHandler(syncable::Directory* dir, | |
| 43 ModelType type, | |
| 44 scoped_refptr<ModelSafeWorker> worker); | |
| 45 ~SyncDirectoryUpdateHandler(); | |
| 46 | |
| 47 // Fills the given parameter with the stored progress marker for this type. | |
| 48 void GetDownloadProgress( | |
| 49 sync_pb::DataTypeProgressMarker* progress_marker) const; | |
| 50 | |
| 51 // Processes the contents of a GetUpdates response message. | |
| 52 // | |
| 53 // Should be invoked with the progress marker and set of SyncEntities from a | |
| 54 // single GetUpdates response message. The progress marker's type must match | |
| 55 // this update handler's type, and the set of SyncEntities must include all | |
| 56 // entities of this type found in the response message. | |
| 57 void ProcessGetUpdatesResponse( | |
| 58 const sync_pb::DataTypeProgressMarker& progress_marker, | |
| 59 const SyncEntityList& applicable_updates, | |
| 60 sessions::StatusController* status); | |
| 61 | |
| 62 // If there are updates to apply, apply them on the proper thread. | |
| 63 // Delegates to ApplyUpdatesImpl(). | |
| 64 void ApplyUpdates(sessions::StatusController* status); | |
| 65 | |
| 66 // Apply updates on the sync thread. This is for use during initial sync | |
| 67 // prior to model association. | |
| 68 void PassiveApplyUpdates(sessions::StatusController* status); | |
| 69 | |
| 70 private: | |
| 71 friend class SyncDirectoryUpdateHandlerApplyUpdateTest; | |
| 72 friend class SyncDirectoryUpdateHandlerProcessUpdateTest; | |
| 73 | |
| 74 // Sometimes there is nothing to do, so we can return without doing anything. | |
| 75 bool IsApplyUpdatesRequired(); | |
| 76 | |
| 77 // Processes the given SyncEntities and stores their data in the directory. | |
| 78 // Their types must match this update handler's type. | |
| 79 void UpdateSyncEntities( | |
| 80 syncable::ModelNeutralWriteTransaction* trans, | |
| 81 const SyncEntityList& applicable_updates, | |
| 82 sessions::StatusController* status); | |
| 83 | |
| 84 // Stores the given progress marker in the directory. | |
| 85 // Its type must match this update handler's type. | |
| 86 void UpdateProgressMarker( | |
| 87 const sync_pb::DataTypeProgressMarker& progress_marker); | |
| 88 | |
| 89 // Skips all checks and goes straight to applying the updates. | |
| 90 SyncerError ApplyUpdatesImpl(sessions::StatusController* status); | |
| 91 | |
| 92 syncable::Directory* dir_; | |
| 93 ModelType type_; | |
| 94 scoped_refptr<ModelSafeWorker> worker_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(SyncDirectoryUpdateHandler); | |
| 97 }; | |
| 98 | |
| 99 } // namespace syncer | |
| 100 | |
| 101 #endif // SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_ | |
| OLD | NEW |