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