| OLD | NEW |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 ack->specifics_hash = pending_commit_specifics_hash_; | 121 ack->specifics_hash = pending_commit_specifics_hash_; |
| 122 | 122 |
| 123 // Because an in-progress commit blocks the sync thread, we can assume that | 123 // 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. | 124 // 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 | 125 // Nothing changed it while the commit was happening. Since we're now in |
| 126 // sync with the server, we can clear the pending commit. | 126 // sync with the server, we can clear the pending commit. |
| 127 ClearPendingCommit(); | 127 ClearPendingCommit(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void WorkerEntityTracker::ReceiveUpdate(const UpdateResponseData& update) { | 130 void WorkerEntityTracker::ReceiveUpdate(const UpdateResponseData& update) { |
| 131 if (update.response_version <= highest_gu_response_version_) | 131 if (!UpdateContainsNewVersion(update)) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 highest_gu_response_version_ = update.response_version; | 134 highest_gu_response_version_ = update.response_version; |
| 135 id_ = update.entity->id; | 135 id_ = update.entity->id; |
| 136 | 136 |
| 137 // Got an applicable update newer than any pending updates. It must be safe | 137 // Got an applicable update newer than any pending updates. It must be safe |
| 138 // to discard the old encrypted update, if there was one. | 138 // to discard the old encrypted update, if there was one. |
| 139 ClearEncryptedUpdate(); | 139 ClearEncryptedUpdate(); |
| 140 | 140 |
| 141 if (IsInConflict()) { | 141 if (IsInConflict()) { |
| 142 // Incoming update clobbers the pending commit on the sync thread. | 142 // Incoming update clobbers the pending commit on the sync thread. |
| 143 // The model thread can re-request this commit later if it wants to. | 143 // The model thread can re-request this commit later if it wants to. |
| 144 ClearPendingCommit(); | 144 ClearPendingCommit(); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool WorkerEntityTracker::UpdateContainsNewVersion( |
| 149 const UpdateResponseData& update) { |
| 150 return (update.response_version > highest_gu_response_version_); |
| 151 } |
| 152 |
| 148 bool WorkerEntityTracker::ReceiveEncryptedUpdate( | 153 bool WorkerEntityTracker::ReceiveEncryptedUpdate( |
| 149 const UpdateResponseData& data) { | 154 const UpdateResponseData& data) { |
| 150 if (data.response_version < highest_gu_response_version_) | 155 if (data.response_version < highest_gu_response_version_) |
| 151 return false; | 156 return false; |
| 152 | 157 |
| 153 highest_gu_response_version_ = data.response_version; | 158 highest_gu_response_version_ = data.response_version; |
| 154 encrypted_update_ = base::MakeUnique<UpdateResponseData>(data); | 159 encrypted_update_ = base::MakeUnique<UpdateResponseData>(data); |
| 155 ClearPendingCommit(); | 160 ClearPendingCommit(); |
| 156 return true; | 161 return true; |
| 157 } | 162 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 bool WorkerEntityTracker::IsServerKnown() const { | 199 bool WorkerEntityTracker::IsServerKnown() const { |
| 195 return base_version_ != kUncommittedVersion; | 200 return base_version_ != kUncommittedVersion; |
| 196 } | 201 } |
| 197 | 202 |
| 198 void WorkerEntityTracker::ClearPendingCommit() { | 203 void WorkerEntityTracker::ClearPendingCommit() { |
| 199 pending_commit_.reset(); | 204 pending_commit_.reset(); |
| 200 pending_commit_specifics_hash_.clear(); | 205 pending_commit_specifics_hash_.clear(); |
| 201 } | 206 } |
| 202 | 207 |
| 203 } // namespace syncer | 208 } // namespace syncer |
| OLD | NEW |