| 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/fake_server_entity.h" | 5 #include "components/sync/test/fake_server/fake_server_entity.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "components/sync/base/model_type.h" |
| 22 #include "components/sync/protocol/sync.pb.h" |
| 21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 22 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
| 23 #include "sync/internal_api/public/base/model_type.h" | |
| 24 #include "sync/protocol/sync.pb.h" | |
| 25 | 25 |
| 26 using std::string; | 26 using std::string; |
| 27 using std::vector; | 27 using std::vector; |
| 28 | 28 |
| 29 using syncer::ModelType; | 29 using syncer::ModelType; |
| 30 | 30 |
| 31 // The separator used when formatting IDs. | 31 // The separator used when formatting IDs. |
| 32 // | 32 // |
| 33 // We chose the underscore character because it doesn't conflict with the | 33 // We chose the underscore character because it doesn't conflict with the |
| 34 // special characters used by base/base64.h's encoding, which is also used in | 34 // special characters used by base/base64.h's encoding, which is also used in |
| 35 // the construction of some IDs. | 35 // the construction of some IDs. |
| 36 const char kIdSeparator[] = "_"; | 36 const char kIdSeparator[] = "_"; |
| 37 | 37 |
| 38 namespace fake_server { | 38 namespace fake_server { |
| 39 | 39 |
| 40 FakeServerEntity::~FakeServerEntity() { } | 40 FakeServerEntity::~FakeServerEntity() {} |
| 41 | 41 |
| 42 const std::string& FakeServerEntity::GetId() const { | 42 const std::string& FakeServerEntity::GetId() const { |
| 43 return id_; | 43 return id_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 ModelType FakeServerEntity::GetModelType() const { | 46 ModelType FakeServerEntity::GetModelType() const { |
| 47 return model_type_; | 47 return model_type_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 int64_t FakeServerEntity::GetVersion() const { | 50 int64_t FakeServerEntity::GetVersion() const { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool FakeServerEntity::IsPermanent() const { | 79 bool FakeServerEntity::IsPermanent() const { |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // static | 83 // static |
| 84 string FakeServerEntity::CreateId(const ModelType& model_type, | 84 string FakeServerEntity::CreateId(const ModelType& model_type, |
| 85 const string& inner_id) { | 85 const string& inner_id) { |
| 86 int field_number = GetSpecificsFieldNumberFromModelType(model_type); | 86 int field_number = GetSpecificsFieldNumberFromModelType(model_type); |
| 87 return base::StringPrintf("%d%s%s", | 87 return base::StringPrintf("%d%s%s", field_number, kIdSeparator, |
| 88 field_number, | |
| 89 kIdSeparator, | |
| 90 inner_id.c_str()); | 88 inner_id.c_str()); |
| 91 } | 89 } |
| 92 | 90 |
| 93 // static | 91 // static |
| 94 std::string FakeServerEntity::GetTopLevelId(const ModelType& model_type) { | 92 std::string FakeServerEntity::GetTopLevelId(const ModelType& model_type) { |
| 95 return FakeServerEntity::CreateId( | 93 return FakeServerEntity::CreateId(model_type, |
| 96 model_type, | 94 syncer::ModelTypeToRootTag(model_type)); |
| 97 syncer::ModelTypeToRootTag(model_type)); | |
| 98 } | 95 } |
| 99 | 96 |
| 100 // static | 97 // static |
| 101 ModelType FakeServerEntity::GetModelTypeFromId(const string& id) { | 98 ModelType FakeServerEntity::GetModelTypeFromId(const string& id) { |
| 102 vector<base::StringPiece> tokens = base::SplitStringPiece( | 99 vector<base::StringPiece> tokens = base::SplitStringPiece( |
| 103 id, kIdSeparator, base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 100 id, kIdSeparator, base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 104 | 101 |
| 105 int field_number; | 102 int field_number; |
| 106 if (tokens.size() != 2 || !base::StringToInt(tokens[0], &field_number)) { | 103 if (tokens.size() != 2 || !base::StringToInt(tokens[0], &field_number)) { |
| 107 return syncer::UNSPECIFIED; | 104 return syncer::UNSPECIFIED; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 128 | 125 |
| 129 // Data via accessors | 126 // Data via accessors |
| 130 sync_entity->set_deleted(IsDeleted()); | 127 sync_entity->set_deleted(IsDeleted()); |
| 131 sync_entity->set_folder(IsFolder()); | 128 sync_entity->set_folder(IsFolder()); |
| 132 | 129 |
| 133 if (RequiresParentId()) | 130 if (RequiresParentId()) |
| 134 sync_entity->set_parent_id_string(GetParentId()); | 131 sync_entity->set_parent_id_string(GetParentId()); |
| 135 } | 132 } |
| 136 | 133 |
| 137 } // namespace fake_server | 134 } // namespace fake_server |
| OLD | NEW |