blob: 950060ee28b7590e41eddee84ba05b892d8e07af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SYNC_API_MODEL_TYPE_SERVICE_H_
#define SYNC_API_MODEL_TYPE_SERVICE_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "sync/api/entity_change.h"
#include "sync/api/entity_data.h"
#include "sync/api/model_type_change_processor.h"
#include "sync/api/sync_error.h"
#include "sync/base/sync_export.h"
namespace syncer_v2 {
class DataBatch;
class MetadataChangeList;
// Interface implemented by model types to receive updates from sync via the
// SharedModelTypeProcessor. Provides a way for sync to update the data and
// metadata for entities, as well as the model type state.
class SYNC_EXPORT ModelTypeService {
public:
typedef base::Callback<void(syncer::SyncError, scoped_ptr<DataBatch>)>
DataCallback;
typedef std::vector<std::string> ClientTagList;
ModelTypeService();
virtual ~ModelTypeService();
// Creates an object used to communicate changes in the sync metadata to the
// model type store.
virtual scoped_ptr<MetadataChangeList> CreateMetadataChangeList() = 0;
// Perform the initial merge of data from the sync server. Should only need
// to be called when sync is first turned on, not on every restart.
virtual syncer::SyncError MergeSyncData(
scoped_ptr<MetadataChangeList> metadata_change_list,
EntityDataMap entity_data_map) = 0;
// Apply changes from the sync server locally.
// Please note that |entity_changes| might have fewer entries than
// |metadata_change_list| in case when some of the data changes are filtered
// out, or even be empty in case when a commit confirmation is processed and
// only the metadata needs to persisted.
virtual syncer::SyncError ApplySyncChanges(
scoped_ptr<MetadataChangeList> metadata_change_list,
EntityChangeList entity_changes) = 0;
// Asynchronously retrieve the corresponding sync data for |client_tags|.
virtual void GetData(ClientTagList client_tags, DataCallback callback) = 0;
// Asynchronously retrieve all of the local sync data.
virtual void GetAllData(DataCallback callback) = 0;
// Get or generate a client tag for |entity_data|.
virtual std::string GetClientTag(const EntityData& entity_data) = 0;
// Overridable notification for when the processor is set. This is typically
// when the service should start loading metadata and then subsequently giving
// it to the processor.
virtual void OnChangeProcessorSet() = 0;
// TODO(skym): See crbug/547087, do we need all these accessors?
ModelTypeChangeProcessor* change_processor() const;
void set_change_processor(
scoped_ptr<ModelTypeChangeProcessor> change_processor);
void clear_change_processor();
private:
// Recieves ownership in set_change_processor(...).
scoped_ptr<ModelTypeChangeProcessor> change_processor_;
};
} // namespace syncer_v2
#endif // SYNC_API_MODEL_TYPE_SERVICE_H_
|