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

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: 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 if (data->creation_time.is_null())
skym 2017/02/14 00:33:40 What do you think of DCHECK we have both times and
pavely 2017/02/14 02:09:42 I thought that if data doesn't specify mtime then
69 data->creation_time = ProtoTimeToTime(metadata_.creation_time());
70 if (data->modification_time.is_null())
71 data->modification_time = ProtoTimeToTime(metadata_.modification_time());
72 DCHECK(MatchesSpecificsHash(data->specifics));
73
74 commit_data_.reset();
skym 2017/02/14 00:33:40 why do you need this reset?
pavely 2017/02/14 02:09:41 CacheCommitData has a DCHECK that ensures there we
67 CacheCommitData(data->PassToPtr()); 75 CacheCommitData(data->PassToPtr());
68 } 76 }
69 77
70 void ProcessorEntityTracker::CacheCommitData(const EntityDataPtr& data_ptr) { 78 void ProcessorEntityTracker::CacheCommitData(const EntityDataPtr& data_ptr) {
71 DCHECK(RequiresCommitData()); 79 DCHECK(RequiresCommitData());
72 commit_data_ = data_ptr; 80 commit_data_ = data_ptr;
73 DCHECK(HasCommitData()); 81 DCHECK(HasCommitData());
74 } 82 }
75 83
76 bool ProcessorEntityTracker::HasCommitData() const { 84 bool ProcessorEntityTracker::HasCommitData() const {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DCHECK(IsUnsynced()); 146 DCHECK(IsUnsynced());
139 // There was a conflict and the server just won it. Explicitly ack all 147 // There was a conflict and the server just won it. Explicitly ack all
140 // pending commits so they are never enqueued again. 148 // pending commits so they are never enqueued again.
141 metadata_.set_acked_sequence_number(metadata_.sequence_number()); 149 metadata_.set_acked_sequence_number(metadata_.sequence_number());
142 commit_data_.reset(); 150 commit_data_.reset();
143 RecordAcceptedUpdate(update); 151 RecordAcceptedUpdate(update);
144 } 152 }
145 153
146 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) { 154 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) {
147 DCHECK(!metadata_.client_tag_hash().empty()); 155 DCHECK(!metadata_.client_tag_hash().empty());
148 DCHECK_EQ(metadata_.client_tag_hash(), data->client_tag_hash);
149 156
150 if (data->modification_time.is_null()) { 157 // Update metadata fields from updated data.
151 data->modification_time = base::Time::Now(); 158 base::Time modification_time = !data->modification_time.is_null()
152 } 159 ? data->modification_time
160 : base::Time::Now();
153 161
162 // IncrementSequenceNumber should be called before UpdateSpecificHash since
163 // it remembers specifics hash before the modifications.
154 IncrementSequenceNumber(); 164 IncrementSequenceNumber();
155 UpdateSpecificsHash(data->specifics); 165 UpdateSpecificsHash(data->specifics);
156 metadata_.set_modification_time(TimeToProtoTime(data->modification_time)); 166 if (!data->creation_time.is_null())
skym 2017/02/14 00:33:40 The rest of your change code seems to be defensive
pavely 2017/02/14 02:09:41 This code says: If data's timestamps were explicit
167 metadata_.set_creation_time(TimeToProtoTime(data->creation_time));
168 metadata_.set_modification_time(TimeToProtoTime(modification_time));
157 metadata_.set_is_deleted(false); 169 metadata_.set_is_deleted(false);
158 170
159 data->id = metadata_.server_id(); 171 // SetCommitData will update data's fileds from metadata and wrap it into
160 data->creation_time = ProtoTimeToTime(metadata_.creation_time()); 172 // immutable EntityDataPtr.
161 commit_data_.reset(); 173 SetCommitData(data.get());
162 CacheCommitData(data.get());
163 } 174 }
164 175
165 void ProcessorEntityTracker::Delete() { 176 void ProcessorEntityTracker::Delete() {
166 IncrementSequenceNumber(); 177 IncrementSequenceNumber();
167 metadata_.set_modification_time(TimeToProtoTime(base::Time::Now())); 178 metadata_.set_modification_time(TimeToProtoTime(base::Time::Now()));
168 metadata_.set_is_deleted(true); 179 metadata_.set_is_deleted(true);
169 metadata_.clear_specifics_hash(); 180 metadata_.clear_specifics_hash();
170 // Clear any cached pending commit data. 181 // Clear any cached pending commit data.
171 commit_data_.reset(); 182 commit_data_.reset();
172 } 183 }
173 184
174 void ProcessorEntityTracker::InitializeCommitRequestData( 185 void ProcessorEntityTracker::InitializeCommitRequestData(
175 CommitRequestData* request) { 186 CommitRequestData* request) {
176 if (!metadata_.is_deleted()) { 187 if (!metadata_.is_deleted()) {
177 DCHECK(HasCommitData()); 188 DCHECK(HasCommitData());
178 DCHECK_EQ(commit_data_->client_tag_hash, metadata_.client_tag_hash()); 189 DCHECK_EQ(commit_data_->client_tag_hash, metadata_.client_tag_hash());
190 DCHECK_EQ(commit_data_->id, metadata_.server_id());
179 request->entity = commit_data_; 191 request->entity = commit_data_;
180 } else { 192 } else {
181 // Make an EntityData with empty specifics to indicate deletion. This is 193 // Make an EntityData with empty specifics to indicate deletion. This is
182 // done lazily here to simplify loading a pending deletion on startup. 194 // done lazily here to simplify loading a pending deletion on startup.
183 EntityData data; 195 EntityData data;
184 data.client_tag_hash = metadata_.client_tag_hash(); 196 data.client_tag_hash = metadata_.client_tag_hash();
185 data.id = metadata_.server_id(); 197 data.id = metadata_.server_id();
186 data.creation_time = ProtoTimeToTime(metadata_.creation_time()); 198 data.creation_time = ProtoTimeToTime(metadata_.creation_time());
187 data.modification_time = ProtoTimeToTime(metadata_.modification_time()); 199 data.modification_time = ProtoTimeToTime(metadata_.modification_time());
188 request->entity = data.PassToPtr(); 200 request->entity = data.PassToPtr();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 void ProcessorEntityTracker::UpdateSpecificsHash( 252 void ProcessorEntityTracker::UpdateSpecificsHash(
241 const sync_pb::EntitySpecifics& specifics) { 253 const sync_pb::EntitySpecifics& specifics) {
242 if (specifics.ByteSize() > 0) { 254 if (specifics.ByteSize() > 0) {
243 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); 255 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
244 } else { 256 } else {
245 metadata_.clear_specifics_hash(); 257 metadata_.clear_specifics_hash();
246 } 258 }
247 } 259 }
248 260
249 } // namespace syncer 261 } // 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