| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/sync_data.h" | 5 #include "sync/api/sync_data.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 SyncData::SyncData(int64 id, sync_pb::SyncEntity* entity) | 49 SyncData::SyncData(int64 id, sync_pb::SyncEntity* entity) |
| 50 : is_valid_(true), | 50 : is_valid_(true), |
| 51 id_(id), | 51 id_(id), |
| 52 immutable_entity_(entity) {} | 52 immutable_entity_(entity) {} |
| 53 | 53 |
| 54 SyncData::~SyncData() {} | 54 SyncData::~SyncData() {} |
| 55 | 55 |
| 56 // Static. | 56 // Static. |
| 57 SyncData SyncData::CreateLocalDelete( | 57 SyncData SyncData::CreateLocalDelete( |
| 58 const std::string& sync_tag, | 58 const std::string& sync_tag, |
| 59 ModelType datatype) { | 59 ModelType datatype, |
| 60 bool is_folder) { |
| 60 sync_pb::EntitySpecifics specifics; | 61 sync_pb::EntitySpecifics specifics; |
| 61 AddDefaultFieldValue(datatype, &specifics); | 62 AddDefaultFieldValue(datatype, &specifics); |
| 62 return CreateLocalData(sync_tag, "", specifics); | 63 return CreateLocalData(sync_tag, "", specifics, is_folder); |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Static. | 66 // Static. |
| 66 SyncData SyncData::CreateLocalData( | 67 SyncData SyncData::CreateLocalData( |
| 67 const std::string& sync_tag, | 68 const std::string& sync_tag, |
| 68 const std::string& non_unique_title, | 69 const std::string& non_unique_title, |
| 69 const sync_pb::EntitySpecifics& specifics) { | 70 const sync_pb::EntitySpecifics& specifics, |
| 71 bool is_folder) { |
| 70 sync_pb::SyncEntity entity; | 72 sync_pb::SyncEntity entity; |
| 71 entity.set_client_defined_unique_tag(sync_tag); | 73 entity.set_client_defined_unique_tag(sync_tag); |
| 72 entity.set_non_unique_name(non_unique_title); | 74 entity.set_non_unique_name(non_unique_title); |
| 73 entity.mutable_specifics()->CopyFrom(specifics); | 75 entity.mutable_specifics()->CopyFrom(specifics); |
| 76 entity.set_folder(is_folder); |
| 74 return SyncData(kInvalidId, &entity); | 77 return SyncData(kInvalidId, &entity); |
| 75 } | 78 } |
| 76 | 79 |
| 77 // Static. | 80 // Static. |
| 78 SyncData SyncData::CreateRemoteData( | 81 SyncData SyncData::CreateRemoteData( |
| 79 int64 id, const sync_pb::EntitySpecifics& specifics) { | 82 int64 id, const sync_pb::EntitySpecifics& specifics, bool is_folder) { |
| 80 DCHECK_NE(id, kInvalidId); | 83 DCHECK_NE(id, kInvalidId); |
| 81 sync_pb::SyncEntity entity; | 84 sync_pb::SyncEntity entity; |
| 82 entity.mutable_specifics()->CopyFrom(specifics); | 85 entity.mutable_specifics()->CopyFrom(specifics); |
| 86 entity.set_folder(is_folder); |
| 83 return SyncData(id, &entity); | 87 return SyncData(id, &entity); |
| 84 } | 88 } |
| 85 | 89 |
| 86 bool SyncData::IsValid() const { | 90 bool SyncData::IsValid() const { |
| 87 return is_valid_; | 91 return is_valid_; |
| 88 } | 92 } |
| 89 | 93 |
| 90 const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { | 94 const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { |
| 91 return immutable_entity_.Get().specifics(); | 95 return immutable_entity_.Get().specifics(); |
| 92 } | 96 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 | 112 |
| 109 int64 SyncData::GetRemoteId() const { | 113 int64 SyncData::GetRemoteId() const { |
| 110 DCHECK(!IsLocal()); | 114 DCHECK(!IsLocal()); |
| 111 return id_; | 115 return id_; |
| 112 } | 116 } |
| 113 | 117 |
| 114 bool SyncData::IsLocal() const { | 118 bool SyncData::IsLocal() const { |
| 115 return id_ == kInvalidId; | 119 return id_ == kInvalidId; |
| 116 } | 120 } |
| 117 | 121 |
| 122 bool SyncData::IsFolder() const { |
| 123 return immutable_entity_.Get().folder(); |
| 124 } |
| 125 |
| 118 std::string SyncData::ToString() const { | 126 std::string SyncData::ToString() const { |
| 119 if (!IsValid()) | 127 if (!IsValid()) |
| 120 return "<Invalid SyncData>"; | 128 return "<Invalid SyncData>"; |
| 121 | 129 |
| 122 std::string type = ModelTypeToString(GetDataType()); | 130 std::string type = ModelTypeToString(GetDataType()); |
| 123 std::string specifics; | 131 std::string specifics; |
| 124 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(GetSpecifics())); | 132 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(GetSpecifics())); |
| 125 base::JSONWriter::WriteWithOptions(value.get(), | 133 base::JSONWriter::WriteWithOptions(value.get(), |
| 126 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 134 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 127 &specifics); | 135 &specifics); |
| 128 | 136 |
| 129 if (IsLocal()) { | 137 if (IsLocal()) { |
| 130 return "{ isLocal: true, type: " + type + ", tag: " + GetTag() + | 138 return "{ isLocal: true, type: " + type + ", tag: " + GetTag() + |
| 131 ", title: " + GetTitle() + ", specifics: " + specifics + "}"; | 139 ", title: " + GetTitle() + ", specifics: " + specifics + "}"; |
| 132 } | 140 } |
| 133 | 141 |
| 134 std::string id = base::Int64ToString(GetRemoteId()); | 142 std::string id = base::Int64ToString(GetRemoteId()); |
| 135 return "{ isLocal: false, type: " + type + ", specifics: " + specifics + | 143 return "{ isLocal: false, type: " + type + ", specifics: " + specifics + |
| 136 ", id: " + id + "}"; | 144 ", id: " + id + "}"; |
| 137 } | 145 } |
| 138 | 146 |
| 139 void PrintTo(const SyncData& sync_data, std::ostream* os) { | 147 void PrintTo(const SyncData& sync_data, std::ostream* os) { |
| 140 *os << sync_data.ToString(); | 148 *os << sync_data.ToString(); |
| 141 } | 149 } |
| 142 | 150 |
| 143 } // namespace syncer | 151 } // namespace syncer |
| OLD | NEW |