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

Side by Side Diff: components/sync/engine_impl/worker_entity_tracker.cc

Issue 2562673003: [Sync] WorkerEntityTracker: Ensure that update and commit response have valid id. (Closed)
Patch Set: Created 4 years 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/engine_impl/model_type_worker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/engine_impl/worker_entity_tracker.h" 5 #include "components/sync/engine_impl/worker_entity_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 11 matching lines...) Expand all
22 WorkerEntityTracker::~WorkerEntityTracker() {} 22 WorkerEntityTracker::~WorkerEntityTracker() {}
23 23
24 bool WorkerEntityTracker::HasPendingCommit() const { 24 bool WorkerEntityTracker::HasPendingCommit() const {
25 return !!pending_commit_; 25 return !!pending_commit_;
26 } 26 }
27 27
28 void WorkerEntityTracker::PopulateCommitProto( 28 void WorkerEntityTracker::PopulateCommitProto(
29 sync_pb::SyncEntity* commit_entity) const { 29 sync_pb::SyncEntity* commit_entity) const {
30 DCHECK(HasPendingCommit()); 30 DCHECK(HasPendingCommit());
31 31
32 if (!id_.empty()) {
33 commit_entity->set_id_string(id_);
34 }
35
36 const EntityData& entity = pending_commit_->entity.value(); 32 const EntityData& entity = pending_commit_->entity.value();
37 DCHECK_EQ(client_tag_hash_, entity.client_tag_hash); 33 DCHECK_EQ(client_tag_hash_, entity.client_tag_hash);
38 34
35 commit_entity->set_id_string(id_);
39 commit_entity->set_client_defined_unique_tag(client_tag_hash_); 36 commit_entity->set_client_defined_unique_tag(client_tag_hash_);
40 commit_entity->set_version(base_version_); 37 commit_entity->set_version(base_version_);
41 commit_entity->set_deleted(entity.is_deleted()); 38 commit_entity->set_deleted(entity.is_deleted());
42 39
43 // TODO(stanisc): This doesn't support bookmarks yet. 40 // TODO(stanisc): This doesn't support bookmarks yet.
44 DCHECK(entity.parent_id.empty()); 41 DCHECK(entity.parent_id.empty());
45 commit_entity->set_folder(false); 42 commit_entity->set_folder(false);
46 43
47 commit_entity->set_name(entity.non_unique_name); 44 commit_entity->set_name(entity.non_unique_name);
48 if (!entity.is_deleted()) { 45 if (!entity.is_deleted()) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Otherwise, keep the data associated with this pending commit 101 // Otherwise, keep the data associated with this pending commit
105 // so it can be committed at the next possible opportunity. 102 // so it can be committed at the next possible opportunity.
106 } 103 }
107 104
108 void WorkerEntityTracker::ReceiveCommitResponse(CommitResponseData* ack) { 105 void WorkerEntityTracker::ReceiveCommitResponse(CommitResponseData* ack) {
109 DCHECK_GT(ack->response_version, highest_commit_response_version_) 106 DCHECK_GT(ack->response_version, highest_commit_response_version_)
110 << "Had expected higher response version." 107 << "Had expected higher response version."
111 << " id: " << id_; 108 << " id: " << id_;
112 109
113 // Commit responses, especially after the first commit, can update our ID. 110 // Commit responses, especially after the first commit, can update our ID.
111 DCHECK(!ack->id.empty());
114 id_ = ack->id; 112 id_ = ack->id;
115 highest_commit_response_version_ = ack->response_version; 113 highest_commit_response_version_ = ack->response_version;
116 114
117 // Fill in some cached info for the response data. Since commits happen 115 // Fill in some cached info for the response data. Since commits happen
118 // synchronously on the sync thread, our item's state is guaranteed to be 116 // synchronously on the sync thread, our item's state is guaranteed to be
119 // the same at the end of the commit as it was at the start. 117 // the same at the end of the commit as it was at the start.
120 ack->sequence_number = sequence_number_; 118 ack->sequence_number = sequence_number_;
121 ack->specifics_hash = pending_commit_specifics_hash_; 119 ack->specifics_hash = pending_commit_specifics_hash_;
122 120
123 // Because an in-progress commit blocks the sync thread, we can assume that 121 // Because an in-progress commit blocks the sync thread, we can assume that
124 // the item we just committed successfully is exactly the one we have now. 122 // the item we just committed successfully is exactly the one we have now.
125 // Nothing changed it while the commit was happening. Since we're now in 123 // Nothing changed it while the commit was happening. Since we're now in
126 // sync with the server, we can clear the pending commit. 124 // sync with the server, we can clear the pending commit.
127 ClearPendingCommit(); 125 ClearPendingCommit();
128 } 126 }
129 127
130 void WorkerEntityTracker::ReceiveUpdate(const UpdateResponseData& update) { 128 void WorkerEntityTracker::ReceiveUpdate(const UpdateResponseData& update) {
131 if (!UpdateContainsNewVersion(update)) 129 if (!UpdateContainsNewVersion(update))
132 return; 130 return;
133 131
134 highest_gu_response_version_ = update.response_version; 132 highest_gu_response_version_ = update.response_version;
133 DCHECK(!update.entity->id.empty());
135 id_ = update.entity->id; 134 id_ = update.entity->id;
136 135
137 // Got an applicable update newer than any pending updates. It must be safe 136 // Got an applicable update newer than any pending updates. It must be safe
138 // to discard the old encrypted update, if there was one. 137 // to discard the old encrypted update, if there was one.
139 ClearEncryptedUpdate(); 138 ClearEncryptedUpdate();
140 139
141 if (IsInConflict()) { 140 if (IsInConflict()) {
142 // Incoming update clobbers the pending commit on the sync thread. 141 // Incoming update clobbers the pending commit on the sync thread.
143 // The model thread can re-request this commit later if it wants to. 142 // The model thread can re-request this commit later if it wants to.
144 ClearPendingCommit(); 143 ClearPendingCommit();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 bool WorkerEntityTracker::IsServerKnown() const { 198 bool WorkerEntityTracker::IsServerKnown() const {
200 return base_version_ != kUncommittedVersion; 199 return base_version_ != kUncommittedVersion;
201 } 200 }
202 201
203 void WorkerEntityTracker::ClearPendingCommit() { 202 void WorkerEntityTracker::ClearPendingCommit() {
204 pending_commit_.reset(); 203 pending_commit_.reset();
205 pending_commit_specifics_hash_.clear(); 204 pending_commit_specifics_hash_.clear();
206 } 205 }
207 206
208 } // namespace syncer 207 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine_impl/model_type_worker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698