Index: components/sync/api/fake_model_type_service.h |
diff --git a/components/sync/api/fake_model_type_service.h b/components/sync/api/fake_model_type_service.h |
deleted file mode 100644 |
index 0107b3eecd08dac6a7f074444401455cd5fae242..0000000000000000000000000000000000000000 |
--- a/components/sync/api/fake_model_type_service.h |
+++ /dev/null |
@@ -1,149 +0,0 @@ |
-// 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 COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ |
-#define COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ |
- |
-#include <map> |
-#include <memory> |
-#include <string> |
- |
-#include "components/sync/api/entity_data.h" |
-#include "components/sync/api/metadata_batch.h" |
-#include "components/sync/api/model_type_service.h" |
-#include "components/sync/core/non_blocking_sync_common.h" |
-#include "components/sync/protocol/entity_metadata.pb.h" |
-#include "components/sync/protocol/model_type_state.pb.h" |
- |
-namespace syncer { |
- |
-// A basic, functional implementation of ModelTypeService for testing purposes. |
-// It uses the PREFERENCES type to provide a simple key/value interface, and |
-// uses its own simple in-memory Store class. |
-class FakeModelTypeService : public ModelTypeService { |
- public: |
- // Generate a client tag with the given key. |
- static std::string ClientTagFromKey(const std::string& key); |
- |
- // Generates the tag hash for a given key. |
- static std::string TagHashFromKey(const std::string& key); |
- |
- // Generates entity specifics for the given key and value. |
- static sync_pb::EntitySpecifics GenerateSpecifics(const std::string& key, |
- const std::string& value); |
- |
- // Generates an EntityData for the given key and value. |
- static std::unique_ptr<EntityData> GenerateEntityData( |
- const std::string& key, |
- const std::string& value); |
- |
- // A basic in-memory storage mechanism for data and metadata. This makes it |
- // easier to test more complex behaviors involving when entities are written, |
- // committed, etc. Having a separate class helps keep the main one cleaner. |
- class Store { |
- public: |
- Store(); |
- virtual ~Store(); |
- |
- void PutData(const std::string& key, const EntityData& data); |
- void PutMetadata(const std::string& key, |
- const sync_pb::EntityMetadata& metadata); |
- void RemoveData(const std::string& key); |
- void RemoveMetadata(const std::string& key); |
- bool HasData(const std::string& key) const; |
- bool HasMetadata(const std::string& key) const; |
- const EntityData& GetData(const std::string& key) const; |
- const std::string& GetValue(const std::string& key) const; |
- const sync_pb::EntityMetadata& GetMetadata(const std::string& key) const; |
- |
- const std::map<std::string, std::unique_ptr<EntityData>>& all_data() const { |
- return data_store_; |
- } |
- |
- size_t data_count() const { return data_store_.size(); } |
- size_t metadata_count() const { return metadata_store_.size(); } |
- size_t data_change_count() const { return data_change_count_; } |
- size_t metadata_change_count() const { return metadata_change_count_; } |
- |
- const sync_pb::ModelTypeState& model_type_state() const { |
- return model_type_state_; |
- } |
- |
- void set_model_type_state(const sync_pb::ModelTypeState& model_type_state) { |
- model_type_state_ = model_type_state; |
- } |
- |
- std::unique_ptr<MetadataBatch> CreateMetadataBatch() const; |
- void Reset(); |
- |
- private: |
- size_t data_change_count_ = 0; |
- size_t metadata_change_count_ = 0; |
- std::map<std::string, std::unique_ptr<EntityData>> data_store_; |
- std::map<std::string, sync_pb::EntityMetadata> metadata_store_; |
- sync_pb::ModelTypeState model_type_state_; |
- }; |
- |
- explicit FakeModelTypeService( |
- const ChangeProcessorFactory& change_processor_factory); |
- ~FakeModelTypeService() override; |
- |
- // Local data modification. Emulates signals from the model thread. |
- sync_pb::EntitySpecifics WriteItem(const std::string& key, |
- const std::string& value); |
- |
- // Overloaded form to allow passing of custom entity data. |
- void WriteItem(const std::string& key, |
- std::unique_ptr<EntityData> entity_data); |
- |
- // Local data deletion. |
- void DeleteItem(const std::string& key); |
- |
- // ModelTypeService implementation |
- std::unique_ptr<MetadataChangeList> CreateMetadataChangeList() override; |
- SyncError MergeSyncData( |
- std::unique_ptr<MetadataChangeList> metadata_change_list, |
- EntityDataMap entity_data_map) override; |
- SyncError ApplySyncChanges( |
- std::unique_ptr<MetadataChangeList> metadata_change_list, |
- EntityChangeList entity_changes) override; |
- void GetData(StorageKeyList storage_keys, DataCallback callback) override; |
- void GetAllData(DataCallback callback) override; |
- std::string GetClientTag(const EntityData& entity_data) override; |
- std::string GetStorageKey(const EntityData& entity_data) override; |
- void OnChangeProcessorSet() override; |
- ConflictResolution ResolveConflict( |
- const EntityData& local_data, |
- const EntityData& remote_data) const override; |
- |
- // Store a resolution for the next call to ResolveConflict. Note that if this |
- // is a USE_NEW resolution, the data will only exist for one resolve call. |
- void SetConflictResolution(ConflictResolution resolution); |
- |
- // Sets the error that the next fallible call to the service will generate. |
- void SetServiceError(SyncError::ErrorType error_type); |
- |
- const Store& db() const { return db_; } |
- |
- protected: |
- // Used to verify conditions upon destruction. |
- virtual void CheckPostConditions(); |
- |
- // Contains all of the data and metadata state. |
- Store db_; |
- |
- private: |
- // Applies |change_list| to the metadata store. |
- void ApplyMetadataChangeList(std::unique_ptr<MetadataChangeList> change_list); |
- |
- // The conflict resolution to use for calls to ResolveConflict. |
- std::unique_ptr<ConflictResolution> conflict_resolution_; |
- |
- // The error to produce on the next service call. |
- SyncError service_error_; |
-}; |
- |
-} // namespace syncer |
- |
-#endif // COMPONENTS_SYNC_API_FAKE_MODEL_TYPE_SERVICE_H_ |