Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / sync / test / fake_server / fake_server_entity.h
bloba1316d189ec8cb70162fa91f8dda7d79125e5c11
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.
5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/protocol/sync.pb.h"
15 namespace fake_server {
17 // The representation of a Sync entity for the fake server.
18 class FakeServerEntity {
19 public:
20 // Creates an ID of the form <type><separator><inner-id> where
21 // <type> is the EntitySpecifics field number for |model_type|, <separator>
22 // is kIdSeparator, and <inner-id> is |inner_id|.
24 // If |inner_id| is globally unique, then the returned ID will also be
25 // globally unique.
26 static std::string CreateId(const syncer::ModelType& model_type,
27 const std::string& inner_id);
29 // Returns the ID string of the top level node for the specified type.
30 static std::string GetTopLevelId(const syncer::ModelType& model_type);
32 virtual ~FakeServerEntity();
33 const std::string& GetId() const;
34 syncer::ModelType GetModelType() const;
35 int64 GetVersion() const;
36 void SetVersion(int64 version);
37 const std::string& GetName() const;
38 void SetName(const std::string& name);
40 // Replaces |specifics_| with |updated_specifics|. This method is meant to be
41 // used to mimic a client commit.
42 void SetSpecifics(const sync_pb::EntitySpecifics& updated_specifics);
44 // Common data items needed by server
45 virtual std::string GetParentId() const = 0;
46 virtual void SerializeAsProto(sync_pb::SyncEntity* proto) const = 0;
47 virtual bool IsDeleted() const;
48 virtual bool IsFolder() const;
49 virtual bool IsPermanent() const;
51 protected:
52 // Extracts the ModelType from |id|. If |id| is malformed or does not contain
53 // a valid ModelType, UNSPECIFIED is returned.
54 static syncer::ModelType GetModelTypeFromId(const std::string& id);
56 FakeServerEntity(const std::string& id,
57 const syncer::ModelType& model_type,
58 int64 version,
59 const std::string& name);
61 void SerializeBaseProtoFields(sync_pb::SyncEntity* sync_entity) const;
63 private:
64 // The entity's ID.
65 std::string id_;
67 // The ModelType that categorizes this entity.
68 syncer::ModelType model_type_;
70 // The version of this entity.
71 int64 version_;
73 // The name of the entity.
74 std::string name_;
76 // The EntitySpecifics for the entity.
77 sync_pb::EntitySpecifics specifics_;
80 } // namespace fake_server
82 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_