| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A class representing an attempt to synchronize the local syncable data | 5 // A class representing an attempt to synchronize the local syncable data |
| 6 // store with a sync server. A SyncSession instance is passed as a stateful | 6 // store with a sync server. A SyncSession instance is passed as a stateful |
| 7 // bundle to and from various SyncerCommands with the goal of converging the | 7 // bundle to and from various SyncerCommands with the goal of converging the |
| 8 // client view of data with that of the server. The commands twiddle with | 8 // client view of data with that of the server. The commands twiddle with |
| 9 // session status in response to events and hiccups along the way, set and | 9 // session status in response to events and hiccups along the way, set and |
| 10 // query session progress with regards to conflict resolution and applying | 10 // query session progress with regards to conflict resolution and applying |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Builds a thread-safe and read-only copy of the current session state. | 105 // Builds a thread-safe and read-only copy of the current session state. |
| 106 SyncSessionSnapshot TakeSnapshot() const; | 106 SyncSessionSnapshot TakeSnapshot() const; |
| 107 | 107 |
| 108 // Builds and sends a snapshot to the session context's listeners. | 108 // Builds and sends a snapshot to the session context's listeners. |
| 109 void SendEventNotification(SyncEngineEvent::EventCause cause); | 109 void SendEventNotification(SyncEngineEvent::EventCause cause); |
| 110 | 110 |
| 111 // Returns true if this session contains data that should go through the sync | 111 // Returns true if this session contains data that should go through the sync |
| 112 // engine again. | 112 // engine again. |
| 113 bool HasMoreToSync() const; | 113 bool HasMoreToSync() const; |
| 114 | 114 |
| 115 // Returns true if we completely ran the session without errors. | 115 // Returns true if we reached the server. Note that "reaching the server" |
| 116 // | 116 // here means that from an HTTP perspective, we succeeded (HTTP 200). The |
| 117 // There are many errors that could prevent a sync cycle from succeeding. | 117 // server **MAY** have returned a sync protocol error. |
| 118 // These include invalid local state, inability to contact the server, | 118 // See SERVER_RETURN_* in the SyncerError enum for values. |
| 119 // inability to authenticate with the server, and server errors. What they | 119 bool DidReachServer() const; |
| 120 // have in common is that the we either need to take some action and then | |
| 121 // retry the sync cycle or, in the case of transient errors, retry after some | |
| 122 // backoff timer has expired. Most importantly, the SyncScheduler should not | |
| 123 // assume that the original action that triggered the sync cycle (ie. a nudge | |
| 124 // or a notification) has been properly serviced. | |
| 125 // | |
| 126 // This function also returns false if SyncShare has not been called on this | |
| 127 // session yet, or if ResetTransientState() has been called on this session | |
| 128 // since the last call to SyncShare. | |
| 129 bool Succeeded() const; | |
| 130 | |
| 131 // Returns true if we reached the server successfully and the server did not | |
| 132 // return any error codes. Returns false if no connection was attempted. | |
| 133 bool SuccessfullyReachedServer() const; | |
| 134 | 120 |
| 135 // Collects all state pertaining to how and why |s| originated and unions it | 121 // Collects all state pertaining to how and why |s| originated and unions it |
| 136 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| | 122 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| |
| 137 // to take on the responsibilities |s| had (e.g. certain data types) in the | 123 // to take on the responsibilities |s| had (e.g. certain data types) in the |
| 138 // next SyncShare operation using |this|, rather than needed two separate | 124 // next SyncShare operation using |this|, rather than needed two separate |
| 139 // sessions. | 125 // sessions. |
| 140 void Coalesce(const SyncSession& session); | 126 void Coalesce(const SyncSession& session); |
| 141 | 127 |
| 142 // Compares the routing_info_, workers and payload map with the passed in | 128 // Compares the routing_info_, workers and payload map with those passed in. |
| 143 // session. Purges types from the above 3 which are not in session. Useful | 129 // Purges types from the above 3 which are not present in latest. Useful |
| 144 // to update the sync session when the user has disabled some types from | 130 // to update the sync session when the user has disabled some types from |
| 145 // syncing. | 131 // syncing. |
| 146 void RebaseRoutingInfoWithLatest(const SyncSession& session); | 132 void RebaseRoutingInfoWithLatest( |
| 133 const ModelSafeRoutingInfo& routing_info, |
| 134 const std::vector<ModelSafeWorker*>& workers); |
| 147 | 135 |
| 148 // Should be called any time |this| is being re-used in a new call to | 136 // Should be called any time |this| is being re-used in a new call to |
| 149 // SyncShare (e.g., HasMoreToSync returned true). | 137 // SyncShare (e.g., HasMoreToSync returned true). |
| 150 void PrepareForAnotherSyncCycle(); | 138 void PrepareForAnotherSyncCycle(); |
| 151 | 139 |
| 152 // TODO(akalin): Split this into context() and mutable_context(). | 140 // TODO(akalin): Split this into context() and mutable_context(). |
| 153 SyncSessionContext* context() const { return context_; } | 141 SyncSessionContext* context() const { return context_; } |
| 154 Delegate* delegate() const { return delegate_; } | 142 Delegate* delegate() const { return delegate_; } |
| 155 syncable::WriteTransaction* write_transaction() { return write_transaction_; } | 143 syncable::WriteTransaction* write_transaction() { return write_transaction_; } |
| 156 const StatusController& status_controller() const { | 144 const StatusController& status_controller() const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 173 | 161 |
| 174 // Returns the set of groups which have enabled types. | 162 // Returns the set of groups which have enabled types. |
| 175 const std::set<ModelSafeGroup>& GetEnabledGroups() const; | 163 const std::set<ModelSafeGroup>& GetEnabledGroups() const; |
| 176 | 164 |
| 177 // Returns the set of enabled groups that have conflicts. | 165 // Returns the set of enabled groups that have conflicts. |
| 178 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; | 166 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; |
| 179 | 167 |
| 180 // Returns the set of enabled groups that have verified updates. | 168 // Returns the set of enabled groups that have verified updates. |
| 181 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const; | 169 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const; |
| 182 | 170 |
| 183 // Mark the session has having finished all the sync steps it needed. | |
| 184 void SetFinished(); | |
| 185 | |
| 186 private: | 171 private: |
| 187 // Extend the encapsulation boundary to utilities for internal member | 172 // Extend the encapsulation boundary to utilities for internal member |
| 188 // assignments. This way, the scope of these actions is explicit, they can't | 173 // assignments. This way, the scope of these actions is explicit, they can't |
| 189 // be overridden, and assigning is always accompanied by unassigning. | 174 // be overridden, and assigning is always accompanied by unassigning. |
| 190 friend class ScopedSetSessionWriteTransaction; | 175 friend class ScopedSetSessionWriteTransaction; |
| 191 | 176 |
| 192 // The context for this session, guaranteed to outlive |this|. | 177 // The context for this session, guaranteed to outlive |this|. |
| 193 SyncSessionContext* const context_; | 178 SyncSessionContext* const context_; |
| 194 | 179 |
| 195 // The source for initiating this sync session. | 180 // The source for initiating this sync session. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 213 | 198 |
| 214 // The routing info for the duration of this session, dictating which | 199 // The routing info for the duration of this session, dictating which |
| 215 // datatypes should be synced and which workers should be used when working | 200 // datatypes should be synced and which workers should be used when working |
| 216 // on those datatypes. | 201 // on those datatypes. |
| 217 ModelSafeRoutingInfo routing_info_; | 202 ModelSafeRoutingInfo routing_info_; |
| 218 | 203 |
| 219 // The set of groups with enabled types. Computed from | 204 // The set of groups with enabled types. Computed from |
| 220 // |routing_info_|. | 205 // |routing_info_|. |
| 221 std::set<ModelSafeGroup> enabled_groups_; | 206 std::set<ModelSafeGroup> enabled_groups_; |
| 222 | 207 |
| 223 // Whether this session has reached its last step or not. Gets reset on each | |
| 224 // new cycle (via PrepareForAnotherSyncCycle). | |
| 225 bool finished_; | |
| 226 | |
| 227 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 208 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 228 }; | 209 }; |
| 229 | 210 |
| 230 // Installs a WriteTransaction to a given session and later clears it when the | 211 // Installs a WriteTransaction to a given session and later clears it when the |
| 231 // utility falls out of scope. Transactions are not nestable, so it is an error | 212 // utility falls out of scope. Transactions are not nestable, so it is an error |
| 232 // to try and use one of these if the session already has a transaction. | 213 // to try and use one of these if the session already has a transaction. |
| 233 class ScopedSetSessionWriteTransaction { | 214 class ScopedSetSessionWriteTransaction { |
| 234 public: | 215 public: |
| 235 ScopedSetSessionWriteTransaction(SyncSession* session, | 216 ScopedSetSessionWriteTransaction(SyncSession* session, |
| 236 syncable::WriteTransaction* trans) | 217 syncable::WriteTransaction* trans) |
| 237 : session_(session) { | 218 : session_(session) { |
| 238 DCHECK(!session_->write_transaction_); | 219 DCHECK(!session_->write_transaction_); |
| 239 session_->write_transaction_ = trans; | 220 session_->write_transaction_ = trans; |
| 240 } | 221 } |
| 241 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 222 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
| 242 | 223 |
| 243 private: | 224 private: |
| 244 SyncSession* session_; | 225 SyncSession* session_; |
| 245 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 226 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
| 246 }; | 227 }; |
| 247 | 228 |
| 248 } // namespace sessions | 229 } // namespace sessions |
| 249 } // namespace syncer | 230 } // namespace syncer |
| 250 | 231 |
| 251 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ | 232 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |