| 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 "sync/engine/worker_entity_tracker.h" | 5 #include "sync/engine/worker_entity_tracker.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "sync/internal_api/public/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 ClearPendingCommit(); | 129 ClearPendingCommit(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void WorkerEntityTracker::ReceiveUpdate(int64_t version) { | 132 void WorkerEntityTracker::ReceiveUpdate(int64_t version) { |
| 133 if (version <= highest_gu_response_version_) | 133 if (version <= highest_gu_response_version_) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 highest_gu_response_version_ = version; | 136 highest_gu_response_version_ = version; |
| 137 | 137 |
| 138 // Got an applicable update newer than any pending updates. It must be safe | 138 // Got an applicable update newer than any pending updates. It must be safe |
| 139 // to discard the old pending update, if there was one. | 139 // to discard the old encrypted update, if there was one. |
| 140 ClearPendingUpdate(); | 140 ClearEncryptedUpdate(); |
| 141 | 141 |
| 142 if (IsInConflict()) { | 142 if (IsInConflict()) { |
| 143 // Incoming update clobbers the pending commit on the sync thread. | 143 // Incoming update clobbers the pending commit on the sync thread. |
| 144 // The model thread can re-request this commit later if it wants to. | 144 // The model thread can re-request this commit later if it wants to. |
| 145 ClearPendingCommit(); | 145 ClearPendingCommit(); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool WorkerEntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) { | 149 bool WorkerEntityTracker::ReceiveEncryptedUpdate( |
| 150 const UpdateResponseData& data) { |
| 150 if (data.response_version < highest_gu_response_version_) | 151 if (data.response_version < highest_gu_response_version_) |
| 151 return false; | 152 return false; |
| 152 | 153 |
| 153 highest_gu_response_version_ = data.response_version; | 154 highest_gu_response_version_ = data.response_version; |
| 154 pending_update_.reset(new UpdateResponseData(data)); | 155 encrypted_update_.reset(new UpdateResponseData(data)); |
| 155 ClearPendingCommit(); | 156 ClearPendingCommit(); |
| 156 return true; | 157 return true; |
| 157 } | 158 } |
| 158 | 159 |
| 159 bool WorkerEntityTracker::HasPendingUpdate() const { | 160 bool WorkerEntityTracker::HasEncryptedUpdate() const { |
| 160 return !!pending_update_; | 161 return !!encrypted_update_; |
| 161 } | 162 } |
| 162 | 163 |
| 163 UpdateResponseData WorkerEntityTracker::GetPendingUpdate() const { | 164 UpdateResponseData WorkerEntityTracker::GetEncryptedUpdate() const { |
| 164 return *pending_update_; | 165 return *encrypted_update_; |
| 165 } | 166 } |
| 166 | 167 |
| 167 void WorkerEntityTracker::ClearPendingUpdate() { | 168 void WorkerEntityTracker::ClearEncryptedUpdate() { |
| 168 pending_update_.reset(); | 169 encrypted_update_.reset(); |
| 169 } | 170 } |
| 170 | 171 |
| 171 bool WorkerEntityTracker::IsInConflict() const { | 172 bool WorkerEntityTracker::IsInConflict() const { |
| 172 if (!HasPendingCommit()) | 173 if (!HasPendingCommit()) |
| 173 return false; | 174 return false; |
| 174 | 175 |
| 175 if (HasPendingUpdate()) | 176 if (HasEncryptedUpdate()) |
| 176 return true; | 177 return true; |
| 177 | 178 |
| 178 if (highest_gu_response_version_ <= highest_commit_response_version_) { | 179 if (highest_gu_response_version_ <= highest_commit_response_version_) { |
| 179 // The most recent server state was created in a commit made by this | 180 // The most recent server state was created in a commit made by this |
| 180 // client. We're fully up to date, and therefore not in conflict. | 181 // client. We're fully up to date, and therefore not in conflict. |
| 181 return false; | 182 return false; |
| 182 } else { | 183 } else { |
| 183 // The most recent server state was written by someone else. | 184 // The most recent server state was written by someone else. |
| 184 // Did the model thread have the most up to date version when it issued the | 185 // Did the model thread have the most up to date version when it issued the |
| 185 // commit request? | 186 // commit request? |
| 186 if (base_version_ >= highest_gu_response_version_) { | 187 if (base_version_ >= highest_gu_response_version_) { |
| 187 return false; // Yes. | 188 return false; // Yes. |
| 188 } else { | 189 } else { |
| 189 return true; // No. | 190 return true; // No. |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 bool WorkerEntityTracker::IsServerKnown() const { | 195 bool WorkerEntityTracker::IsServerKnown() const { |
| 195 return base_version_ != kUncommittedVersion; | 196 return base_version_ != kUncommittedVersion; |
| 196 } | 197 } |
| 197 | 198 |
| 198 void WorkerEntityTracker::ClearPendingCommit() { | 199 void WorkerEntityTracker::ClearPendingCommit() { |
| 199 pending_commit_.reset(); | 200 pending_commit_.reset(); |
| 200 } | 201 } |
| 201 | 202 |
| 202 } // namespace syncer_v2 | 203 } // namespace syncer_v2 |
| OLD | NEW |