| 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/entity_tracker.h" | 5 #include "sync/engine/entity_tracker.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "sync/internal_api/public/base/model_type.h" | 8 #include "sync/internal_api/public/base/model_type.h" |
| 9 #include "sync/internal_api/public/non_blocking_sync_common.h" | 9 #include "sync/internal_api/public/non_blocking_sync_common.h" |
| 10 #include "sync/syncable/syncable_util.h" | 10 #include "sync/syncable/syncable_util.h" |
| 11 #include "sync/util/time.h" | 11 #include "sync/util/time.h" |
| 12 | 12 |
| 13 namespace syncer { | 13 namespace syncer_v2 { |
| 14 | 14 |
| 15 scoped_ptr<EntityTracker> EntityTracker::FromServerUpdate( | 15 scoped_ptr<EntityTracker> EntityTracker::FromServerUpdate( |
| 16 const std::string& id_string, | 16 const std::string& id_string, |
| 17 const std::string& client_tag_hash, | 17 const std::string& client_tag_hash, |
| 18 int64 received_version) { | 18 int64 received_version) { |
| 19 return make_scoped_ptr( | 19 return make_scoped_ptr( |
| 20 new EntityTracker(id_string, client_tag_hash, 0, received_version)); | 20 new EntityTracker(id_string, client_tag_hash, 0, received_version)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 scoped_ptr<EntityTracker> EntityTracker::FromCommitRequest( | 23 scoped_ptr<EntityTracker> EntityTracker::FromCommitRequest( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool EntityTracker::IsCommitPending() const { | 82 bool EntityTracker::IsCommitPending() const { |
| 83 return is_commit_pending_; | 83 return is_commit_pending_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void EntityTracker::PrepareCommitProto(sync_pb::SyncEntity* commit_entity, | 86 void EntityTracker::PrepareCommitProto(sync_pb::SyncEntity* commit_entity, |
| 87 int64* sequence_number) const { | 87 int64* sequence_number) const { |
| 88 // Set ID if we have a server-assigned ID. Otherwise, it will be up to | 88 // Set ID if we have a server-assigned ID. Otherwise, it will be up to |
| 89 // our caller to assign a client-unique initial ID. | 89 // our caller to assign a client-unique initial ID. |
| 90 if (base_version_ != syncer_v2::kUncommittedVersion) { | 90 if (base_version_ != kUncommittedVersion) { |
| 91 commit_entity->set_id_string(id_); | 91 commit_entity->set_id_string(id_); |
| 92 } | 92 } |
| 93 | 93 |
| 94 commit_entity->set_client_defined_unique_tag(client_tag_hash_); | 94 commit_entity->set_client_defined_unique_tag(client_tag_hash_); |
| 95 commit_entity->set_version(base_version_); | 95 commit_entity->set_version(base_version_); |
| 96 commit_entity->set_deleted(deleted_); | 96 commit_entity->set_deleted(deleted_); |
| 97 commit_entity->set_folder(false); | 97 commit_entity->set_folder(false); |
| 98 commit_entity->set_name(non_unique_name_); | 98 commit_entity->set_name(non_unique_name_); |
| 99 if (!deleted_) { | 99 if (!deleted_) { |
| 100 commit_entity->set_ctime(TimeToProtoTime(ctime_)); | 100 commit_entity->set_ctime(syncer::TimeToProtoTime(ctime_)); |
| 101 commit_entity->set_mtime(TimeToProtoTime(mtime_)); | 101 commit_entity->set_mtime(syncer::TimeToProtoTime(mtime_)); |
| 102 commit_entity->mutable_specifics()->CopyFrom(specifics_); | 102 commit_entity->mutable_specifics()->CopyFrom(specifics_); |
| 103 } | 103 } |
| 104 | 104 |
| 105 *sequence_number = sequence_number_; | 105 *sequence_number = sequence_number_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void EntityTracker::RequestCommit(const std::string& id, | 108 void EntityTracker::RequestCommit(const std::string& id, |
| 109 const std::string& client_tag_hash, | 109 const std::string& client_tag_hash, |
| 110 int64 sequence_number, | 110 int64 sequence_number, |
| 111 int64 base_version, | 111 int64 base_version, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // to discard the old pending update, if there was one. | 194 // to discard the old pending update, if there was one. |
| 195 ClearPendingUpdate(); | 195 ClearPendingUpdate(); |
| 196 | 196 |
| 197 if (IsInConflict()) { | 197 if (IsInConflict()) { |
| 198 // Incoming update clobbers the pending commit on the sync thread. | 198 // Incoming update clobbers the pending commit on the sync thread. |
| 199 // The model thread can re-request this commit later if it wants to. | 199 // The model thread can re-request this commit later if it wants to. |
| 200 ClearPendingCommit(); | 200 ClearPendingCommit(); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool EntityTracker::ReceivePendingUpdate( | 204 bool EntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) { |
| 205 const syncer_v2::UpdateResponseData& data) { | |
| 206 if (data.response_version < highest_gu_response_version_) | 205 if (data.response_version < highest_gu_response_version_) |
| 207 return false; | 206 return false; |
| 208 | 207 |
| 209 highest_gu_response_version_ = data.response_version; | 208 highest_gu_response_version_ = data.response_version; |
| 210 pending_update_.reset(new syncer_v2::UpdateResponseData(data)); | 209 pending_update_.reset(new UpdateResponseData(data)); |
| 211 ClearPendingCommit(); | 210 ClearPendingCommit(); |
| 212 return true; | 211 return true; |
| 213 } | 212 } |
| 214 | 213 |
| 215 bool EntityTracker::HasPendingUpdate() const { | 214 bool EntityTracker::HasPendingUpdate() const { |
| 216 return !!pending_update_; | 215 return !!pending_update_; |
| 217 } | 216 } |
| 218 | 217 |
| 219 syncer_v2::UpdateResponseData EntityTracker::GetPendingUpdate() const { | 218 UpdateResponseData EntityTracker::GetPendingUpdate() const { |
| 220 return *pending_update_; | 219 return *pending_update_; |
| 221 } | 220 } |
| 222 | 221 |
| 223 void EntityTracker::ClearPendingUpdate() { | 222 void EntityTracker::ClearPendingUpdate() { |
| 224 pending_update_.reset(); | 223 pending_update_.reset(); |
| 225 } | 224 } |
| 226 | 225 |
| 227 bool EntityTracker::IsInConflict() const { | 226 bool EntityTracker::IsInConflict() const { |
| 228 if (!is_commit_pending_) | 227 if (!is_commit_pending_) |
| 229 return false; | 228 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 241 // commit request? | 240 // commit request? |
| 242 if (base_version_ >= highest_gu_response_version_) { | 241 if (base_version_ >= highest_gu_response_version_) { |
| 243 return false; // Yes. | 242 return false; // Yes. |
| 244 } else { | 243 } else { |
| 245 return true; // No. | 244 return true; // No. |
| 246 } | 245 } |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 | 248 |
| 250 bool EntityTracker::IsServerKnown() const { | 249 bool EntityTracker::IsServerKnown() const { |
| 251 return base_version_ != syncer_v2::kUncommittedVersion; | 250 return base_version_ != kUncommittedVersion; |
| 252 } | 251 } |
| 253 | 252 |
| 254 void EntityTracker::ClearPendingCommit() { | 253 void EntityTracker::ClearPendingCommit() { |
| 255 is_commit_pending_ = false; | 254 is_commit_pending_ = false; |
| 256 | 255 |
| 257 // Clearing the specifics might free up some memory. It can't hurt to try. | 256 // Clearing the specifics might free up some memory. It can't hurt to try. |
| 258 specifics_.Clear(); | 257 specifics_.Clear(); |
| 259 } | 258 } |
| 260 | 259 |
| 261 } // namespace syncer | 260 } // namespace syncer |
| OLD | NEW |