| 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 #ifndef SYNC_ENGINE_MODEL_THREAD_SYNC_ENTITY_H_ | 5 #ifndef SYNC_ENGINE_MODEL_TYPE_ENTITY_H_ |
| 6 #define SYNC_ENGINE_MODEL_THREAD_SYNC_ENTITY_H_ | 6 #define SYNC_ENGINE_MODEL_TYPE_ENTITY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
| 13 #include "sync/engine/non_blocking_sync_common.h" | 13 #include "sync/engine/non_blocking_sync_common.h" |
| 14 #include "sync/protocol/sync.pb.h" | 14 #include "sync/protocol/sync.pb.h" |
| 15 | 15 |
| 16 namespace syncer { | 16 namespace syncer { |
| 17 | 17 |
| 18 // This is the model thread's representation of a SyncEntity. | 18 // This is the model thread's representation of a SyncEntity. |
| 19 // | 19 // |
| 20 // The model thread sync entity receives updates from the model itself and | 20 // The model type entity receives updates from the model itself and |
| 21 // (asynchronously) from the sync server via the sync thread. From the point | 21 // (asynchronously) from the sync server via the sync thread. From the point |
| 22 // of view of this class, updates from the server take precedence over local | 22 // of view of this class, updates from the server take precedence over local |
| 23 // changes, though the model may be given an opportunity to overwrite this | 23 // changes, though the model may be given an opportunity to overwrite this |
| 24 // decision later. | 24 // decision later. |
| 25 // | 25 // |
| 26 // Sync will try to commit this entity's data to the sync server and local | 26 // Sync will try to commit this entity's data to the sync server and local |
| 27 // storage. | 27 // storage. |
| 28 // | 28 // |
| 29 // Most of the logic related to those processes live outside this class. This | 29 // Most of the logic related to those processes live outside this class. This |
| 30 // class helps out a bit by offering some functions to serialize its data to | 30 // class helps out a bit by offering some functions to serialize its data to |
| 31 // various formats and query the entity's status. | 31 // various formats and query the entity's status. |
| 32 class SYNC_EXPORT_PRIVATE ModelThreadSyncEntity { | 32 class SYNC_EXPORT_PRIVATE ModelTypeEntity { |
| 33 public: | 33 public: |
| 34 // Construct an instance representing a new locally-created item. | 34 // Construct an instance representing a new locally-created item. |
| 35 static scoped_ptr<ModelThreadSyncEntity> NewLocalItem( | 35 static scoped_ptr<ModelTypeEntity> NewLocalItem( |
| 36 const std::string& client_tag, | 36 const std::string& client_tag, |
| 37 const sync_pb::EntitySpecifics& specifics, | 37 const sync_pb::EntitySpecifics& specifics, |
| 38 base::Time now); | 38 base::Time now); |
| 39 | 39 |
| 40 // Construct an instance representing an item newly received from the server. | 40 // Construct an instance representing an item newly received from the server. |
| 41 static scoped_ptr<ModelThreadSyncEntity> FromServerUpdate( | 41 static scoped_ptr<ModelTypeEntity> FromServerUpdate( |
| 42 const std::string& id, | 42 const std::string& id, |
| 43 const std::string& client_tag_hash, | 43 const std::string& client_tag_hash, |
| 44 const std::string& non_unique_name, | 44 const std::string& non_unique_name, |
| 45 int64 version, | 45 int64 version, |
| 46 const sync_pb::EntitySpecifics& specifics, | 46 const sync_pb::EntitySpecifics& specifics, |
| 47 bool deleted, | 47 bool deleted, |
| 48 base::Time ctime, | 48 base::Time ctime, |
| 49 base::Time mtime); | 49 base::Time mtime); |
| 50 | 50 |
| 51 // TODO(rlarocque): Implement FromDisk constructor when we implement storage. | 51 // TODO(rlarocque): Implement FromDisk constructor when we implement storage. |
| 52 | 52 |
| 53 ~ModelThreadSyncEntity(); | 53 ~ModelTypeEntity(); |
| 54 | 54 |
| 55 // Returns true if this data is out of sync with local storage. | 55 // Returns true if this data is out of sync with local storage. |
| 56 bool IsWriteRequired() const; | 56 bool IsWriteRequired() const; |
| 57 | 57 |
| 58 // Returns true if this data is out of sync with the server. | 58 // Returns true if this data is out of sync with the server. |
| 59 // A commit may or may not be in progress at this time. | 59 // A commit may or may not be in progress at this time. |
| 60 bool IsUnsynced() const; | 60 bool IsUnsynced() const; |
| 61 | 61 |
| 62 // Returns true if this data is out of sync with the sync thread. | 62 // Returns true if this data is out of sync with the sync thread. |
| 63 // | 63 // |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 int64 sequence_number, | 106 int64 sequence_number, |
| 107 int64 response_version); | 107 int64 response_version); |
| 108 | 108 |
| 109 // Clears any in-memory sync state associated with outstanding commits. | 109 // Clears any in-memory sync state associated with outstanding commits. |
| 110 void ClearTransientSyncState(); | 110 void ClearTransientSyncState(); |
| 111 | 111 |
| 112 // Clears all sync state. Invoked when a user signs out. | 112 // Clears all sync state. Invoked when a user signs out. |
| 113 void ClearSyncState(); | 113 void ClearSyncState(); |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 ModelThreadSyncEntity(int64 sequence_number, | 116 ModelTypeEntity(int64 sequence_number, |
| 117 int64 commit_requested_sequence_number, | 117 int64 commit_requested_sequence_number, |
| 118 int64 acked_sequence_number, | 118 int64 acked_sequence_number, |
| 119 int64 base_version, | 119 int64 base_version, |
| 120 bool is_dirty, | 120 bool is_dirty, |
| 121 const std::string& id, | 121 const std::string& id, |
| 122 const std::string& client_tag_hash, | 122 const std::string& client_tag_hash, |
| 123 const std::string& non_unique_name, | 123 const std::string& non_unique_name, |
| 124 const sync_pb::EntitySpecifics& specifics, | 124 const sync_pb::EntitySpecifics& specifics, |
| 125 bool deleted, | 125 bool deleted, |
| 126 base::Time ctime, | 126 base::Time ctime, |
| 127 base::Time mtime); | 127 base::Time mtime); |
| 128 | 128 |
| 129 // A sequence number used to track in-progress commits. Each local change | 129 // A sequence number used to track in-progress commits. Each local change |
| 130 // increments this number. | 130 // increments this number. |
| 131 int64 sequence_number_; | 131 int64 sequence_number_; |
| 132 | 132 |
| 133 // The sequence number of the last item sent to the sync thread. | 133 // The sequence number of the last item sent to the sync thread. |
| 134 int64 commit_requested_sequence_number_; | 134 int64 commit_requested_sequence_number_; |
| 135 | 135 |
| 136 // The sequence number of the last item known to be successfully committed. | 136 // The sequence number of the last item known to be successfully committed. |
| 137 int64 acked_sequence_number_; | 137 int64 acked_sequence_number_; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 182 |
| 183 // Entity creation and modification timestamps. | 183 // Entity creation and modification timestamps. |
| 184 // Assigned by the client and synced by the server, though the server usually | 184 // Assigned by the client and synced by the server, though the server usually |
| 185 // doesn't bother to inspect their values. | 185 // doesn't bother to inspect their values. |
| 186 base::Time ctime_; | 186 base::Time ctime_; |
| 187 base::Time mtime_; | 187 base::Time mtime_; |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 } // namespace syncer | 190 } // namespace syncer |
| 191 | 191 |
| 192 #endif // SYNC_ENGINE_MODEL_THREAD_SYNC_ENTITY_H_ | 192 #endif // SYNC_ENGINE_MODEL_TYPE_ENTITY_H_ |
| OLD | NEW |