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

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

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

Powered by Google App Engine
This is Rietveld 408576698