Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: components/sync/engine_impl/loopback_server/loopback_server_entity.h

Issue 2360703002: [Sync] Implements the loopback sync server. (Closed)
Patch Set: Shuffle and rename stuff around. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/sync.pb.h" 14 #include "components/sync/protocol/sync.pb.h"
15 15
16 namespace fake_server { 16 namespace syncer {
17 17
18 // The representation of a Sync entity for the fake server. 18 // The representation of a Sync entity for the loopback server.
19 class FakeServerEntity { 19 class LoopbackServerEntity {
20 public: 20 public:
21 // Creates an ID of the form <type><separator><inner-id> where 21 // Creates an ID of the form <type><separator><inner-id> where
22 // <type> is the EntitySpecifics field number for |model_type|, <separator> 22 // <type> is the EntitySpecifics field number for |model_type|, <separator>
23 // is kIdSeparator, and <inner-id> is |inner_id|. 23 // is kIdSeparator, and <inner-id> is |inner_id|.
24 // 24 //
25 // If |inner_id| is globally unique, then the returned ID will also be 25 // If |inner_id| is globally unique, then the returned ID will also be
26 // globally unique. 26 // globally unique.
27 static std::string CreateId(const syncer::ModelType& model_type, 27 static std::string CreateId(const syncer::ModelType& model_type,
28 const std::string& inner_id); 28 const std::string& inner_id);
29 29
30 // Returns the ID string of the top level node for the specified type. 30 // Returns the ID string of the top level node for the specified type.
31 static std::string GetTopLevelId(const syncer::ModelType& model_type); 31 static std::string GetTopLevelId(const syncer::ModelType& model_type);
32 32
33 virtual ~FakeServerEntity(); 33 virtual ~LoopbackServerEntity();
34 const std::string& id() const { return id_; } 34 const std::string& GetId() const;
35 const std::string& client_defined_unique_tag() const { 35 syncer::ModelType GetModelType() const;
36 return client_defined_unique_tag_;
37 }
38 syncer::ModelType model_type() const { return model_type_; }
39 int64_t GetVersion() const; 36 int64_t GetVersion() const;
40 void SetVersion(int64_t version); 37 void SetVersion(int64_t version);
41 const std::string& GetName() const; 38 const std::string& GetName() const;
42 void SetName(const std::string& name); 39 void SetName(const std::string& name);
43 40
44 // Replaces |specifics_| with |updated_specifics|. This method is meant to be 41 // Replaces |specifics_| with |updated_specifics|. This method is meant to be
45 // used to mimic a client commit. 42 // used to mimic a client commit.
46 void SetSpecifics(const sync_pb::EntitySpecifics& updated_specifics); 43 void SetSpecifics(const sync_pb::EntitySpecifics& updated_specifics);
44 sync_pb::EntitySpecifics GetSpecifics() const;
47 45
48 // Common data items needed by server 46 // Common data items needed by server
49 virtual bool RequiresParentId() const = 0; 47 virtual bool RequiresParentId() const = 0;
50 virtual std::string GetParentId() const = 0; 48 virtual std::string GetParentId() const = 0;
51 virtual void SerializeAsProto(sync_pb::SyncEntity* proto) const = 0; 49 virtual void SerializeAsProto(sync_pb::SyncEntity* proto) const = 0;
52 virtual bool IsDeleted() const; 50 virtual bool IsDeleted() const;
53 virtual bool IsFolder() const; 51 virtual bool IsFolder() const;
54 virtual bool IsPermanent() const; 52 virtual bool IsPermanent() const;
55 53
56 protected: 54 protected:
57 // Extracts the ModelType from |id|. If |id| is malformed or does not contain 55 // Extracts the ModelType from |id|. If |id| is malformed or does not contain
58 // a valid ModelType, UNSPECIFIED is returned. 56 // a valid ModelType, UNSPECIFIED is returned.
59 static syncer::ModelType GetModelTypeFromId(const std::string& id); 57 static syncer::ModelType GetModelTypeFromId(const std::string& id);
60 58
61 FakeServerEntity(const std::string& id, 59 LoopbackServerEntity(const std::string& id,
62 const std::string& client_defined_unique_tag, 60 const syncer::ModelType& model_type,
63 const syncer::ModelType& model_type, 61 int64_t version,
64 int64_t version, 62 const std::string& name);
65 const std::string& name);
66 63
67 void SerializeBaseProtoFields(sync_pb::SyncEntity* sync_entity) const; 64 void SerializeBaseProtoFields(sync_pb::SyncEntity* sync_entity) const;
68 65
69 private: 66 private:
70 // The entity's ID. 67 // The entity's ID.
71 const std::string id_; 68 std::string id_;
pavely 2016/10/06 23:48:45 Why did you remove const? Are you planning to modi
pastarmovj 2016/10/13 14:13:40 Nope. I needed this for manual testing but then I
72
73 // The tag for this entity. Can be empty for bookmarks or permanent entities.
74 const std::string client_defined_unique_tag_;
75 69
76 // The ModelType that categorizes this entity. 70 // The ModelType that categorizes this entity.
77 const syncer::ModelType model_type_; 71 syncer::ModelType model_type_;
78 72
79 // The version of this entity. 73 // The version of this entity.
80 int64_t version_; 74 int64_t version_;
81 75
82 // The name of the entity. 76 // The name of the entity.
83 std::string name_; 77 std::string name_;
84 78
85 // The EntitySpecifics for the entity. 79 // The EntitySpecifics for the entity.
86 sync_pb::EntitySpecifics specifics_; 80 sync_pb::EntitySpecifics specifics_;
87 }; 81 };
88 82
89 } // namespace fake_server 83 } // namespace syncer
90 84
91 #endif // COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_ENTITY_H_ 85 #endif // COMPONENTS_SYNC_ENGINE_IMPL_LOOPBACK_SERVER_LOOPBACK_SERVER_ENTITY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698