| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // The sync process consists of a sequence of sync cycles, each of which | |
| 6 // (hopefully) moves the client into closer synchronization with the server. | |
| 7 // This class holds state that is pertinent to a single sync cycle. | |
| 8 // | |
| 9 // THIS CLASS PROVIDES NO SYNCHRONIZATION GUARANTEES. | |
| 10 | |
| 11 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNC_CYCLE_STATE_H_ | |
| 12 #define CHROME_BROWSER_SYNC_ENGINE_SYNC_CYCLE_STATE_H_ | |
| 13 | |
| 14 #include <utility> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "base/basictypes.h" | |
| 18 #include "chrome/browser/sync/engine/syncer_types.h" | |
| 19 #include "chrome/browser/sync/engine/syncproto.h" | |
| 20 #include "chrome/browser/sync/util/event_sys.h" | |
| 21 | |
| 22 namespace syncable { | |
| 23 class WriteTransaction; | |
| 24 class Id; | |
| 25 } // namespace syncable | |
| 26 | |
| 27 namespace browser_sync { | |
| 28 | |
| 29 typedef std::pair<VerifyResult, sync_pb::SyncEntity> VerifiedUpdate; | |
| 30 typedef std::pair<UpdateAttemptResponse, syncable::Id> AppliedUpdate; | |
| 31 | |
| 32 // This is the type declaration for the eventsys channel that the syncer uses | |
| 33 // to send events to other system components. | |
| 34 struct SyncerEvent; | |
| 35 | |
| 36 // SyncCycleState holds the entire state of a single sync cycle; | |
| 37 // GetUpdates, Commit, and Conflict Resolution. After said cycle, the | |
| 38 // State may contain items that were unable to be processed because of | |
| 39 // errors. | |
| 40 class SyncCycleState { | |
| 41 public: | |
| 42 SyncCycleState() | |
| 43 : write_transaction_(NULL), | |
| 44 conflict_sets_built_(false), | |
| 45 conflicts_resolved_(false), | |
| 46 items_committed_(false), | |
| 47 over_quota_(false), | |
| 48 timestamp_dirty_(false), | |
| 49 dirty_(true) {} | |
| 50 | |
| 51 void set_update_response(const ClientToServerResponse& update_response) { | |
| 52 update_response_.CopyFrom(update_response); | |
| 53 } | |
| 54 | |
| 55 const ClientToServerResponse& update_response() const { | |
| 56 return update_response_; | |
| 57 } | |
| 58 | |
| 59 void set_commit_response(const ClientToServerResponse& commit_response) { | |
| 60 commit_response_.CopyFrom(commit_response); | |
| 61 } | |
| 62 | |
| 63 const ClientToServerResponse& commit_response() const { | |
| 64 return commit_response_; | |
| 65 } | |
| 66 | |
| 67 void AddVerifyResult(const VerifyResult& verify_result, | |
| 68 const sync_pb::SyncEntity& entity) { | |
| 69 verified_updates_.push_back(std::make_pair(verify_result, entity)); | |
| 70 } | |
| 71 | |
| 72 bool HasVerifiedUpdates() const { | |
| 73 return !verified_updates_.empty(); | |
| 74 } | |
| 75 | |
| 76 // Log a successful or failing update attempt. | |
| 77 void AddAppliedUpdate(const UpdateAttemptResponse& response, | |
| 78 const syncable::Id& id) { | |
| 79 applied_updates_.push_back(std::make_pair(response, id)); | |
| 80 } | |
| 81 | |
| 82 bool HasAppliedUpdates() const { | |
| 83 return !applied_updates_.empty(); | |
| 84 } | |
| 85 | |
| 86 std::vector<AppliedUpdate>::iterator AppliedUpdatesBegin() { | |
| 87 return applied_updates_.begin(); | |
| 88 } | |
| 89 | |
| 90 std::vector<VerifiedUpdate>::iterator VerifiedUpdatesBegin() { | |
| 91 return verified_updates_.begin(); | |
| 92 } | |
| 93 | |
| 94 std::vector<AppliedUpdate>::iterator AppliedUpdatesEnd() { | |
| 95 return applied_updates_.end(); | |
| 96 } | |
| 97 | |
| 98 std::vector<VerifiedUpdate>::iterator VerifiedUpdatesEnd() { | |
| 99 return verified_updates_.end(); | |
| 100 } | |
| 101 | |
| 102 // Returns the number of update application attempts. This includes both | |
| 103 // failures and successes. | |
| 104 int AppliedUpdatesSize() const { | |
| 105 return applied_updates_.size(); | |
| 106 } | |
| 107 | |
| 108 // Count the number of successful update applications that have happend this | |
| 109 // cycle. Note that if an item is successfully applied twice, it will be | |
| 110 // double counted here. | |
| 111 int SuccessfullyAppliedUpdateCount() const { | |
| 112 int count = 0; | |
| 113 for (std::vector<AppliedUpdate>::const_iterator it = | |
| 114 applied_updates_.begin(); | |
| 115 it != applied_updates_.end(); | |
| 116 ++it) { | |
| 117 if (it->first == SUCCESS) | |
| 118 count++; | |
| 119 } | |
| 120 return count; | |
| 121 } | |
| 122 | |
| 123 int VerifiedUpdatesSize() const { | |
| 124 return verified_updates_.size(); | |
| 125 } | |
| 126 | |
| 127 const std::vector<int64>& unsynced_handles() const { | |
| 128 return unsynced_handles_; | |
| 129 } | |
| 130 | |
| 131 void set_unsynced_handles(const std::vector<int64>& unsynced_handles) { | |
| 132 UpdateDirty(unsynced_handles != unsynced_handles_); | |
| 133 unsynced_handles_ = unsynced_handles; | |
| 134 } | |
| 135 | |
| 136 int64 unsynced_count() const { return unsynced_handles_.size(); } | |
| 137 | |
| 138 const std::vector<syncable::Id>& commit_ids() const { return commit_ids_; } | |
| 139 | |
| 140 void set_commit_ids(const std::vector<syncable::Id>& commit_ids) { | |
| 141 commit_ids_ = commit_ids; | |
| 142 } | |
| 143 | |
| 144 bool commit_ids_empty() const { return commit_ids_.empty(); } | |
| 145 | |
| 146 // The write transaction must be deleted by the caller of this function. | |
| 147 void set_write_transaction(syncable::WriteTransaction* write_transaction) { | |
| 148 DCHECK(!write_transaction_) << "Forgot to clear the write transaction."; | |
| 149 write_transaction_ = write_transaction; | |
| 150 } | |
| 151 | |
| 152 syncable::WriteTransaction* write_transaction() const { | |
| 153 return write_transaction_; | |
| 154 } | |
| 155 | |
| 156 bool has_open_write_transaction() { return write_transaction_ != NULL; } | |
| 157 | |
| 158 // Sets the write transaction to null, but doesn't free the memory. | |
| 159 void ClearWriteTransaction() { write_transaction_ = NULL; } | |
| 160 | |
| 161 ClientToServerMessage* commit_message() { return &commit_message_; } | |
| 162 | |
| 163 void set_commit_message(ClientToServerMessage message) { | |
| 164 commit_message_ = message; | |
| 165 } | |
| 166 | |
| 167 void set_conflict_sets_built(bool b) { | |
| 168 conflict_sets_built_ = b; | |
| 169 } | |
| 170 | |
| 171 bool conflict_sets_built() const { | |
| 172 return conflict_sets_built_; | |
| 173 } | |
| 174 | |
| 175 void set_conflicts_resolved(bool b) { | |
| 176 conflicts_resolved_ = b; | |
| 177 } | |
| 178 | |
| 179 bool conflicts_resolved() const { | |
| 180 return conflicts_resolved_; | |
| 181 } | |
| 182 | |
| 183 void set_over_quota(bool b) { | |
| 184 UpdateDirty(b != over_quota_); | |
| 185 over_quota_ = b; | |
| 186 } | |
| 187 | |
| 188 bool over_quota() const { | |
| 189 return over_quota_; | |
| 190 } | |
| 191 | |
| 192 void set_item_committed() { items_committed_ |= true; } | |
| 193 | |
| 194 bool items_committed() const { return items_committed_; } | |
| 195 | |
| 196 // Returns true if this object has been modified since last SetClean() call. | |
| 197 bool IsDirty() const { return dirty_; } | |
| 198 | |
| 199 // Call to tell this status object that its new state has been seen. | |
| 200 void SetClean() { dirty_ = false; } | |
| 201 | |
| 202 // Indicate that we've made a change to directory timestamp. | |
| 203 void set_timestamp_dirty() { | |
| 204 timestamp_dirty_ = true; | |
| 205 } | |
| 206 | |
| 207 bool is_timestamp_dirty() const { | |
| 208 return timestamp_dirty_; | |
| 209 } | |
| 210 | |
| 211 private: | |
| 212 void UpdateDirty(bool new_info) { dirty_ |= new_info; } | |
| 213 | |
| 214 // Download updates supplies: | |
| 215 ClientToServerResponse update_response_; | |
| 216 ClientToServerResponse commit_response_; | |
| 217 ClientToServerMessage commit_message_; | |
| 218 | |
| 219 syncable::WriteTransaction* write_transaction_; | |
| 220 std::vector<int64> unsynced_handles_; | |
| 221 std::vector<syncable::Id> commit_ids_; | |
| 222 | |
| 223 // At a certain point during the sync process we'll want to build the | |
| 224 // conflict sets. This variable tracks whether or not that has happened. | |
| 225 bool conflict_sets_built_; | |
| 226 bool conflicts_resolved_; | |
| 227 bool items_committed_; | |
| 228 bool over_quota_; | |
| 229 | |
| 230 // If we've set the timestamp to a new value during this cycle. | |
| 231 bool timestamp_dirty_; | |
| 232 | |
| 233 bool dirty_; | |
| 234 | |
| 235 // Some container for updates that failed verification. | |
| 236 std::vector<VerifiedUpdate> verified_updates_; | |
| 237 | |
| 238 // Stores the result of the various ApplyUpdate attempts we've made. | |
| 239 // May contain duplicate entries. | |
| 240 std::vector<AppliedUpdate> applied_updates_; | |
| 241 | |
| 242 DISALLOW_COPY_AND_ASSIGN(SyncCycleState); | |
| 243 }; | |
| 244 | |
| 245 } // namespace browser_sync | |
| 246 | |
| 247 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNC_CYCLE_STATE_H_ | |
| OLD | NEW |