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

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

Issue 2690913005: [Sync] Update EntityData on all codepaths from model type sync bridge (Closed)
Patch Set: Address comments Created 3 years, 10 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/model_impl/processor_entity_tracker.h" 5 #include "components/sync/model_impl/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/engine/non_blocking_sync_common.h" 10 #include "components/sync/engine/non_blocking_sync_common.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 sync_pb::EntityMetadata* metadata) 52 sync_pb::EntityMetadata* metadata)
53 : storage_key_(storage_key), 53 : storage_key_(storage_key),
54 commit_requested_sequence_number_(metadata->acked_sequence_number()) { 54 commit_requested_sequence_number_(metadata->acked_sequence_number()) {
55 DCHECK(metadata->has_client_tag_hash()); 55 DCHECK(metadata->has_client_tag_hash());
56 DCHECK(metadata->has_creation_time()); 56 DCHECK(metadata->has_creation_time());
57 metadata_.Swap(metadata); 57 metadata_.Swap(metadata);
58 } 58 }
59 59
60 ProcessorEntityTracker::~ProcessorEntityTracker() {} 60 ProcessorEntityTracker::~ProcessorEntityTracker() {}
61 61
62 void ProcessorEntityTracker::CacheCommitData(EntityData* data) { 62 void ProcessorEntityTracker::SetCommitData(EntityData* data) {
63 DCHECK(data); 63 DCHECK(data);
64 if (data->client_tag_hash.empty()) { 64 // Update data's fields from metadata.
65 data->client_tag_hash = metadata_.client_tag_hash(); 65 data->client_tag_hash = metadata_.client_tag_hash();
66 } 66 if (!metadata_.server_id().empty())
67 data->id = metadata_.server_id();
68 data->creation_time = ProtoTimeToTime(metadata_.creation_time());
69 data->modification_time = ProtoTimeToTime(metadata_.modification_time());
70 DCHECK(MatchesSpecificsHash(data->specifics));
71
72 commit_data_.reset();
67 CacheCommitData(data->PassToPtr()); 73 CacheCommitData(data->PassToPtr());
68 } 74 }
69 75
70 void ProcessorEntityTracker::CacheCommitData(const EntityDataPtr& data_ptr) { 76 void ProcessorEntityTracker::CacheCommitData(const EntityDataPtr& data_ptr) {
71 DCHECK(RequiresCommitData()); 77 DCHECK(RequiresCommitData());
72 commit_data_ = data_ptr; 78 commit_data_ = data_ptr;
73 DCHECK(HasCommitData()); 79 DCHECK(HasCommitData());
74 } 80 }
75 81
76 bool ProcessorEntityTracker::HasCommitData() const { 82 bool ProcessorEntityTracker::HasCommitData() const {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DCHECK(IsUnsynced()); 144 DCHECK(IsUnsynced());
139 // There was a conflict and the server just won it. Explicitly ack all 145 // There was a conflict and the server just won it. Explicitly ack all
140 // pending commits so they are never enqueued again. 146 // pending commits so they are never enqueued again.
141 metadata_.set_acked_sequence_number(metadata_.sequence_number()); 147 metadata_.set_acked_sequence_number(metadata_.sequence_number());
142 commit_data_.reset(); 148 commit_data_.reset();
143 RecordAcceptedUpdate(update); 149 RecordAcceptedUpdate(update);
144 } 150 }
145 151
146 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) { 152 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) {
147 DCHECK(!metadata_.client_tag_hash().empty()); 153 DCHECK(!metadata_.client_tag_hash().empty());
148 DCHECK_EQ(metadata_.client_tag_hash(), data->client_tag_hash);
149 154
150 if (data->modification_time.is_null()) { 155 // Update metadata fields from updated data.
151 data->modification_time = base::Time::Now(); 156 base::Time modification_time = !data->modification_time.is_null()
152 } 157 ? data->modification_time
158 : base::Time::Now();
153 159
160 // IncrementSequenceNumber should be called before UpdateSpecificHash since
161 // it remembers specifics hash before the modifications.
154 IncrementSequenceNumber(); 162 IncrementSequenceNumber();
155 UpdateSpecificsHash(data->specifics); 163 UpdateSpecificsHash(data->specifics);
156 metadata_.set_modification_time(TimeToProtoTime(data->modification_time)); 164 if (!data->creation_time.is_null())
165 metadata_.set_creation_time(TimeToProtoTime(data->creation_time));
166 metadata_.set_modification_time(TimeToProtoTime(modification_time));
157 metadata_.set_is_deleted(false); 167 metadata_.set_is_deleted(false);
158 168
159 data->id = metadata_.server_id(); 169 // SetCommitData will update data's fileds from metadata and wrap it into
160 data->creation_time = ProtoTimeToTime(metadata_.creation_time()); 170 // immutable EntityDataPtr.
161 commit_data_.reset(); 171 SetCommitData(data.get());
162 CacheCommitData(data.get());
163 } 172 }
164 173
165 void ProcessorEntityTracker::Delete() { 174 void ProcessorEntityTracker::Delete() {
166 IncrementSequenceNumber(); 175 IncrementSequenceNumber();
167 metadata_.set_modification_time(TimeToProtoTime(base::Time::Now())); 176 metadata_.set_modification_time(TimeToProtoTime(base::Time::Now()));
168 metadata_.set_is_deleted(true); 177 metadata_.set_is_deleted(true);
169 metadata_.clear_specifics_hash(); 178 metadata_.clear_specifics_hash();
170 // Clear any cached pending commit data. 179 // Clear any cached pending commit data.
171 commit_data_.reset(); 180 commit_data_.reset();
172 } 181 }
173 182
174 void ProcessorEntityTracker::InitializeCommitRequestData( 183 void ProcessorEntityTracker::InitializeCommitRequestData(
175 CommitRequestData* request) { 184 CommitRequestData* request) {
176 if (!metadata_.is_deleted()) { 185 if (!metadata_.is_deleted()) {
177 DCHECK(HasCommitData()); 186 DCHECK(HasCommitData());
178 DCHECK_EQ(commit_data_->client_tag_hash, metadata_.client_tag_hash()); 187 DCHECK_EQ(commit_data_->client_tag_hash, metadata_.client_tag_hash());
188 DCHECK_EQ(commit_data_->id, metadata_.server_id());
179 request->entity = commit_data_; 189 request->entity = commit_data_;
180 } else { 190 } else {
181 // Make an EntityData with empty specifics to indicate deletion. This is 191 // Make an EntityData with empty specifics to indicate deletion. This is
182 // done lazily here to simplify loading a pending deletion on startup. 192 // done lazily here to simplify loading a pending deletion on startup.
183 EntityData data; 193 EntityData data;
184 data.client_tag_hash = metadata_.client_tag_hash(); 194 data.client_tag_hash = metadata_.client_tag_hash();
185 data.id = metadata_.server_id(); 195 data.id = metadata_.server_id();
186 data.creation_time = ProtoTimeToTime(metadata_.creation_time()); 196 data.creation_time = ProtoTimeToTime(metadata_.creation_time());
187 data.modification_time = ProtoTimeToTime(metadata_.modification_time()); 197 data.modification_time = ProtoTimeToTime(metadata_.modification_time());
188 request->entity = data.PassToPtr(); 198 request->entity = data.PassToPtr();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void ProcessorEntityTracker::UpdateSpecificsHash( 250 void ProcessorEntityTracker::UpdateSpecificsHash(
241 const sync_pb::EntitySpecifics& specifics) { 251 const sync_pb::EntitySpecifics& specifics) {
242 if (specifics.ByteSize() > 0) { 252 if (specifics.ByteSize() > 0) {
243 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); 253 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
244 } else { 254 } else {
245 metadata_.clear_specifics_hash(); 255 metadata_.clear_specifics_hash();
246 } 256 }
247 } 257 }
248 258
249 } // namespace syncer 259 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/model_impl/processor_entity_tracker.h ('k') | components/sync/model_impl/shared_model_type_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698