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 "components/sync/api/sync_data.h" | 5 #include "components/sync/api/sync_data.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/sync/core/base_node.h" | 13 #include "components/sync/core/base_node.h" |
14 #include "components/sync/protocol/proto_value_conversions.h" | 14 #include "components/sync/protocol/proto_value_conversions.h" |
15 #include "components/sync/protocol/sync.pb.h" | 15 #include "components/sync/protocol/sync.pb.h" |
16 | 16 |
17 namespace syncer { | |
18 namespace { | 17 namespace { |
19 | 18 |
20 sync_pb::AttachmentIdProto IdToProto(const AttachmentId& attachment_id) { | 19 sync_pb::AttachmentIdProto IdToProto( |
| 20 const syncer::AttachmentId& attachment_id) { |
21 return attachment_id.GetProto(); | 21 return attachment_id.GetProto(); |
22 } | 22 } |
23 | 23 |
24 AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) { | 24 syncer::AttachmentId ProtoToId(const sync_pb::AttachmentIdProto& proto) { |
25 return AttachmentId::CreateFromProto(proto); | 25 return syncer::AttachmentId::CreateFromProto(proto); |
26 } | 26 } |
27 | 27 |
28 // Return true iff |attachment_ids| contains duplicates. | 28 // Return true iff |attachment_ids| contains duplicates. |
29 bool ContainsDuplicateAttachments(const AttachmentIdList& attachment_ids) { | 29 bool ContainsDuplicateAttachments( |
30 AttachmentIdSet id_set; | 30 const syncer::AttachmentIdList& attachment_ids) { |
| 31 syncer::AttachmentIdSet id_set; |
31 id_set.insert(attachment_ids.begin(), attachment_ids.end()); | 32 id_set.insert(attachment_ids.begin(), attachment_ids.end()); |
32 return id_set.size() != attachment_ids.size(); | 33 return id_set.size() != attachment_ids.size(); |
33 } | 34 } |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
| 38 namespace syncer { |
| 39 |
37 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper(Wrapper* wrapper) { | 40 void SyncData::ImmutableSyncEntityTraits::InitializeWrapper(Wrapper* wrapper) { |
38 *wrapper = new sync_pb::SyncEntity(); | 41 *wrapper = new sync_pb::SyncEntity(); |
39 } | 42 } |
40 | 43 |
41 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper(Wrapper* wrapper) { | 44 void SyncData::ImmutableSyncEntityTraits::DestroyWrapper(Wrapper* wrapper) { |
42 delete *wrapper; | 45 delete *wrapper; |
43 } | 46 } |
44 | 47 |
45 const sync_pb::SyncEntity& SyncData::ImmutableSyncEntityTraits::Unwrap( | 48 const sync_pb::SyncEntity& SyncData::ImmutableSyncEntityTraits::Unwrap( |
46 const Wrapper& wrapper) { | 49 const Wrapper& wrapper) { |
47 return *wrapper; | 50 return *wrapper; |
48 } | 51 } |
49 | 52 |
50 sync_pb::SyncEntity* SyncData::ImmutableSyncEntityTraits::UnwrapMutable( | 53 sync_pb::SyncEntity* SyncData::ImmutableSyncEntityTraits::UnwrapMutable( |
51 Wrapper* wrapper) { | 54 Wrapper* wrapper) { |
52 return *wrapper; | 55 return *wrapper; |
53 } | 56 } |
54 | 57 |
55 void SyncData::ImmutableSyncEntityTraits::Swap(sync_pb::SyncEntity* t1, | 58 void SyncData::ImmutableSyncEntityTraits::Swap(sync_pb::SyncEntity* t1, |
56 sync_pb::SyncEntity* t2) { | 59 sync_pb::SyncEntity* t2) { |
57 t1->Swap(t2); | 60 t1->Swap(t2); |
58 } | 61 } |
59 | 62 |
60 SyncData::SyncData() : id_(kInvalidId), is_valid_(false) {} | 63 SyncData::SyncData() : id_(kInvalidId), is_valid_(false) {} |
61 | 64 |
62 SyncData::SyncData(int64_t id, | 65 SyncData::SyncData(int64_t id, |
63 sync_pb::SyncEntity* entity, | 66 sync_pb::SyncEntity* entity, |
64 const base::Time& remote_modification_time, | 67 const base::Time& remote_modification_time, |
65 const AttachmentServiceProxy& attachment_service) | 68 const syncer::AttachmentServiceProxy& attachment_service) |
66 : id_(id), | 69 : id_(id), |
67 remote_modification_time_(remote_modification_time), | 70 remote_modification_time_(remote_modification_time), |
68 immutable_entity_(entity), | 71 immutable_entity_(entity), |
69 attachment_service_(attachment_service), | 72 attachment_service_(attachment_service), |
70 is_valid_(true) {} | 73 is_valid_(true) {} |
71 | 74 |
72 SyncData::SyncData(const SyncData& other) = default; | 75 SyncData::SyncData(const SyncData& other) = default; |
73 | 76 |
74 SyncData::~SyncData() {} | 77 SyncData::~SyncData() {} |
75 | 78 |
76 // Static. | 79 // Static. |
77 SyncData SyncData::CreateLocalDelete(const std::string& sync_tag, | 80 SyncData SyncData::CreateLocalDelete(const std::string& sync_tag, |
78 ModelType datatype) { | 81 ModelType datatype) { |
79 sync_pb::EntitySpecifics specifics; | 82 sync_pb::EntitySpecifics specifics; |
80 AddDefaultFieldValue(datatype, &specifics); | 83 AddDefaultFieldValue(datatype, &specifics); |
81 return CreateLocalData(sync_tag, std::string(), specifics); | 84 return CreateLocalData(sync_tag, std::string(), specifics); |
82 } | 85 } |
83 | 86 |
84 // Static. | 87 // Static. |
85 SyncData SyncData::CreateLocalData(const std::string& sync_tag, | 88 SyncData SyncData::CreateLocalData(const std::string& sync_tag, |
86 const std::string& non_unique_title, | 89 const std::string& non_unique_title, |
87 const sync_pb::EntitySpecifics& specifics) { | 90 const sync_pb::EntitySpecifics& specifics) { |
88 AttachmentIdList attachment_ids; | 91 syncer::AttachmentIdList attachment_ids; |
89 return CreateLocalDataWithAttachments(sync_tag, non_unique_title, specifics, | 92 return CreateLocalDataWithAttachments(sync_tag, non_unique_title, specifics, |
90 attachment_ids); | 93 attachment_ids); |
91 } | 94 } |
92 | 95 |
93 // Static. | 96 // Static. |
94 SyncData SyncData::CreateLocalDataWithAttachments( | 97 SyncData SyncData::CreateLocalDataWithAttachments( |
95 const std::string& sync_tag, | 98 const std::string& sync_tag, |
96 const std::string& non_unique_title, | 99 const std::string& non_unique_title, |
97 const sync_pb::EntitySpecifics& specifics, | 100 const sync_pb::EntitySpecifics& specifics, |
98 const AttachmentIdList& attachment_ids) { | 101 const AttachmentIdList& attachment_ids) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 211 } |
209 | 212 |
210 const std::string& SyncDataRemote::GetClientTagHash() const { | 213 const std::string& SyncDataRemote::GetClientTagHash() const { |
211 // It seems that client_defined_unique_tag has a bit of an overloaded use, | 214 // It seems that client_defined_unique_tag has a bit of an overloaded use, |
212 // holding onto the un-hashed tag while local, and then the hashed value when | 215 // holding onto the un-hashed tag while local, and then the hashed value when |
213 // communicating with the server. This usage is copying the latter of these | 216 // communicating with the server. This usage is copying the latter of these |
214 // cases, where this is the hashed tag value. The original tag is not sent to | 217 // cases, where this is the hashed tag value. The original tag is not sent to |
215 // the server so we wouldn't be able to set this value anyways. The only way | 218 // the server so we wouldn't be able to set this value anyways. The only way |
216 // to recreate an un-hashed tag is for the service to do so with a specifics. | 219 // to recreate an un-hashed tag is for the service to do so with a specifics. |
217 // Should only be used by sessions, see crbug.com/604657. | 220 // Should only be used by sessions, see crbug.com/604657. |
218 DCHECK_EQ(SESSIONS, GetDataType()); | 221 DCHECK_EQ(syncer::SESSIONS, GetDataType()); |
219 return immutable_entity_.Get().client_defined_unique_tag(); | 222 return immutable_entity_.Get().client_defined_unique_tag(); |
220 } | 223 } |
221 | 224 |
222 void SyncDataRemote::GetOrDownloadAttachments( | 225 void SyncDataRemote::GetOrDownloadAttachments( |
223 const AttachmentIdList& attachment_ids, | 226 const AttachmentIdList& attachment_ids, |
224 const AttachmentService::GetOrDownloadCallback& callback) { | 227 const AttachmentService::GetOrDownloadCallback& callback) { |
225 attachment_service_.GetOrDownloadAttachments(attachment_ids, callback); | 228 attachment_service_.GetOrDownloadAttachments(attachment_ids, callback); |
226 } | 229 } |
227 | 230 |
228 } // namespace syncer | 231 } // namespace syncer |
OLD | NEW |