Chromium Code Reviews| 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/engine/model_safe_worker.h" | |
|
Nicolas Zea
2013/11/19 22:45:26
I think you can probably forward declare this
rlarocque
2013/11/21 18:28:47
Done.
| |
| 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 |
| 30 // This class represents the syncable::Directory's processes for requesting and | 32 // This class represents the syncable::Directory's processes for requesting and |
| 31 // processing updates from the sync server. | 33 // processing updates from the sync server. |
| 32 // | 34 // |
| 33 // Each instance of this class represents a particular type in the | 35 // Each instance of this class represents a particular type in the |
| 34 // syncable::Directory. It can store and retreive that type's progress markers. | 36 // 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. | 37 // It can also process a set of received SyncEntities and store their data. |
| 36 class SYNC_EXPORT_PRIVATE SyncDirectoryUpdateHandler { | 38 class SYNC_EXPORT_PRIVATE SyncDirectoryUpdateHandler { |
| 37 public: | 39 public: |
| 38 SyncDirectoryUpdateHandler(syncable::Directory* dir, ModelType type); | 40 SyncDirectoryUpdateHandler(syncable::Directory* dir, |
| 41 ModelType type, | |
| 42 scoped_refptr<ModelSafeWorker> worker); | |
| 39 ~SyncDirectoryUpdateHandler(); | 43 ~SyncDirectoryUpdateHandler(); |
| 40 | 44 |
| 41 // Fills the given parameter with the stored progress marker for this type. | 45 // Fills the given parameter with the stored progress marker for this type. |
| 42 void GetDownloadProgress( | 46 void GetDownloadProgress( |
| 43 sync_pb::DataTypeProgressMarker* progress_marker) const; | 47 sync_pb::DataTypeProgressMarker* progress_marker) const; |
| 44 | 48 |
| 45 // Processes the contents of a GetUpdates response message. | 49 // Processes the contents of a GetUpdates response message. |
| 46 // | 50 // |
| 47 // Should be invoked with the progress marker and set of SyncEntities from a | 51 // 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 | 52 // 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 | 53 // this update handler's type, and the set of SyncEntities must include all |
| 50 // entities of this type found in the response message. | 54 // entities of this type found in the response message. |
| 51 void ProcessGetUpdatesResponse( | 55 void ProcessGetUpdatesResponse( |
| 52 const sync_pb::DataTypeProgressMarker& progress_marker, | 56 const sync_pb::DataTypeProgressMarker& progress_marker, |
| 53 const SyncEntityList& applicable_updates, | 57 const SyncEntityList& applicable_updates, |
| 54 sessions::StatusController* status); | 58 sessions::StatusController* status); |
| 55 | 59 |
| 60 // If there are updates to apply, apply them on the proper thread. | |
| 61 // Delegates to ApplyUpdatesImpl(). | |
| 62 void ApplyUpdates(sessions::StatusController* status); | |
| 63 | |
| 56 private: | 64 private: |
| 57 friend class SyncDirectoryUpdateHandlerTest; | 65 friend class SyncDirectoryUpdateHandlerApplyUpdateTest; |
| 66 friend class SyncDirectoryUpdateHandlerProcessUpdateTest; | |
| 58 | 67 |
| 59 // Processes the given SyncEntities and stores their data in the directory. | 68 // Processes the given SyncEntities and stores their data in the directory. |
| 60 // Their types must match this update handler's type. | 69 // Their types must match this update handler's type. |
| 61 void UpdateSyncEntities( | 70 void UpdateSyncEntities( |
| 62 syncable::ModelNeutralWriteTransaction* trans, | 71 syncable::ModelNeutralWriteTransaction* trans, |
| 63 const SyncEntityList& applicable_updates, | 72 const SyncEntityList& applicable_updates, |
| 64 sessions::StatusController* status); | 73 sessions::StatusController* status); |
| 65 | 74 |
| 66 // Stores the given progress marker in the directory. | 75 // Stores the given progress marker in the directory. |
| 67 // Its type must match this update handler's type. | 76 // Its type must match this update handler's type. |
| 68 void UpdateProgressMarker( | 77 void UpdateProgressMarker( |
| 69 const sync_pb::DataTypeProgressMarker& progress_marker); | 78 const sync_pb::DataTypeProgressMarker& progress_marker); |
| 70 | 79 |
| 80 // Skips all checks and goes straight to applying the updates. | |
| 81 SyncerError ApplyUpdatesImpl(sessions::StatusController* status); | |
| 82 | |
| 71 syncable::Directory* dir_; | 83 syncable::Directory* dir_; |
| 72 ModelType type_; | 84 ModelType type_; |
| 85 scoped_refptr<ModelSafeWorker> worker_; | |
| 73 | 86 |
| 74 DISALLOW_COPY_AND_ASSIGN(SyncDirectoryUpdateHandler); | 87 DISALLOW_COPY_AND_ASSIGN(SyncDirectoryUpdateHandler); |
| 75 }; | 88 }; |
| 76 | 89 |
| 77 // TODO(rlarocque): Find a better place to define this. | 90 // TODO(rlarocque): Find a better place to define this. |
| 78 typedef std::map<ModelType, SyncDirectoryUpdateHandler*> UpdateHandlerMap; | 91 typedef std::map<ModelType, SyncDirectoryUpdateHandler*> UpdateHandlerMap; |
| 79 | 92 |
| 80 } // namespace syncer | 93 } // namespace syncer |
| 81 | 94 |
| 82 #endif // SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_ | 95 #endif // SYNC_ENGINE_SYNC_DIRECTORY_UPDATE_HANDLER_H_ |
| OLD | NEW |