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

Side by Side Diff: components/sync/api/sync_data.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
« no previous file with comments | « components/sync/api/sync_data.h ('k') | components/sync/api/sync_data_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/sync/api/sync_data.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <ostream> 10 #include <ostream>
11 11
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" 15 #include "components/sync/base/model_type.h"
16 #include "sync/internal_api/public/base/model_type.h" 16 #include "components/sync/core/attachments/attachment_service_proxy.h"
17 #include "sync/internal_api/public/base_node.h" 17 #include "components/sync/core/base_node.h"
18 #include "sync/protocol/proto_value_conversions.h" 18 #include "components/sync/protocol/proto_value_conversions.h"
19 #include "sync/protocol/sync.pb.h" 19 #include "components/sync/protocol/sync.pb.h"
20 20
21 namespace { 21 namespace {
22 22
23 sync_pb::AttachmentIdProto IdToProto( 23 sync_pb::AttachmentIdProto IdToProto(
24 const syncer::AttachmentId& attachment_id) { 24 const syncer::AttachmentId& attachment_id) {
25 return attachment_id.GetProto(); 25 return attachment_id.GetProto();
26 } 26 }
27 27
28 syncer::AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) { 28 syncer::AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) {
29 return syncer::AttachmentId::CreateFromProto(proto); 29 return syncer::AttachmentId::CreateFromProto(proto);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 sync_pb::EntitySpecifics specifics; 86 sync_pb::EntitySpecifics specifics;
87 AddDefaultFieldValue(datatype, &specifics); 87 AddDefaultFieldValue(datatype, &specifics);
88 return CreateLocalData(sync_tag, std::string(), specifics); 88 return CreateLocalData(sync_tag, std::string(), specifics);
89 } 89 }
90 90
91 // Static. 91 // Static.
92 SyncData SyncData::CreateLocalData(const std::string& sync_tag, 92 SyncData SyncData::CreateLocalData(const std::string& sync_tag,
93 const std::string& non_unique_title, 93 const std::string& non_unique_title,
94 const sync_pb::EntitySpecifics& specifics) { 94 const sync_pb::EntitySpecifics& specifics) {
95 syncer::AttachmentIdList attachment_ids; 95 syncer::AttachmentIdList attachment_ids;
96 return CreateLocalDataWithAttachments( 96 return CreateLocalDataWithAttachments(sync_tag, non_unique_title, specifics,
97 sync_tag, non_unique_title, specifics, attachment_ids); 97 attachment_ids);
98 } 98 }
99 99
100 // Static. 100 // Static.
101 SyncData SyncData::CreateLocalDataWithAttachments( 101 SyncData SyncData::CreateLocalDataWithAttachments(
102 const std::string& sync_tag, 102 const std::string& sync_tag,
103 const std::string& non_unique_title, 103 const std::string& non_unique_title,
104 const sync_pb::EntitySpecifics& specifics, 104 const sync_pb::EntitySpecifics& specifics,
105 const AttachmentIdList& attachment_ids) { 105 const AttachmentIdList& attachment_ids) {
106 DCHECK(!ContainsDuplicateAttachments(attachment_ids)); 106 DCHECK(!ContainsDuplicateAttachments(attachment_ids));
107 sync_pb::SyncEntity entity; 107 sync_pb::SyncEntity entity;
108 entity.set_client_defined_unique_tag(sync_tag); 108 entity.set_client_defined_unique_tag(sync_tag);
109 entity.set_non_unique_name(non_unique_title); 109 entity.set_non_unique_name(non_unique_title);
110 entity.mutable_specifics()->CopyFrom(specifics); 110 entity.mutable_specifics()->CopyFrom(specifics);
111 std::transform(attachment_ids.begin(), 111 std::transform(attachment_ids.begin(), attachment_ids.end(),
112 attachment_ids.end(),
113 RepeatedFieldBackInserter(entity.mutable_attachment_id()), 112 RepeatedFieldBackInserter(entity.mutable_attachment_id()),
114 IdToProto); 113 IdToProto);
115 return SyncData(kInvalidId, 114 return SyncData(kInvalidId, &entity, base::Time(), AttachmentServiceProxy());
116 &entity,
117 base::Time(),
118 AttachmentServiceProxy());
119 } 115 }
120 116
121 // Static. 117 // Static.
122 SyncData SyncData::CreateRemoteData( 118 SyncData SyncData::CreateRemoteData(
123 int64_t id, 119 int64_t id,
124 const sync_pb::EntitySpecifics& specifics, 120 const sync_pb::EntitySpecifics& specifics,
125 const base::Time& modification_time, 121 const base::Time& modification_time,
126 const AttachmentIdList& attachment_ids, 122 const AttachmentIdList& attachment_ids,
127 const AttachmentServiceProxy& attachment_service, 123 const AttachmentServiceProxy& attachment_service,
128 const std::string& client_tag_hash) { 124 const std::string& client_tag_hash) {
129 DCHECK_NE(id, kInvalidId); 125 DCHECK_NE(id, kInvalidId);
130 sync_pb::SyncEntity entity; 126 sync_pb::SyncEntity entity;
131 entity.mutable_specifics()->CopyFrom(specifics); 127 entity.mutable_specifics()->CopyFrom(specifics);
132 entity.set_client_defined_unique_tag(client_tag_hash); 128 entity.set_client_defined_unique_tag(client_tag_hash);
133 std::transform(attachment_ids.begin(), 129 std::transform(attachment_ids.begin(), attachment_ids.end(),
134 attachment_ids.end(),
135 RepeatedFieldBackInserter(entity.mutable_attachment_id()), 130 RepeatedFieldBackInserter(entity.mutable_attachment_id()),
136 IdToProto); 131 IdToProto);
137 return SyncData(id, &entity, modification_time, attachment_service); 132 return SyncData(id, &entity, modification_time, attachment_service);
138 } 133 }
139 134
140 bool SyncData::IsValid() const { return is_valid_; } 135 bool SyncData::IsValid() const {
136 return is_valid_;
137 }
141 138
142 const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { 139 const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const {
143 return immutable_entity_.Get().specifics(); 140 return immutable_entity_.Get().specifics();
144 } 141 }
145 142
146 ModelType SyncData::GetDataType() const { 143 ModelType SyncData::GetDataType() const {
147 return GetModelTypeFromSpecifics(GetSpecifics()); 144 return GetModelTypeFromSpecifics(GetSpecifics());
148 } 145 }
149 146
150 const std::string& SyncData::GetTitle() const { 147 const std::string& SyncData::GetTitle() const {
151 // TODO(zea): set this for data coming from the syncer too. 148 // TODO(zea): set this for data coming from the syncer too.
152 DCHECK(immutable_entity_.Get().has_non_unique_name()); 149 DCHECK(immutable_entity_.Get().has_non_unique_name());
153 return immutable_entity_.Get().non_unique_name(); 150 return immutable_entity_.Get().non_unique_name();
154 } 151 }
155 152
156 bool SyncData::IsLocal() const { return id_ == kInvalidId; } 153 bool SyncData::IsLocal() const {
154 return id_ == kInvalidId;
155 }
157 156
158 std::string SyncData::ToString() const { 157 std::string SyncData::ToString() const {
159 if (!IsValid()) 158 if (!IsValid())
160 return "<Invalid SyncData>"; 159 return "<Invalid SyncData>";
161 160
162 std::string type = ModelTypeToString(GetDataType()); 161 std::string type = ModelTypeToString(GetDataType());
163 std::string specifics; 162 std::string specifics;
164 base::JSONWriter::WriteWithOptions(*EntitySpecificsToValue(GetSpecifics()), 163 base::JSONWriter::WriteWithOptions(*EntitySpecificsToValue(GetSpecifics()),
165 base::JSONWriter::OPTIONS_PRETTY_PRINT, 164 base::JSONWriter::OPTIONS_PRETTY_PRINT,
166 &specifics); 165 &specifics);
(...skipping 11 matching lines...) Expand all
178 ", id: " + id + "}"; 177 ", id: " + id + "}";
179 } 178 }
180 179
181 void PrintTo(const SyncData& sync_data, std::ostream* os) { 180 void PrintTo(const SyncData& sync_data, std::ostream* os) {
182 *os << sync_data.ToString(); 181 *os << sync_data.ToString();
183 } 182 }
184 183
185 AttachmentIdList SyncData::GetAttachmentIds() const { 184 AttachmentIdList SyncData::GetAttachmentIds() const {
186 AttachmentIdList result; 185 AttachmentIdList result;
187 const sync_pb::SyncEntity& entity = immutable_entity_.Get(); 186 const sync_pb::SyncEntity& entity = immutable_entity_.Get();
188 std::transform(entity.attachment_id().begin(), 187 std::transform(entity.attachment_id().begin(), entity.attachment_id().end(),
189 entity.attachment_id().end(), 188 std::back_inserter(result), ProtoToId);
190 std::back_inserter(result),
191 ProtoToId);
192 return result; 189 return result;
193 } 190 }
194 191
195 SyncDataLocal::SyncDataLocal(const SyncData& sync_data) : SyncData(sync_data) { 192 SyncDataLocal::SyncDataLocal(const SyncData& sync_data) : SyncData(sync_data) {
196 DCHECK(sync_data.IsLocal()); 193 DCHECK(sync_data.IsLocal());
197 } 194 }
198 195
199 SyncDataLocal::~SyncDataLocal() {} 196 SyncDataLocal::~SyncDataLocal() {}
200 197
201 const std::string& SyncDataLocal::GetTag() const { 198 const std::string& SyncDataLocal::GetTag() const {
(...skipping 27 matching lines...) Expand all
229 return immutable_entity_.Get().client_defined_unique_tag(); 226 return immutable_entity_.Get().client_defined_unique_tag();
230 } 227 }
231 228
232 void SyncDataRemote::GetOrDownloadAttachments( 229 void SyncDataRemote::GetOrDownloadAttachments(
233 const AttachmentIdList& attachment_ids, 230 const AttachmentIdList& attachment_ids,
234 const AttachmentService::GetOrDownloadCallback& callback) { 231 const AttachmentService::GetOrDownloadCallback& callback) {
235 attachment_service_.GetOrDownloadAttachments(attachment_ids, callback); 232 attachment_service_.GetOrDownloadAttachments(attachment_ids, callback);
236 } 233 }
237 234
238 } // namespace syncer 235 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/api/sync_data.h ('k') | components/sync/api/sync_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698