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 #include "sync/test/fake_server/permanent_entity.h" | 5 #include "sync/test/fake_server/permanent_entity.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "sync/internal_api/public/base/model_type.h" | 11 #include "sync/internal_api/public/base/model_type.h" |
11 #include "sync/protocol/sync.pb.h" | 12 #include "sync/protocol/sync.pb.h" |
12 #include "sync/test/fake_server/fake_server_entity.h" | 13 #include "sync/test/fake_server/fake_server_entity.h" |
13 | 14 |
14 using std::string; | 15 using std::string; |
15 | 16 |
16 using syncer::ModelType; | 17 using syncer::ModelType; |
17 | 18 |
18 // The parent tag for children of the root entity. Entities with this parent are | 19 // The parent tag for children of the root entity. Entities with this parent are |
19 // referred to as top level enities. | 20 // referred to as top level enities. |
20 static const char kRootParentTag[] = "0"; | 21 static const char kRootParentTag[] = "0"; |
21 | 22 |
22 namespace fake_server { | 23 namespace fake_server { |
23 | 24 |
24 PermanentEntity::~PermanentEntity() { } | 25 PermanentEntity::~PermanentEntity() { } |
25 | 26 |
26 // static | 27 // static |
27 scoped_ptr<FakeServerEntity> PermanentEntity::Create( | 28 std::unique_ptr<FakeServerEntity> PermanentEntity::Create( |
28 const ModelType& model_type, | 29 const ModelType& model_type, |
29 const string& server_tag, | 30 const string& server_tag, |
30 const string& name, | 31 const string& name, |
31 const string& parent_server_tag) { | 32 const string& parent_server_tag) { |
32 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " | 33 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " |
33 << "invalid."; | 34 << "invalid."; |
34 CHECK(!server_tag.empty()) << "A PermanentEntity must have a server tag."; | 35 CHECK(!server_tag.empty()) << "A PermanentEntity must have a server tag."; |
35 CHECK(!name.empty()) << "The entity must have a non-empty name."; | 36 CHECK(!name.empty()) << "The entity must have a non-empty name."; |
36 CHECK(!parent_server_tag.empty()) << "A PermanentEntity must have a parent " | 37 CHECK(!parent_server_tag.empty()) << "A PermanentEntity must have a parent " |
37 << "server tag."; | 38 << "server tag."; |
38 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not " | 39 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not " |
39 << "be created with this factory."; | 40 << "be created with this factory."; |
40 | 41 |
41 string id = FakeServerEntity::CreateId(model_type, server_tag); | 42 string id = FakeServerEntity::CreateId(model_type, server_tag); |
42 string parent_id = FakeServerEntity::CreateId(model_type, parent_server_tag); | 43 string parent_id = FakeServerEntity::CreateId(model_type, parent_server_tag); |
43 sync_pb::EntitySpecifics entity_specifics; | 44 sync_pb::EntitySpecifics entity_specifics; |
44 AddDefaultFieldValue(model_type, &entity_specifics); | 45 AddDefaultFieldValue(model_type, &entity_specifics); |
45 return scoped_ptr<FakeServerEntity>(new PermanentEntity( | 46 return std::unique_ptr<FakeServerEntity>(new PermanentEntity( |
46 id, model_type, name, parent_id, server_tag, entity_specifics)); | 47 id, model_type, name, parent_id, server_tag, entity_specifics)); |
47 } | 48 } |
48 | 49 |
49 // static | 50 // static |
50 scoped_ptr<FakeServerEntity> PermanentEntity::CreateTopLevel( | 51 std::unique_ptr<FakeServerEntity> PermanentEntity::CreateTopLevel( |
51 const ModelType& model_type) { | 52 const ModelType& model_type) { |
52 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " | 53 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " |
53 << "invalid."; | 54 << "invalid."; |
54 string server_tag = syncer::ModelTypeToRootTag(model_type); | 55 string server_tag = syncer::ModelTypeToRootTag(model_type); |
55 string name = syncer::ModelTypeToString(model_type); | 56 string name = syncer::ModelTypeToString(model_type); |
56 string id = FakeServerEntity::GetTopLevelId(model_type); | 57 string id = FakeServerEntity::GetTopLevelId(model_type); |
57 sync_pb::EntitySpecifics entity_specifics; | 58 sync_pb::EntitySpecifics entity_specifics; |
58 AddDefaultFieldValue(model_type, &entity_specifics); | 59 AddDefaultFieldValue(model_type, &entity_specifics); |
59 return scoped_ptr<FakeServerEntity>(new PermanentEntity( | 60 return std::unique_ptr<FakeServerEntity>(new PermanentEntity( |
60 id, model_type, name, kRootParentTag, server_tag, entity_specifics)); | 61 id, model_type, name, kRootParentTag, server_tag, entity_specifics)); |
61 } | 62 } |
62 | 63 |
63 // static | 64 // static |
64 scoped_ptr<FakeServerEntity> PermanentEntity::CreateUpdatedNigoriEntity( | 65 std::unique_ptr<FakeServerEntity> PermanentEntity::CreateUpdatedNigoriEntity( |
65 const sync_pb::SyncEntity& client_entity, | 66 const sync_pb::SyncEntity& client_entity, |
66 const FakeServerEntity& current_server_entity) { | 67 const FakeServerEntity& current_server_entity) { |
67 ModelType model_type = current_server_entity.GetModelType(); | 68 ModelType model_type = current_server_entity.GetModelType(); |
68 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI " | 69 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI " |
69 << "entities."; | 70 << "entities."; |
70 | 71 |
71 return make_scoped_ptr<FakeServerEntity>(new PermanentEntity( | 72 return base::WrapUnique<FakeServerEntity>(new PermanentEntity( |
72 current_server_entity.GetId(), model_type, | 73 current_server_entity.GetId(), model_type, |
73 current_server_entity.GetName(), current_server_entity.GetParentId(), | 74 current_server_entity.GetName(), current_server_entity.GetParentId(), |
74 syncer::ModelTypeToRootTag(model_type), client_entity.specifics())); | 75 syncer::ModelTypeToRootTag(model_type), client_entity.specifics())); |
75 } | 76 } |
76 | 77 |
77 PermanentEntity::PermanentEntity(const string& id, | 78 PermanentEntity::PermanentEntity(const string& id, |
78 const ModelType& model_type, | 79 const ModelType& model_type, |
79 const string& name, | 80 const string& name, |
80 const string& parent_id, | 81 const string& parent_id, |
81 const string& server_defined_unique_tag, | 82 const string& server_defined_unique_tag, |
(...skipping 19 matching lines...) Expand all Loading... |
101 | 102 |
102 bool PermanentEntity::IsFolder() const { | 103 bool PermanentEntity::IsFolder() const { |
103 return true; | 104 return true; |
104 } | 105 } |
105 | 106 |
106 bool PermanentEntity::IsPermanent() const { | 107 bool PermanentEntity::IsPermanent() const { |
107 return true; | 108 return true; |
108 } | 109 } |
109 | 110 |
110 } // namespace fake_server | 111 } // namespace fake_server |
OLD | NEW |