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

Side by Side Diff: components/sync/core/processor_entity_tracker.cc

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/core/processor_entity_tracker.h" 5 #include "components/sync/core/processor_entity_tracker.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/sha1.h" 8 #include "base/sha1.h"
9 #include "components/sync/base/time.h" 9 #include "components/sync/base/time.h"
10 #include "components/sync/core/non_blocking_sync_common.h" 10 #include "components/sync/core/non_blocking_sync_common.h"
11 #include "components/sync/syncable/syncable_util.h" 11 #include "components/sync/syncable/syncable_util.h"
12 12
13 namespace syncer { 13 namespace syncer_v2 {
14 14
15 namespace { 15 namespace {
16 16
17 void HashSpecifics(const sync_pb::EntitySpecifics& specifics, 17 void HashSpecifics(const sync_pb::EntitySpecifics& specifics,
18 std::string* hash) { 18 std::string* hash) {
19 DCHECK_GT(specifics.ByteSize(), 0); 19 DCHECK_GT(specifics.ByteSize(), 0);
20 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash); 20 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash);
21 } 21 }
22 22
23 } // namespace 23 } // namespace
24 24
25 std::unique_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew( 25 std::unique_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew(
26 const std::string& storage_key, 26 const std::string& storage_key,
27 const std::string& client_tag_hash, 27 const std::string& client_tag_hash,
28 const std::string& id, 28 const std::string& id,
29 base::Time creation_time) { 29 base::Time creation_time) {
30 // Initialize metadata 30 // Initialize metadata
31 sync_pb::EntityMetadata metadata; 31 sync_pb::EntityMetadata metadata;
32 metadata.set_client_tag_hash(client_tag_hash); 32 metadata.set_client_tag_hash(client_tag_hash);
33 if (!id.empty()) 33 if (!id.empty())
34 metadata.set_server_id(id); 34 metadata.set_server_id(id);
35 metadata.set_sequence_number(0); 35 metadata.set_sequence_number(0);
36 metadata.set_acked_sequence_number(0); 36 metadata.set_acked_sequence_number(0);
37 metadata.set_server_version(kUncommittedVersion); 37 metadata.set_server_version(kUncommittedVersion);
38 metadata.set_creation_time(TimeToProtoTime(creation_time)); 38 metadata.set_creation_time(syncer::TimeToProtoTime(creation_time));
39 39
40 return std::unique_ptr<ProcessorEntityTracker>( 40 return std::unique_ptr<ProcessorEntityTracker>(
41 new ProcessorEntityTracker(storage_key, &metadata)); 41 new ProcessorEntityTracker(storage_key, &metadata));
42 } 42 }
43 43
44 std::unique_ptr<ProcessorEntityTracker> 44 std::unique_ptr<ProcessorEntityTracker>
45 ProcessorEntityTracker::CreateFromMetadata(const std::string& storage_key, 45 ProcessorEntityTracker::CreateFromMetadata(const std::string& storage_key,
46 sync_pb::EntityMetadata* metadata) { 46 sync_pb::EntityMetadata* metadata) {
47 return std::unique_ptr<ProcessorEntityTracker>( 47 return std::unique_ptr<ProcessorEntityTracker>(
48 new ProcessorEntityTracker(storage_key, metadata)); 48 new ProcessorEntityTracker(storage_key, metadata));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // commit and this should follow, or the pending commit needs to be requeued. 123 // commit and this should follow, or the pending commit needs to be requeued.
124 commit_requested_sequence_number_ = metadata_.acked_sequence_number(); 124 commit_requested_sequence_number_ = metadata_.acked_sequence_number();
125 } 125 }
126 126
127 void ProcessorEntityTracker::RecordAcceptedUpdate( 127 void ProcessorEntityTracker::RecordAcceptedUpdate(
128 const UpdateResponseData& update) { 128 const UpdateResponseData& update) {
129 DCHECK(!IsUnsynced()); 129 DCHECK(!IsUnsynced());
130 RecordIgnoredUpdate(update); 130 RecordIgnoredUpdate(update);
131 metadata_.set_is_deleted(update.entity->is_deleted()); 131 metadata_.set_is_deleted(update.entity->is_deleted());
132 metadata_.set_modification_time( 132 metadata_.set_modification_time(
133 TimeToProtoTime(update.entity->modification_time)); 133 syncer::TimeToProtoTime(update.entity->modification_time));
134 UpdateSpecificsHash(update.entity->specifics); 134 UpdateSpecificsHash(update.entity->specifics);
135 } 135 }
136 136
137 void ProcessorEntityTracker::RecordForcedUpdate( 137 void ProcessorEntityTracker::RecordForcedUpdate(
138 const UpdateResponseData& update) { 138 const UpdateResponseData& update) {
139 DCHECK(IsUnsynced()); 139 DCHECK(IsUnsynced());
140 // There was a conflict and the server just won it. Explicitly ack all 140 // There was a conflict and the server just won it. Explicitly ack all
141 // pending commits so they are never enqueued again. 141 // pending commits so they are never enqueued again.
142 metadata_.set_acked_sequence_number(metadata_.sequence_number()); 142 metadata_.set_acked_sequence_number(metadata_.sequence_number());
143 commit_data_.reset(); 143 commit_data_.reset();
144 RecordAcceptedUpdate(update); 144 RecordAcceptedUpdate(update);
145 } 145 }
146 146
147 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) { 147 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) {
148 DCHECK(!metadata_.client_tag_hash().empty()); 148 DCHECK(!metadata_.client_tag_hash().empty());
149 DCHECK_EQ(metadata_.client_tag_hash(), data->client_tag_hash); 149 DCHECK_EQ(metadata_.client_tag_hash(), data->client_tag_hash);
150 150
151 if (data->modification_time.is_null()) { 151 if (data->modification_time.is_null()) {
152 data->modification_time = base::Time::Now(); 152 data->modification_time = base::Time::Now();
153 } 153 }
154 154
155 IncrementSequenceNumber(); 155 IncrementSequenceNumber();
156 UpdateSpecificsHash(data->specifics); 156 UpdateSpecificsHash(data->specifics);
157 metadata_.set_modification_time(TimeToProtoTime(data->modification_time)); 157 metadata_.set_modification_time(
158 syncer::TimeToProtoTime(data->modification_time));
158 metadata_.set_is_deleted(false); 159 metadata_.set_is_deleted(false);
159 160
160 data->id = metadata_.server_id(); 161 data->id = metadata_.server_id();
161 data->creation_time = ProtoTimeToTime(metadata_.creation_time()); 162 data->creation_time = syncer::ProtoTimeToTime(metadata_.creation_time());
162 commit_data_.reset(); 163 commit_data_.reset();
163 CacheCommitData(data.get()); 164 CacheCommitData(data.get());
164 } 165 }
165 166
166 void ProcessorEntityTracker::Delete() { 167 void ProcessorEntityTracker::Delete() {
167 IncrementSequenceNumber(); 168 IncrementSequenceNumber();
168 metadata_.set_modification_time(TimeToProtoTime(base::Time::Now())); 169 metadata_.set_modification_time(syncer::TimeToProtoTime(base::Time::Now()));
169 metadata_.set_is_deleted(true); 170 metadata_.set_is_deleted(true);
170 metadata_.clear_specifics_hash(); 171 metadata_.clear_specifics_hash();
171 // Clear any cached pending commit data. 172 // Clear any cached pending commit data.
172 commit_data_.reset(); 173 commit_data_.reset();
173 } 174 }
174 175
175 void ProcessorEntityTracker::InitializeCommitRequestData( 176 void ProcessorEntityTracker::InitializeCommitRequestData(
176 CommitRequestData* request) { 177 CommitRequestData* request) {
177 if (!metadata_.is_deleted()) { 178 if (!metadata_.is_deleted()) {
178 DCHECK(HasCommitData()); 179 DCHECK(HasCommitData());
179 DCHECK_EQ(commit_data_->client_tag_hash, metadata_.client_tag_hash()); 180 DCHECK_EQ(commit_data_->client_tag_hash, metadata_.client_tag_hash());
180 request->entity = commit_data_; 181 request->entity = commit_data_;
181 } else { 182 } else {
182 // Make an EntityData with empty specifics to indicate deletion. This is 183 // Make an EntityData with empty specifics to indicate deletion. This is
183 // done lazily here to simplify loading a pending deletion on startup. 184 // done lazily here to simplify loading a pending deletion on startup.
184 EntityData data; 185 EntityData data;
185 data.client_tag_hash = metadata_.client_tag_hash(); 186 data.client_tag_hash = metadata_.client_tag_hash();
186 data.id = metadata_.server_id(); 187 data.id = metadata_.server_id();
187 data.creation_time = ProtoTimeToTime(metadata_.creation_time()); 188 data.creation_time = syncer::ProtoTimeToTime(metadata_.creation_time());
188 data.modification_time = ProtoTimeToTime(metadata_.modification_time()); 189 data.modification_time =
190 syncer::ProtoTimeToTime(metadata_.modification_time());
189 request->entity = data.PassToPtr(); 191 request->entity = data.PassToPtr();
190 } 192 }
191 193
192 request->sequence_number = metadata_.sequence_number(); 194 request->sequence_number = metadata_.sequence_number();
193 request->base_version = metadata_.server_version(); 195 request->base_version = metadata_.server_version();
194 request->specifics_hash = metadata_.specifics_hash(); 196 request->specifics_hash = metadata_.specifics_hash();
195 commit_requested_sequence_number_ = metadata_.sequence_number(); 197 commit_requested_sequence_number_ = metadata_.sequence_number();
196 } 198 }
197 199
198 void ProcessorEntityTracker::ReceiveCommitResponse( 200 void ProcessorEntityTracker::ReceiveCommitResponse(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 242
241 void ProcessorEntityTracker::UpdateSpecificsHash( 243 void ProcessorEntityTracker::UpdateSpecificsHash(
242 const sync_pb::EntitySpecifics& specifics) { 244 const sync_pb::EntitySpecifics& specifics) {
243 if (specifics.ByteSize() > 0) { 245 if (specifics.ByteSize() > 0) {
244 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); 246 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
245 } else { 247 } else {
246 metadata_.clear_specifics_hash(); 248 metadata_.clear_specifics_hash();
247 } 249 }
248 } 250 }
249 251
250 } // namespace syncer 252 } // namespace syncer_v2
OLDNEW
« no previous file with comments | « components/sync/core/processor_entity_tracker.h ('k') | components/sync/core/processor_entity_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698