[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / sync / test / fake_server / fake_server_entity.cc
blob602a266c394e60e273ca304aa52a674b1b4470a4
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"
7 #include <limits>
8 #include <string>
9 #include <vector>
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"
24 using std::string;
25 using std::vector;
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 {
37 return id_;
40 ModelType FakeServerEntity::GetModelType() const {
41 return model_type_;
44 int64 FakeServerEntity::GetVersion() const {
45 return version_;
48 void FakeServerEntity::SetVersion(int64 version) {
49 version_ = version;
52 const std::string& FakeServerEntity::GetName() const {
53 return name_;
56 // static
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",
61 field_number,
62 kIdSeparator,
63 inner_id.c_str());
66 // static
67 std::string FakeServerEntity::GetTopLevelId(const ModelType& model_type) {
68 return FakeServerEntity::CreateId(
69 model_type,
70 syncer::ModelTypeToRootTag(model_type));
73 // static
74 ModelType FakeServerEntity::GetModelTypeFromId(const string& id) {
75 vector<string> tokens;
76 size_t token_count = Tokenize(id, kIdSeparator, &tokens);
78 int field_number;
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,
88 int64 version,
89 const string& name)
90 : model_type_(model_type),
91 id_(id),
92 version_(version),
93 name_(name) {}
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