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.
5 #include "sync/test/fake_server/fake_server_entity.h"
11 #include "base/basictypes.h"
12 #include "base/guid.h"
13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h"
19 #include "net/base/net_errors.h"
20 #include "net/http/http_status_code.h"
21 #include "sync/internal_api/public/base/model_type.h"
22 #include "sync/protocol/sync.pb.h"
27 using syncer::ModelType
;
29 // The separator used when formatting IDs.
30 const char kIdSeparator
[] = "/";
32 namespace fake_server
{
34 FakeServerEntity::~FakeServerEntity() { }
36 const std::string
& FakeServerEntity::GetId() const {
40 ModelType
FakeServerEntity::GetModelType() const {
44 int64
FakeServerEntity::GetVersion() const {
48 void FakeServerEntity::SetVersion(int64 version
) {
52 const std::string
& FakeServerEntity::GetName() const {
57 string
FakeServerEntity::CreateId(const ModelType
& model_type
,
58 const string
& inner_id
) {
59 int field_number
= GetSpecificsFieldNumberFromModelType(model_type
);
60 return base::StringPrintf("%d%s%s",
67 std::string
FakeServerEntity::GetTopLevelId(const ModelType
& model_type
) {
68 return FakeServerEntity::CreateId(
70 syncer::ModelTypeToRootTag(model_type
));
74 ModelType
FakeServerEntity::GetModelTypeFromId(const string
& id
) {
75 vector
<string
> tokens
;
76 size_t token_count
= Tokenize(id
, kIdSeparator
, &tokens
);
79 if (token_count
!= 2 || !base::StringToInt(tokens
[0], &field_number
)) {
80 return syncer::UNSPECIFIED
;
83 return syncer::GetModelTypeFromSpecificsFieldNumber(field_number
);
86 FakeServerEntity::FakeServerEntity(const string
& id
,
87 const ModelType
& model_type
,
90 : model_type_(model_type
),
95 void FakeServerEntity::SerializeBaseProtoFields(
96 sync_pb::SyncEntity
* sync_entity
) {
97 // FakeServerEntity fields
98 sync_entity
->set_id_string(id_
);
99 sync_entity
->set_version(version_
);
100 sync_entity
->set_name(name_
);
102 // Data via accessors
103 sync_entity
->set_deleted(IsDeleted());
104 sync_entity
->set_folder(IsFolder());
107 } // namespace fake_server