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_
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"
20 class DataTypeProgressMarker
;
21 class GarbageCollectionDirective
;
22 class GetUpdatesResponse
;
28 class StatusController
;
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
{
46 DirectoryUpdateHandler(syncable::Directory
* dir
,
48 scoped_refptr
<ModelSafeWorker
> worker
,
49 DirectoryTypeDebugInfoEmitter
* debug_info_emitter
);
50 virtual ~DirectoryUpdateHandler();
52 // UpdateHandler implementation.
53 virtual void GetDownloadProgress(
54 sync_pb::DataTypeProgressMarker
* progress_marker
) const OVERRIDE
;
55 virtual void GetDataTypeContext(sync_pb::DataTypeContext
* context
) const
57 virtual 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 virtual void ApplyUpdates(sessions::StatusController
* status
) OVERRIDE
;
63 virtual void PassiveApplyUpdates(sessions::StatusController
* status
) OVERRIDE
;
66 friend class DirectoryUpdateHandlerApplyUpdateTest
;
67 friend class DirectoryUpdateHandlerProcessUpdateTest
;
69 // Sometimes there is nothing to do, so we can return without doing anything.
70 bool IsApplyUpdatesRequired();
72 // Processes the given SyncEntities and stores their data in the directory.
73 // Their types must match this update handler's type.
74 void UpdateSyncEntities(
75 syncable::ModelNeutralWriteTransaction
* trans
,
76 const SyncEntityList
& applicable_updates
,
77 sessions::StatusController
* status
);
79 // Expires entries according to GC directives.
80 void ExpireEntriesIfNeeded(
81 syncable::ModelNeutralWriteTransaction
* trans
,
82 const sync_pb::DataTypeProgressMarker
& progress_marker
);
84 // Stores the given progress marker in the directory.
85 // Its type must match this update handler's type.
86 void UpdateProgressMarker(
87 const sync_pb::DataTypeProgressMarker
& progress_marker
);
89 bool IsValidProgressMarker(
90 const sync_pb::DataTypeProgressMarker
& progress_marker
) const;
92 // Skips all checks and goes straight to applying the updates.
93 SyncerError
ApplyUpdatesImpl(sessions::StatusController
* status
);
95 syncable::Directory
* dir_
;
97 scoped_refptr
<ModelSafeWorker
> worker_
;
98 DirectoryTypeDebugInfoEmitter
* debug_info_emitter_
;
100 scoped_ptr
<sync_pb::GarbageCollectionDirective
> cached_gc_directive_
;
102 DISALLOW_COPY_AND_ASSIGN(DirectoryUpdateHandler
);
105 } // namespace syncer
107 #endif // SYNC_ENGINE_DIRECTORY_UPDATE_HANDLER_H_