| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_SYNC_ENGINE_IMPL_DIRECTORY_UPDATE_HANDLER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_DIRECTORY_UPDATE_HANDLER_H_ |
| 6 #define COMPONENTS_SYNC_ENGINE_IMPL_DIRECTORY_UPDATE_HANDLER_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_DIRECTORY_UPDATE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "components/sync/base/model_type.h" | 13 #include "components/sync/base/model_type.h" |
| 14 #include "components/sync/base/syncer_error.h" | 14 #include "components/sync/base/syncer_error.h" |
| 15 #include "components/sync/engine_impl/process_updates_util.h" | 15 #include "components/sync/engine_impl/process_updates_util.h" |
| 16 #include "components/sync/engine_impl/update_handler.h" | 16 #include "components/sync/engine_impl/update_handler.h" |
| 17 | 17 |
| 18 namespace sync_pb { | 18 namespace sync_pb { |
| 19 class DataTypeProgressMarker; | 19 class DataTypeProgressMarker; |
| 20 class GarbageCollectionDirective; | 20 class GarbageCollectionDirective; |
| 21 class GetUpdatesResponse; | 21 class GetUpdatesResponse; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace syncer { | 24 namespace syncer { |
| 25 | 25 |
| 26 namespace sessions { | 26 class DirectoryTypeDebugInfoEmitter; |
| 27 class ModelSafeWorker; |
| 27 class StatusController; | 28 class StatusController; |
| 28 } | |
| 29 | 29 |
| 30 namespace syncable { | 30 namespace syncable { |
| 31 class Directory; | 31 class Directory; |
| 32 } | 32 } |
| 33 | 33 |
| 34 class DirectoryTypeDebugInfoEmitter; | |
| 35 class ModelSafeWorker; | |
| 36 | |
| 37 // This class represents the syncable::Directory's processes for requesting and | 34 // This class represents the syncable::Directory's processes for requesting and |
| 38 // processing updates from the sync server. | 35 // processing updates from the sync server. |
| 39 // | 36 // |
| 40 // Each instance of this class represents a particular type in the | 37 // Each instance of this class represents a particular type in the |
| 41 // 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. |
| 42 // 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. |
| 43 class DirectoryUpdateHandler : public UpdateHandler { | 40 class DirectoryUpdateHandler : public UpdateHandler { |
| 44 public: | 41 public: |
| 45 DirectoryUpdateHandler(syncable::Directory* dir, | 42 DirectoryUpdateHandler(syncable::Directory* dir, |
| 46 ModelType type, | 43 ModelType type, |
| 47 scoped_refptr<ModelSafeWorker> worker, | 44 scoped_refptr<ModelSafeWorker> worker, |
| 48 DirectoryTypeDebugInfoEmitter* debug_info_emitter); | 45 DirectoryTypeDebugInfoEmitter* debug_info_emitter); |
| 49 ~DirectoryUpdateHandler() override; | 46 ~DirectoryUpdateHandler() override; |
| 50 | 47 |
| 51 // UpdateHandler implementation. | 48 // UpdateHandler implementation. |
| 52 bool IsInitialSyncEnded() const override; | 49 bool IsInitialSyncEnded() const override; |
| 53 void GetDownloadProgress( | 50 void GetDownloadProgress( |
| 54 sync_pb::DataTypeProgressMarker* progress_marker) const override; | 51 sync_pb::DataTypeProgressMarker* progress_marker) const override; |
| 55 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override; | 52 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override; |
| 56 SyncerError ProcessGetUpdatesResponse( | 53 SyncerError ProcessGetUpdatesResponse( |
| 57 const sync_pb::DataTypeProgressMarker& progress_marker, | 54 const sync_pb::DataTypeProgressMarker& progress_marker, |
| 58 const sync_pb::DataTypeContext& mutated_context, | 55 const sync_pb::DataTypeContext& mutated_context, |
| 59 const SyncEntityList& applicable_updates, | 56 const SyncEntityList& applicable_updates, |
| 60 sessions::StatusController* status) override; | 57 StatusController* status) override; |
| 61 void ApplyUpdates(sessions::StatusController* status) override; | 58 void ApplyUpdates(StatusController* status) override; |
| 62 void PassiveApplyUpdates(sessions::StatusController* status) override; | 59 void PassiveApplyUpdates(StatusController* status) override; |
| 63 | 60 |
| 64 private: | 61 private: |
| 65 friend class DirectoryUpdateHandlerApplyUpdateTest; | 62 friend class DirectoryUpdateHandlerApplyUpdateTest; |
| 66 friend class DirectoryUpdateHandlerProcessUpdateTest; | 63 friend class DirectoryUpdateHandlerProcessUpdateTest; |
| 67 | 64 |
| 68 // Sometimes there is nothing to do, so we can return without doing anything. | 65 // Sometimes there is nothing to do, so we can return without doing anything. |
| 69 bool IsApplyUpdatesRequired(); | 66 bool IsApplyUpdatesRequired(); |
| 70 | 67 |
| 71 // Called at the end of ApplyUpdates and PassiveApplyUpdates and performs | 68 // Called at the end of ApplyUpdates and PassiveApplyUpdates and performs |
| 72 // steps common to both (even when IsApplyUpdatesRequired has returned | 69 // steps common to both (even when IsApplyUpdatesRequired has returned |
| 73 // false). | 70 // false). |
| 74 void PostApplyUpdates(); | 71 void PostApplyUpdates(); |
| 75 | 72 |
| 76 // Processes the given SyncEntities and stores their data in the directory. | 73 // Processes the given SyncEntities and stores their data in the directory. |
| 77 // Their types must match this update handler's type. | 74 // Their types must match this update handler's type. |
| 78 void UpdateSyncEntities(syncable::ModelNeutralWriteTransaction* trans, | 75 void UpdateSyncEntities(syncable::ModelNeutralWriteTransaction* trans, |
| 79 const SyncEntityList& applicable_updates, | 76 const SyncEntityList& applicable_updates, |
| 80 sessions::StatusController* status); | 77 StatusController* status); |
| 81 | 78 |
| 82 // Expires entries according to GC directives. | 79 // Expires entries according to GC directives. |
| 83 void ExpireEntriesIfNeeded( | 80 void ExpireEntriesIfNeeded( |
| 84 syncable::ModelNeutralWriteTransaction* trans, | 81 syncable::ModelNeutralWriteTransaction* trans, |
| 85 const sync_pb::DataTypeProgressMarker& progress_marker); | 82 const sync_pb::DataTypeProgressMarker& progress_marker); |
| 86 | 83 |
| 87 // Stores the given progress marker in the directory. | 84 // Stores the given progress marker in the directory. |
| 88 // Its type must match this update handler's type. | 85 // Its type must match this update handler's type. |
| 89 void UpdateProgressMarker( | 86 void UpdateProgressMarker( |
| 90 const sync_pb::DataTypeProgressMarker& progress_marker); | 87 const sync_pb::DataTypeProgressMarker& progress_marker); |
| 91 | 88 |
| 92 bool IsValidProgressMarker( | 89 bool IsValidProgressMarker( |
| 93 const sync_pb::DataTypeProgressMarker& progress_marker) const; | 90 const sync_pb::DataTypeProgressMarker& progress_marker) const; |
| 94 | 91 |
| 95 // Skips all checks and goes straight to applying the updates. | 92 // Skips all checks and goes straight to applying the updates. |
| 96 SyncerError ApplyUpdatesImpl(sessions::StatusController* status); | 93 SyncerError ApplyUpdatesImpl(StatusController* status); |
| 97 | 94 |
| 98 // Creates root node for the handled model type. | 95 // Creates root node for the handled model type. |
| 99 void CreateTypeRoot(syncable::ModelNeutralWriteTransaction* trans); | 96 void CreateTypeRoot(syncable::ModelNeutralWriteTransaction* trans); |
| 100 | 97 |
| 101 syncable::Directory* dir_; | 98 syncable::Directory* dir_; |
| 102 ModelType type_; | 99 ModelType type_; |
| 103 scoped_refptr<ModelSafeWorker> worker_; | 100 scoped_refptr<ModelSafeWorker> worker_; |
| 104 DirectoryTypeDebugInfoEmitter* debug_info_emitter_; | 101 DirectoryTypeDebugInfoEmitter* debug_info_emitter_; |
| 105 | 102 |
| 106 std::unique_ptr<sync_pb::GarbageCollectionDirective> cached_gc_directive_; | 103 std::unique_ptr<sync_pb::GarbageCollectionDirective> cached_gc_directive_; |
| 107 | 104 |
| 108 DISALLOW_COPY_AND_ASSIGN(DirectoryUpdateHandler); | 105 DISALLOW_COPY_AND_ASSIGN(DirectoryUpdateHandler); |
| 109 }; | 106 }; |
| 110 | 107 |
| 111 } // namespace syncer | 108 } // namespace syncer |
| 112 | 109 |
| 113 #endif // COMPONENTS_SYNC_ENGINE_IMPL_DIRECTORY_UPDATE_HANDLER_H_ | 110 #endif // COMPONENTS_SYNC_ENGINE_IMPL_DIRECTORY_UPDATE_HANDLER_H_ |
| OLD | NEW |