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/unique_client_entity.h" | 5 #include "sync/test/fake_server/unique_client_entity.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "sync/internal_api/public/base/model_type.h" | 11 #include "sync/internal_api/public/base/model_type.h" |
12 #include "sync/protocol/sync.pb.h" | 12 #include "sync/protocol/sync.pb.h" |
13 #include "sync/test/fake_server/fake_server_entity.h" | 13 #include "sync/test/fake_server/fake_server_entity.h" |
14 #include "sync/test/fake_server/permanent_entity.h" | 14 #include "sync/test/fake_server/permanent_entity.h" |
15 | 15 |
16 using std::string; | 16 using std::string; |
17 | 17 |
18 using syncer::ModelType; | 18 using syncer::ModelType; |
19 | 19 |
20 namespace fake_server { | 20 namespace fake_server { |
21 | 21 |
22 UniqueClientEntity::~UniqueClientEntity() { } | 22 UniqueClientEntity::~UniqueClientEntity() { } |
23 | 23 |
24 // static | 24 // static |
25 FakeServerEntity* UniqueClientEntity::CreateNew( | 25 FakeServerEntity* UniqueClientEntity::Create( |
26 const sync_pb::SyncEntity& client_entity) { | 26 const sync_pb::SyncEntity& client_entity) { |
27 CHECK(client_entity.has_client_defined_unique_tag()) | 27 CHECK(client_entity.has_client_defined_unique_tag()) |
28 << "A UniqueClientEntity must have a client-defined unique tag."; | 28 << "A UniqueClientEntity must have a client-defined unique tag."; |
29 ModelType model_type = | 29 ModelType model_type = |
30 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); | 30 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); |
31 string id = client_entity.version() == 0 ? | 31 string id = EffectiveIdForClientTaggedEntity(client_entity); |
32 FakeServerEntity::CreateId(model_type, base::GenerateGUID()) : | |
33 client_entity.id_string(); | |
34 return new UniqueClientEntity(id, | 32 return new UniqueClientEntity(id, |
35 model_type, | 33 model_type, |
36 client_entity.version(), | 34 client_entity.version(), |
37 client_entity.name(), | 35 client_entity.name(), |
38 client_entity.client_defined_unique_tag(), | 36 client_entity.client_defined_unique_tag(), |
39 client_entity.specifics(), | 37 client_entity.specifics(), |
40 client_entity.ctime(), | 38 client_entity.ctime(), |
41 client_entity.mtime()); | 39 client_entity.mtime()); |
42 } | 40 } |
43 | 41 |
44 // static | 42 // static |
45 FakeServerEntity* UniqueClientEntity::CreateUpdatedVersion( | 43 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( |
46 const sync_pb::SyncEntity& client_entity, | 44 const sync_pb::SyncEntity& entity) { |
47 FakeServerEntity* current_server_entity) { | 45 return FakeServerEntity::CreateId( |
48 return new UniqueClientEntity(client_entity.id_string(), | 46 syncer::GetModelTypeFromSpecifics(entity.specifics()), |
49 current_server_entity->GetModelType(), | 47 entity.client_defined_unique_tag()); |
50 client_entity.version(), | |
51 client_entity.name(), | |
52 client_entity.client_defined_unique_tag(), | |
53 client_entity.specifics(), | |
54 client_entity.ctime(), | |
55 client_entity.mtime()); | |
56 } | 48 } |
57 | 49 |
58 UniqueClientEntity::UniqueClientEntity( | 50 UniqueClientEntity::UniqueClientEntity( |
59 const string& id, | 51 const string& id, |
60 const ModelType& model_type, | 52 const ModelType& model_type, |
61 int64 version, | 53 int64 version, |
62 const string& name, | 54 const string& name, |
63 const string& client_defined_unique_tag, | 55 const string& client_defined_unique_tag, |
64 const sync_pb::EntitySpecifics& specifics, | 56 const sync_pb::EntitySpecifics& specifics, |
65 int64 creation_time, | 57 int64 creation_time, |
(...skipping 27 matching lines...) Expand all Loading... |
93 | 85 |
94 bool UniqueClientEntity::IsDeleted() const { | 86 bool UniqueClientEntity::IsDeleted() const { |
95 return false; | 87 return false; |
96 } | 88 } |
97 | 89 |
98 bool UniqueClientEntity::IsFolder() const { | 90 bool UniqueClientEntity::IsFolder() const { |
99 return false; | 91 return false; |
100 } | 92 } |
101 | 93 |
102 } // namespace fake_server | 94 } // namespace fake_server |
OLD | NEW |