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