Index: sync/engine/sync_thread_sync_entity.h |
diff --git a/sync/engine/sync_thread_sync_entity.h b/sync/engine/sync_thread_sync_entity.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bc3d6a212e79e7452c07fc8593148aa42bb25aaf |
--- /dev/null |
+++ b/sync/engine/sync_thread_sync_entity.h |
@@ -0,0 +1,130 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SYNC_ENGINE_SYNC_THREAD_SYNC_ENTITY_H_ |
+#define SYNC_ENGINE_SYNC_THREAD_SYNC_ENTITY_H_ |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/time/time.h" |
+#include "sync/base/sync_export.h" |
+#include "sync/protocol/sync.pb.h" |
+ |
+namespace syncer { |
+ |
+// Manages the pending commit and update state for an entity on the syncthread. |
+// |
+// This object maintains the state associated with a particular sync entity |
+// which are required to make decisions about the entity on the sync thread. |
+// The sync thread's data is ephemeral and always out of date, since the "true" |
+// local state lives on the model thread and the "true" server state lives on |
+// the server. It uses counters and sequence numbers to detect and manage |
+// conflicts between the sources of truth and its cached data. |
+class SYNC_EXPORT SyncThreadSyncEntity { |
+ public: |
+ ~SyncThreadSyncEntity(); |
+ |
+ static SyncThreadSyncEntity* FromServerUpdate( |
+ const std::string& id_string, |
+ const std::string& client_tag_hash, |
+ int64 version); |
+ static SyncThreadSyncEntity* FromCommitRequest( |
+ const std::string& id_string, |
+ const std::string& client_tag_hash, |
+ int64 sequence_number, |
+ int64 base_version, |
+ base::Time ctime, |
+ base::Time mtime, |
+ const std::string& non_unique_name, |
+ bool deleted, |
+ const sync_pb::EntitySpecifics& specifics); |
+ |
+ bool IsCommitPending() const; |
+ |
+ void PrepareCommitProto(sync_pb::SyncEntity* commit_entity, |
+ int64* sequence_number) const; |
+ |
+ void RequestCommit(const std::string& id, |
+ const std::string& client_tag_hash, |
+ int64 sequence_number, |
+ int64 base_version, |
+ base::Time ctime, |
+ base::Time mtime, |
+ const std::string& non_unique_name, |
+ bool deleted, |
+ const sync_pb::EntitySpecifics& specifics); |
+ void ReceiveCommitResponse(int64 version, int64 sequence_number); |
+ |
+ void ReceiveUpdate(int64 version); |
+ |
+ sync_pb::SyncEntity& GetCurrentSpecifics(); |
+ |
+ private: |
+ // Constructor that doesn't bother to initialize any pending commit fields. |
+ SyncThreadSyncEntity(const std::string& id, |
+ const std::string& client_tag_hash, |
+ int64 highest_commit_response_version, |
+ int64 highest_gu_response_version); |
+ |
+ // Constructor that initializes all fields. |
+ SyncThreadSyncEntity(const std::string& id, |
+ const std::string& client_tag_hash, |
+ int64 highest_commit_response_version, |
+ int64 highest_gu_response_version, |
+ bool is_commit_pending, |
+ int64 sequence_number, |
+ int64 base_version, |
+ base::Time ctime, |
+ base::Time mtime, |
+ const std::string& non_unique_name, |
+ bool deleted, |
+ const sync_pb::EntitySpecifics& specifics); |
+ |
+ // Checks if the current state indicates a conflict. |
+ // |
+ // This can be true only while a call to this object is in progress. |
+ // Conflicts are always cleared before the method call ends. |
+ bool IsInConflict() const; |
+ |
+ // Clears flag and optionally clears state associated with a pending commit. |
+ void ClearPendingCommit(); |
+ |
+ // The ID for this entry. May be empty if the entry has never been committed. |
+ std::string id_; |
+ |
+ // The hashed client tag for this entry. |
+ std::string client_tag_hash_; |
+ |
+ // The highest version seen in a commit response for this entry. |
+ int64 highest_commit_response_version_; |
+ |
+ // The highest version seen in a GU response for this entry. |
+ int64 highest_gu_response_version_; |
+ |
+ // Flag that indicates whether or not we're waiting for a chance to commit |
+ // this item. |
+ bool is_commit_pending_; |
+ |
+ // Used to track in-flight commit requests on the model thread. All we need |
+ // to do here is return it back to the model thread when the pending commit |
+ // is completed and confirmed. Not valid if no commit is pending. |
+ int64 sequence_number_; |
+ |
+ // The following fields are valid only when a commit is pending. |
+ // This is where we store the data that is to be sent up to the server |
+ // at the next possible opportunity. |
+ int64 base_version_; |
+ base::Time ctime_; |
+ base::Time mtime_; |
+ std::string non_unique_name_; |
+ bool deleted_; |
+ sync_pb::EntitySpecifics specifics_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SyncThreadSyncEntity); |
+}; |
+ |
+} // namespace syncer |
+ |
+#endif // SYNC_ENGINE_SYNC_THREAD_SYNC_ENTITY_H_ |