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

Side by Side Diff: sync/test/fake_server/unique_client_entity.cc

Issue 414953002: Make client tag IDs consistent in sync fake server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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 #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::CreateNew(
pval...(no longer on Chromium) 2014/07/23 23:54:15 CreateNew and CreateUpdatedVersion look pretty sim
rlarocque 2014/07/24 00:18:40 I hadn't noticed that until now. Good point. I'l
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 FakeServerEntity* UniqueClientEntity::CreateUpdatedVersion(
46 const sync_pb::SyncEntity& client_entity, 44 const sync_pb::SyncEntity& client_entity,
47 FakeServerEntity* current_server_entity) { 45 FakeServerEntity* current_server_entity) {
48 return new UniqueClientEntity(client_entity.id_string(), 46 string id = EffectiveIdForClientTaggedEntity(client_entity);
47 return new UniqueClientEntity(id,
49 current_server_entity->GetModelType(), 48 current_server_entity->GetModelType(),
50 client_entity.version(), 49 client_entity.version(),
51 client_entity.name(), 50 client_entity.name(),
52 client_entity.client_defined_unique_tag(), 51 client_entity.client_defined_unique_tag(),
53 client_entity.specifics(), 52 client_entity.specifics(),
54 client_entity.ctime(), 53 client_entity.ctime(),
55 client_entity.mtime()); 54 client_entity.mtime());
56 } 55 }
57 56
57 // static
58 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity(
59 const sync_pb::SyncEntity& entity) {
60 return FakeServerEntity::CreateId(
61 syncer::GetModelTypeFromSpecifics(entity.specifics()),
62 entity.client_defined_unique_tag());
63 }
64
58 UniqueClientEntity::UniqueClientEntity( 65 UniqueClientEntity::UniqueClientEntity(
59 const string& id, 66 const string& id,
60 const ModelType& model_type, 67 const ModelType& model_type,
61 int64 version, 68 int64 version,
62 const string& name, 69 const string& name,
63 const string& client_defined_unique_tag, 70 const string& client_defined_unique_tag,
64 const sync_pb::EntitySpecifics& specifics, 71 const sync_pb::EntitySpecifics& specifics,
65 int64 creation_time, 72 int64 creation_time,
66 int64 last_modified_time) 73 int64 last_modified_time)
67 : FakeServerEntity(id, model_type, version, name), 74 : FakeServerEntity(id, model_type, version, name),
(...skipping 25 matching lines...) Expand all
93 100
94 bool UniqueClientEntity::IsDeleted() const { 101 bool UniqueClientEntity::IsDeleted() const {
95 return false; 102 return false;
96 } 103 }
97 104
98 bool UniqueClientEntity::IsFolder() const { 105 bool UniqueClientEntity::IsFolder() const {
99 return false; 106 return false;
100 } 107 }
101 108
102 } // namespace fake_server 109 } // namespace fake_server
OLDNEW
« sync/test/fake_server/fake_server.cc ('K') | « sync/test/fake_server/unique_client_entity.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698