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

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

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