OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_API_FAKE_MODEL_TYPE_SERVICE_H_ | 5 #ifndef COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ |
6 #define COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ | 6 #define COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "components/sync/api/entity_data.h" | 11 #include "components/sync/api/entity_data.h" |
12 #include "components/sync/api/metadata_batch.h" | 12 #include "components/sync/api/metadata_batch.h" |
13 #include "components/sync/api/model_type_service.h" | 13 #include "components/sync/api/model_type_service.h" |
14 #include "components/sync/core/non_blocking_sync_common.h" | 14 #include "components/sync/core/non_blocking_sync_common.h" |
15 #include "components/sync/protocol/data_type_state.pb.h" | 15 #include "components/sync/protocol/data_type_state.pb.h" |
16 #include "components/sync/protocol/entity_metadata.pb.h" | 16 #include "components/sync/protocol/entity_metadata.pb.h" |
17 | 17 |
18 namespace syncer_v2 { | 18 namespace syncer { |
19 | 19 |
20 // A basic, functional implementation of ModelTypeService for testing purposes. | 20 // A basic, functional implementation of ModelTypeService for testing purposes. |
21 // It uses the PREFERENCES type to provide a simple key/value interface, and | 21 // It uses the PREFERENCES type to provide a simple key/value interface, and |
22 // uses its own simple in-memory Store class. | 22 // uses its own simple in-memory Store class. |
23 class FakeModelTypeService : public ModelTypeService { | 23 class FakeModelTypeService : public ModelTypeService { |
24 public: | 24 public: |
25 // Generate a client tag with the given key. | 25 // Generate a client tag with the given key. |
26 static std::string ClientTagFromKey(const std::string& key); | 26 static std::string ClientTagFromKey(const std::string& key); |
27 | 27 |
28 // Generates the tag hash for a given key. | 28 // Generates the tag hash for a given key. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 // Overloaded form to allow passing of custom entity data. | 95 // Overloaded form to allow passing of custom entity data. |
96 void WriteItem(const std::string& key, | 96 void WriteItem(const std::string& key, |
97 std::unique_ptr<EntityData> entity_data); | 97 std::unique_ptr<EntityData> entity_data); |
98 | 98 |
99 // Local data deletion. | 99 // Local data deletion. |
100 void DeleteItem(const std::string& key); | 100 void DeleteItem(const std::string& key); |
101 | 101 |
102 // ModelTypeService implementation | 102 // ModelTypeService implementation |
103 std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() override; | 103 std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() override; |
104 syncer::SyncError MergeSyncData( | 104 SyncError MergeSyncData( |
105 std::unique_ptr<MetadataChangeList> metadata_change_list, | 105 std::unique_ptr<MetadataChangeList> metadata_change_list, |
106 EntityDataMap entity_data_map) override; | 106 EntityDataMap entity_data_map) override; |
107 syncer::SyncError ApplySyncChanges( | 107 SyncError ApplySyncChanges( |
108 std::unique_ptr<MetadataChangeList> metadata_change_list, | 108 std::unique_ptr<MetadataChangeList> metadata_change_list, |
109 EntityChangeList entity_changes) override; | 109 EntityChangeList entity_changes) override; |
110 void GetData(StorageKeyList storage_keys, DataCallback callback) override; | 110 void GetData(StorageKeyList storage_keys, DataCallback callback) override; |
111 void GetAllData(DataCallback callback) override; | 111 void GetAllData(DataCallback callback) override; |
112 std::string GetClientTag(const EntityData& entity_data) override; | 112 std::string GetClientTag(const EntityData& entity_data) override; |
113 std::string GetStorageKey(const EntityData& entity_data) override; | 113 std::string GetStorageKey(const EntityData& entity_data) override; |
114 void OnChangeProcessorSet() override; | 114 void OnChangeProcessorSet() override; |
115 ConflictResolution ResolveConflict( | 115 ConflictResolution ResolveConflict( |
116 const EntityData& local_data, | 116 const EntityData& local_data, |
117 const EntityData& remote_data) const override; | 117 const EntityData& remote_data) const override; |
118 | 118 |
119 // Store a resolution for the next call to ResolveConflict. Note that if this | 119 // Store a resolution for the next call to ResolveConflict. Note that if this |
120 // is a USE_NEW resolution, the data will only exist for one resolve call. | 120 // is a USE_NEW resolution, the data will only exist for one resolve call. |
121 void SetConflictResolution(ConflictResolution resolution); | 121 void SetConflictResolution(ConflictResolution resolution); |
122 | 122 |
123 // Sets the error that the next fallible call to the service will generate. | 123 // Sets the error that the next fallible call to the service will generate. |
124 void SetServiceError(syncer::SyncError::ErrorType error_type); | 124 void SetServiceError(SyncError::ErrorType error_type); |
125 | 125 |
126 const Store& db() const { return db_; } | 126 const Store& db() const { return db_; } |
127 | 127 |
128 protected: | 128 protected: |
129 // Used to verify conditions upon destruction. | 129 // Used to verify conditions upon destruction. |
130 virtual void CheckPostConditions(); | 130 virtual void CheckPostConditions(); |
131 | 131 |
132 // Contains all of the data and metadata state. | 132 // Contains all of the data and metadata state. |
133 Store db_; | 133 Store db_; |
134 | 134 |
135 private: | 135 private: |
136 // Applies |change_list| to the metadata store. | 136 // Applies |change_list| to the metadata store. |
137 void ApplyMetadataChangeList(std::unique_ptr<MetadataChangeList> change_list); | 137 void ApplyMetadataChangeList(std::unique_ptr<MetadataChangeList> change_list); |
138 | 138 |
139 // The conflict resolution to use for calls to ResolveConflict. | 139 // The conflict resolution to use for calls to ResolveConflict. |
140 std::unique_ptr<ConflictResolution> conflict_resolution_; | 140 std::unique_ptr<ConflictResolution> conflict_resolution_; |
141 | 141 |
142 // The error to produce on the next service call. | 142 // The error to produce on the next service call. |
143 syncer::SyncError service_error_; | 143 SyncError service_error_; |
144 }; | 144 }; |
145 | 145 |
146 } // namespace syncer_v2 | 146 } // namespace syncer |
147 | 147 |
148 #endif // COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ | 148 #endif // COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ |
OLD | NEW |