Chromium Code Reviews| 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 "components/sync/base/model_type.h" | 10 #include "components/sync/base/model_type.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 ack->specifics_hash = pending_commit_specifics_hash_; | 120 ack->specifics_hash = pending_commit_specifics_hash_; |
| 121 | 121 |
| 122 // Because an in-progress commit blocks the sync thread, we can assume that | 122 // Because an in-progress commit blocks the sync thread, we can assume that |
| 123 // the item we just committed successfully is exactly the one we have now. | 123 // the item we just committed successfully is exactly the one we have now. |
| 124 // Nothing changed it while the commit was happening. Since we're now in | 124 // Nothing changed it while the commit was happening. Since we're now in |
| 125 // sync with the server, we can clear the pending commit. | 125 // sync with the server, we can clear the pending commit. |
| 126 ClearPendingCommit(); | 126 ClearPendingCommit(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void WorkerEntityTracker::ReceiveUpdate(const UpdateResponseData& update) { | 129 void WorkerEntityTracker::ReceiveUpdate(const UpdateResponseData& update) { |
| 130 if (update.response_version <= highest_gu_response_version_) | 130 if (!UpdateContainsNewVersion(update)) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 highest_gu_response_version_ = update.response_version; | 133 highest_gu_response_version_ = update.response_version; |
| 134 id_ = update.entity->id; | 134 id_ = update.entity->id; |
| 135 | 135 |
| 136 // 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 |
| 137 // to discard the old encrypted update, if there was one. | 137 // to discard the old encrypted update, if there was one. |
| 138 ClearEncryptedUpdate(); | 138 ClearEncryptedUpdate(); |
| 139 | 139 |
| 140 if (IsInConflict()) { | 140 if (IsInConflict()) { |
| 141 // Incoming update clobbers the pending commit on the sync thread. | 141 // Incoming update clobbers the pending commit on the sync thread. |
| 142 // 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. |
| 143 ClearPendingCommit(); | 143 ClearPendingCommit(); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool WorkerEntityTracker::UpdateContainsNewVersion( | |
| 148 const UpdateResponseData& update) { | |
| 149 if (update.response_version <= highest_gu_response_version_) | |
|
pavely
2016/10/19 18:18:59
It is easier to read if condition follows name/sem
Gang Wu
2016/10/20 21:35:36
Done.
| |
| 150 return false; | |
| 151 return true; | |
| 152 } | |
| 153 | |
| 147 bool WorkerEntityTracker::ReceiveEncryptedUpdate( | 154 bool WorkerEntityTracker::ReceiveEncryptedUpdate( |
| 148 const UpdateResponseData& data) { | 155 const UpdateResponseData& data) { |
| 149 if (data.response_version < highest_gu_response_version_) | 156 if (data.response_version < highest_gu_response_version_) |
| 150 return false; | 157 return false; |
| 151 | 158 |
| 152 highest_gu_response_version_ = data.response_version; | 159 highest_gu_response_version_ = data.response_version; |
| 153 encrypted_update_.reset(new UpdateResponseData(data)); | 160 encrypted_update_.reset(new UpdateResponseData(data)); |
| 154 ClearPendingCommit(); | 161 ClearPendingCommit(); |
| 155 return true; | 162 return true; |
| 156 } | 163 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 bool WorkerEntityTracker::IsServerKnown() const { | 200 bool WorkerEntityTracker::IsServerKnown() const { |
| 194 return base_version_ != kUncommittedVersion; | 201 return base_version_ != kUncommittedVersion; |
| 195 } | 202 } |
| 196 | 203 |
| 197 void WorkerEntityTracker::ClearPendingCommit() { | 204 void WorkerEntityTracker::ClearPendingCommit() { |
| 198 pending_commit_.reset(); | 205 pending_commit_.reset(); |
| 199 pending_commit_specifics_hash_.clear(); | 206 pending_commit_specifics_hash_.clear(); |
| 200 } | 207 } |
| 201 | 208 |
| 202 } // namespace syncer | 209 } // namespace syncer |
| OLD | NEW |