| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_LOOPBACK_SERVER_LOOPBACK_SERVER_ENTITY_H_ |
| 6 #define COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_LOOPBACK_SERVER_LOOPBACK_SERVER_ENTITY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "components/sync/base/model_type.h" | 13 #include "components/sync/base/model_type.h" |
| 14 #include "components/sync/protocol/loopback_server.pb.h" |
| 14 #include "components/sync/protocol/sync.pb.h" | 15 #include "components/sync/protocol/sync.pb.h" |
| 15 | 16 |
| 16 namespace fake_server { | 17 namespace syncer { |
| 17 | 18 |
| 18 // The representation of a Sync entity for the fake server. | 19 // The representation of a Sync entity for the loopback server. |
| 19 class FakeServerEntity { | 20 class LoopbackServerEntity { |
| 20 public: | 21 public: |
| 21 // Creates an ID of the form <type><separator><inner-id> where | 22 // Creates an ID of the form <type><separator><inner-id> where |
| 22 // <type> is the EntitySpecifics field number for |model_type|, <separator> | 23 // <type> is the EntitySpecifics field number for |model_type|, <separator> |
| 23 // is kIdSeparator, and <inner-id> is |inner_id|. | 24 // is kIdSeparator, and <inner-id> is |inner_id|. |
| 24 // | 25 // |
| 25 // If |inner_id| is globally unique, then the returned ID will also be | 26 // If |inner_id| is globally unique, then the returned ID will also be |
| 26 // globally unique. | 27 // globally unique. |
| 27 static std::string CreateId(const syncer::ModelType& model_type, | 28 static std::string CreateId(const syncer::ModelType& model_type, |
| 28 const std::string& inner_id); | 29 const std::string& inner_id); |
| 29 | 30 |
| 30 // Returns the ID string of the top level node for the specified type. | 31 // Returns the ID string of the top level node for the specified type. |
| 31 static std::string GetTopLevelId(const syncer::ModelType& model_type); | 32 static std::string GetTopLevelId(const syncer::ModelType& model_type); |
| 32 | 33 |
| 33 virtual ~FakeServerEntity(); | 34 static std::unique_ptr<LoopbackServerEntity> CreateEntityFromProto( |
| 34 const std::string& id() const { return id_; } | 35 const sync_pb::LoopbackServerEntity& entity); |
| 35 const std::string& client_defined_unique_tag() const { | 36 |
| 36 return client_defined_unique_tag_; | 37 virtual ~LoopbackServerEntity(); |
| 37 } | 38 const std::string& GetId() const; |
| 38 syncer::ModelType model_type() const { return model_type_; } | 39 syncer::ModelType GetModelType() const; |
| 39 int64_t GetVersion() const; | 40 int64_t GetVersion() const; |
| 40 void SetVersion(int64_t version); | 41 void SetVersion(int64_t version); |
| 41 const std::string& GetName() const; | 42 const std::string& GetName() const; |
| 42 void SetName(const std::string& name); | 43 void SetName(const std::string& name); |
| 43 | 44 |
| 44 // Replaces |specifics_| with |updated_specifics|. This method is meant to be | 45 // Replaces |specifics_| with |updated_specifics|. This method is meant to be |
| 45 // used to mimic a client commit. | 46 // used to mimic a client commit. |
| 46 void SetSpecifics(const sync_pb::EntitySpecifics& updated_specifics); | 47 void SetSpecifics(const sync_pb::EntitySpecifics& updated_specifics); |
| 48 sync_pb::EntitySpecifics GetSpecifics() const; |
| 47 | 49 |
| 48 // Common data items needed by server | 50 // Common data items needed by server |
| 49 virtual bool RequiresParentId() const = 0; | 51 virtual bool RequiresParentId() const = 0; |
| 50 virtual std::string GetParentId() const = 0; | 52 virtual std::string GetParentId() const = 0; |
| 51 virtual void SerializeAsProto(sync_pb::SyncEntity* proto) const = 0; | 53 virtual void SerializeAsProto(sync_pb::SyncEntity* proto) const = 0; |
| 54 virtual sync_pb::LoopbackServerEntity_Type GetLoopbackServerEntityType() |
| 55 const; |
| 52 virtual bool IsDeleted() const; | 56 virtual bool IsDeleted() const; |
| 53 virtual bool IsFolder() const; | 57 virtual bool IsFolder() const; |
| 54 virtual bool IsPermanent() const; | 58 virtual bool IsPermanent() const; |
| 55 | 59 |
| 60 virtual void SerializeAsLoopbackServerEntity( |
| 61 sync_pb::LoopbackServerEntity* entity) const; |
| 62 |
| 56 protected: | 63 protected: |
| 57 // Extracts the ModelType from |id|. If |id| is malformed or does not contain | 64 // Extracts the ModelType from |id|. If |id| is malformed or does not contain |
| 58 // a valid ModelType, UNSPECIFIED is returned. | 65 // a valid ModelType, UNSPECIFIED is returned. |
| 59 static syncer::ModelType GetModelTypeFromId(const std::string& id); | 66 static syncer::ModelType GetModelTypeFromId(const std::string& id); |
| 60 | 67 |
| 61 FakeServerEntity(const std::string& id, | 68 LoopbackServerEntity(const std::string& id, |
| 62 const std::string& client_defined_unique_tag, | 69 const syncer::ModelType& model_type, |
| 63 const syncer::ModelType& model_type, | 70 int64_t version, |
| 64 int64_t version, | 71 const std::string& name); |
| 65 const std::string& name); | |
| 66 | 72 |
| 67 void SerializeBaseProtoFields(sync_pb::SyncEntity* sync_entity) const; | 73 void SerializeBaseProtoFields(sync_pb::SyncEntity* sync_entity) const; |
| 68 | 74 |
| 69 private: | 75 private: |
| 70 // The entity's ID. | 76 // The entity's ID. |
| 71 const std::string id_; | 77 const std::string id_; |
| 72 | 78 |
| 73 // The tag for this entity. Can be empty for bookmarks or permanent entities. | |
| 74 const std::string client_defined_unique_tag_; | |
| 75 | |
| 76 // The ModelType that categorizes this entity. | 79 // The ModelType that categorizes this entity. |
| 77 const syncer::ModelType model_type_; | 80 const syncer::ModelType model_type_; |
| 78 | 81 |
| 79 // The version of this entity. | 82 // The version of this entity. |
| 80 int64_t version_; | 83 int64_t version_; |
| 81 | 84 |
| 82 // The name of the entity. | 85 // The name of the entity. |
| 83 std::string name_; | 86 std::string name_; |
| 84 | 87 |
| 85 // The EntitySpecifics for the entity. | 88 // The EntitySpecifics for the entity. |
| 86 sync_pb::EntitySpecifics specifics_; | 89 sync_pb::EntitySpecifics specifics_; |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 } // namespace fake_server | 92 } // namespace syncer |
| 90 | 93 |
| 91 #endif // COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_ | 94 #endif // COMPONENTS_SYNC_ENGINE_IMPL_LOOPBACK_SERVER_LOOPBACK_SERVER_ENTITY_H_ |
| OLD | NEW |