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_ENTITY_TRACKER_H_ | 5 #ifndef SYNC_ENGINE_ENTITY_TRACKER_H_ |
6 #define SYNC_ENGINE_ENTITY_TRACKER_H_ | 6 #define SYNC_ENGINE_ENTITY_TRACKER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "sync/base/sync_export.h" | 13 #include "sync/base/sync_export.h" |
| 14 #include "sync/internal_api/public/non_blocking_sync_common.h" |
13 #include "sync/protocol/sync.pb.h" | 15 #include "sync/protocol/sync.pb.h" |
14 | 16 |
15 namespace syncer { | 17 namespace syncer { |
16 | 18 |
17 // Manages the pending commit and update state for an entity on the sync | 19 // Manages the pending commit and update state for an entity on the sync |
18 // thread. | 20 // thread. |
19 // | 21 // |
20 // It should be considered a helper class internal to the | 22 // It should be considered a helper class internal to the |
21 // ModelTypeSyncWorker. | 23 // ModelTypeSyncWorker. |
22 // | 24 // |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Since commits happen entirely on the sync thread, we can safely assume | 76 // Since commits happen entirely on the sync thread, we can safely assume |
75 // that our item's state at the end of the commit is the same as it was at | 77 // that our item's state at the end of the commit is the same as it was at |
76 // the start. | 78 // the start. |
77 void ReceiveCommitResponse(const std::string& response_id, | 79 void ReceiveCommitResponse(const std::string& response_id, |
78 int64 response_version, | 80 int64 response_version, |
79 int64 sequence_number); | 81 int64 sequence_number); |
80 | 82 |
81 // Handles receipt of an update from the server. | 83 // Handles receipt of an update from the server. |
82 void ReceiveUpdate(int64 version); | 84 void ReceiveUpdate(int64 version); |
83 | 85 |
| 86 // Handles the receipt of an pending update from the server. |
| 87 // |
| 88 // Returns true if the tracker decides this item is worth keeping. Returns |
| 89 // false if the item is discarded, which could happen if the version number |
| 90 // is out of date. |
| 91 bool ReceivePendingUpdate(const UpdateResponseData& data); |
| 92 |
| 93 // Functions to fetch the latest pending update. |
| 94 bool HasPendingUpdate() const; |
| 95 UpdateResponseData GetPendingUpdate() const; |
| 96 |
| 97 // Clears the pending update. Allows us to resume regular commit behavior. |
| 98 void ClearPendingUpdate(); |
| 99 |
84 private: | 100 private: |
85 // Initializes received update state. Does not initialize state related to | 101 // Initializes received update state. Does not initialize state related to |
86 // pending commits and sets |is_commit_pending_| to false. | 102 // pending commits and sets |is_commit_pending_| to false. |
87 EntityTracker(const std::string& id, | 103 EntityTracker(const std::string& id, |
88 const std::string& client_tag_hash, | 104 const std::string& client_tag_hash, |
89 int64 highest_commit_response_version, | 105 int64 highest_commit_response_version, |
90 int64 highest_gu_response_version); | 106 int64 highest_gu_response_version); |
91 | 107 |
92 // Initializes all fields. Sets |is_commit_pending_| to true. | 108 // Initializes all fields. Sets |is_commit_pending_| to true. |
93 EntityTracker(const std::string& id, | 109 EntityTracker(const std::string& id, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // The following fields are valid only when a commit is pending. | 155 // The following fields are valid only when a commit is pending. |
140 // This is where we store the data that is to be sent up to the server | 156 // This is where we store the data that is to be sent up to the server |
141 // at the next possible opportunity. | 157 // at the next possible opportunity. |
142 int64 base_version_; | 158 int64 base_version_; |
143 base::Time ctime_; | 159 base::Time ctime_; |
144 base::Time mtime_; | 160 base::Time mtime_; |
145 std::string non_unique_name_; | 161 std::string non_unique_name_; |
146 bool deleted_; | 162 bool deleted_; |
147 sync_pb::EntitySpecifics specifics_; | 163 sync_pb::EntitySpecifics specifics_; |
148 | 164 |
| 165 // An update for this item which can't be applied right now. The presence of |
| 166 // an pending update prevents commits. As of this writing, the only source |
| 167 // of pending updates is updates we can't decrypt right now. |
| 168 scoped_ptr<UpdateResponseData> pending_update_; |
| 169 |
149 DISALLOW_COPY_AND_ASSIGN(EntityTracker); | 170 DISALLOW_COPY_AND_ASSIGN(EntityTracker); |
150 }; | 171 }; |
151 | 172 |
152 } // namespace syncer | 173 } // namespace syncer |
153 | 174 |
154 #endif // SYNC_ENGINE_ENTITY_TRACKER_H_ | 175 #endif // SYNC_ENGINE_ENTITY_TRACKER_H_ |
OLD | NEW |