Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / sync / test / fake_server / fake_server_entity.h
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 SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/protocol/sync.pb.h"
14
15 namespace fake_server {
16
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|.
23   //
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);
28
29   virtual ~FakeServerEntity();
30   const std::string& GetId() const;
31   syncer::ModelType GetModelType() const;
32   int64 GetVersion() const;
33   void SetVersion(int64 version);
34   const std::string& GetName() const;
35
36   // Common data items needed by server
37   virtual std::string GetParentId() const = 0;
38   virtual sync_pb::SyncEntity* SerializeAsProto() = 0;
39   virtual bool IsDeleted() const = 0;
40   virtual bool IsFolder() const = 0;
41
42  protected:
43   // Extracts the ModelType from |id|. If |id| is malformed or does not contain
44   // a valid ModelType, UNSPECIFIED is returned.
45   static syncer::ModelType GetModelTypeFromId(const std::string& id);
46
47   FakeServerEntity(const std::string& id,
48                    const syncer::ModelType& model_type,
49                    int64 version,
50                    const std::string& name);
51
52   void SerializeBaseProtoFields(sync_pb::SyncEntity* sync_entity);
53
54  private:
55   // The entity's ID.
56   std::string id_;
57
58   // The ModelType that categorizes this entity.
59   syncer::ModelType model_type_;
60
61   // The version of this entity.
62   int64 version_;
63
64   // The name of the entity.
65   std::string name_;
66 };
67
68 }  // namespace fake_server
69
70 #endif  // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_