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