Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / sync / engine / directory_update_handler.h
blob246d412a87d274f12487b9ff89da2168284dda57
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.
5 #ifndef SYNC_ENGINE_DIRECTORY_UPDATE_HANDLER_H_
6 #define SYNC_ENGINE_DIRECTORY_UPDATE_HANDLER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.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"
19 namespace sync_pb {
20 class DataTypeProgressMarker;
21 class GarbageCollectionDirective;
22 class GetUpdatesResponse;
25 namespace syncer {
27 namespace sessions {
28 class StatusController;
31 namespace syncable {
32 class Directory;
35 class DirectoryTypeDebugInfoEmitter;
36 class ModelSafeWorker;
38 // This class represents the syncable::Directory's processes for requesting and
39 // processing updates from the sync server.
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_PRIVATE 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;
52 // UpdateHandler implementation.
53 void GetDownloadProgress(
54 sync_pb::DataTypeProgressMarker* progress_marker) const override;
55 void GetDataTypeContext(sync_pb::DataTypeContext* context) const override;
56 SyncerError ProcessGetUpdatesResponse(
57 const sync_pb::DataTypeProgressMarker& progress_marker,
58 const sync_pb::DataTypeContext& mutated_context,
59 const SyncEntityList& applicable_updates,
60 sessions::StatusController* status) override;
61 void ApplyUpdates(sessions::StatusController* status) override;
62 void PassiveApplyUpdates(sessions::StatusController* status) override;
64 private:
65 friend class DirectoryUpdateHandlerApplyUpdateTest;
66 friend class DirectoryUpdateHandlerProcessUpdateTest;
68 // Sometimes there is nothing to do, so we can return without doing anything.
69 bool IsApplyUpdatesRequired();
71 // Processes the given SyncEntities and stores their data in the directory.
72 // Their types must match this update handler's type.
73 void UpdateSyncEntities(
74 syncable::ModelNeutralWriteTransaction* trans,
75 const SyncEntityList& applicable_updates,
76 sessions::StatusController* status);
78 // Expires entries according to GC directives.
79 void ExpireEntriesIfNeeded(
80 syncable::ModelNeutralWriteTransaction* trans,
81 const sync_pb::DataTypeProgressMarker& progress_marker);
83 // Stores the given progress marker in the directory.
84 // Its type must match this update handler's type.
85 void UpdateProgressMarker(
86 const sync_pb::DataTypeProgressMarker& progress_marker);
88 bool IsValidProgressMarker(
89 const sync_pb::DataTypeProgressMarker& progress_marker) const;
91 // Skips all checks and goes straight to applying the updates.
92 SyncerError ApplyUpdatesImpl(sessions::StatusController* status);
94 // Creates root node for the handled model type.
95 void CreateTypeRoot(syncable::ModelNeutralWriteTransaction* trans);
97 syncable::Directory* dir_;
98 ModelType type_;
99 scoped_refptr<ModelSafeWorker> worker_;
100 DirectoryTypeDebugInfoEmitter* debug_info_emitter_;
102 scoped_ptr<sync_pb::GarbageCollectionDirective> cached_gc_directive_;
104 DISALLOW_COPY_AND_ASSIGN(DirectoryUpdateHandler);
107 } // namespace syncer
109 #endif // SYNC_ENGINE_DIRECTORY_UPDATE_HANDLER_H_