| 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 there we did not detect any errors in this session. | 115 // Returns true if we completely ran the session without errors. |
| 116 // | 116 // |
| 117 // There are many errors that could prevent a sync cycle from succeeding. | 117 // There are many errors that could prevent a sync cycle from succeeding. |
| 118 // These include invalid local state, inability to contact the server, | 118 // These include invalid local state, inability to contact the server, |
| 119 // inability to authenticate with the server, and server errors. What they | 119 // inability to authenticate with the server, and server errors. What they |
| 120 // have in common is that the we either need to take some action and then | 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 | 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 | 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 | 123 // assume that the original action that triggered the sync cycle (ie. a nudge |
| 124 // or a notification) has been properly serviced. | 124 // or a notification) has been properly serviced. |
| 125 // | 125 // |
| 126 // This function also returns false if SyncShare has not been called on this | 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 | 127 // session yet, or if ResetTransientState() has been called on this session |
| 128 // since the last call to SyncShare. | 128 // since the last call to SyncShare. |
| 129 bool Succeeded() const; | 129 bool Succeeded() const; |
| 130 | 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 |
| 131 // Collects all state pertaining to how and why |s| originated and unions it | 135 // Collects all state pertaining to how and why |s| originated and unions it |
| 132 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| | 136 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| |
| 133 // to take on the responsibilities |s| had (e.g. certain data types) in the | 137 // to take on the responsibilities |s| had (e.g. certain data types) in the |
| 134 // next SyncShare operation using |this|, rather than needed two separate | 138 // next SyncShare operation using |this|, rather than needed two separate |
| 135 // sessions. | 139 // sessions. |
| 136 void Coalesce(const SyncSession& session); | 140 void Coalesce(const SyncSession& session); |
| 137 | 141 |
| 138 // Compares the routing_info_, workers and payload map with the passed in | 142 // Compares the routing_info_, workers and payload map with the passed in |
| 139 // session. Purges types from the above 3 which are not in session. Useful | 143 // session. Purges types from the above 3 which are not in session. Useful |
| 140 // to update the sync session when the user has disabled some types from | 144 // to update the sync session when the user has disabled some types from |
| (...skipping 28 matching lines...) Expand all Loading... |
| 169 | 173 |
| 170 // Returns the set of groups which have enabled types. | 174 // Returns the set of groups which have enabled types. |
| 171 const std::set<ModelSafeGroup>& GetEnabledGroups() const; | 175 const std::set<ModelSafeGroup>& GetEnabledGroups() const; |
| 172 | 176 |
| 173 // Returns the set of enabled groups that have conflicts. | 177 // Returns the set of enabled groups that have conflicts. |
| 174 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; | 178 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; |
| 175 | 179 |
| 176 // Returns the set of enabled groups that have verified updates. | 180 // Returns the set of enabled groups that have verified updates. |
| 177 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const; | 181 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const; |
| 178 | 182 |
| 183 // Mark the session has having finished all the sync steps it needed. |
| 184 void SetFinished(); |
| 185 |
| 179 private: | 186 private: |
| 180 // Extend the encapsulation boundary to utilities for internal member | 187 // Extend the encapsulation boundary to utilities for internal member |
| 181 // assignments. This way, the scope of these actions is explicit, they can't | 188 // assignments. This way, the scope of these actions is explicit, they can't |
| 182 // be overridden, and assigning is always accompanied by unassigning. | 189 // be overridden, and assigning is always accompanied by unassigning. |
| 183 friend class ScopedSetSessionWriteTransaction; | 190 friend class ScopedSetSessionWriteTransaction; |
| 184 | 191 |
| 185 // The context for this session, guaranteed to outlive |this|. | 192 // The context for this session, guaranteed to outlive |this|. |
| 186 SyncSessionContext* const context_; | 193 SyncSessionContext* const context_; |
| 187 | 194 |
| 188 // The source for initiating this sync session. | 195 // The source for initiating this sync session. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 206 | 213 |
| 207 // The routing info for the duration of this session, dictating which | 214 // The routing info for the duration of this session, dictating which |
| 208 // datatypes should be synced and which workers should be used when working | 215 // datatypes should be synced and which workers should be used when working |
| 209 // on those datatypes. | 216 // on those datatypes. |
| 210 ModelSafeRoutingInfo routing_info_; | 217 ModelSafeRoutingInfo routing_info_; |
| 211 | 218 |
| 212 // The set of groups with enabled types. Computed from | 219 // The set of groups with enabled types. Computed from |
| 213 // |routing_info_|. | 220 // |routing_info_|. |
| 214 std::set<ModelSafeGroup> enabled_groups_; | 221 std::set<ModelSafeGroup> enabled_groups_; |
| 215 | 222 |
| 223 // Whether this session has reached its last step or not. Gets reset on each |
| 224 // new cycle (via PrepareForAnotherSyncCycle). |
| 225 bool finished_; |
| 226 |
| 216 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 227 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 217 }; | 228 }; |
| 218 | 229 |
| 219 // Installs a WriteTransaction to a given session and later clears it when the | 230 // Installs a WriteTransaction to a given session and later clears it when the |
| 220 // utility falls out of scope. Transactions are not nestable, so it is an error | 231 // utility falls out of scope. Transactions are not nestable, so it is an error |
| 221 // to try and use one of these if the session already has a transaction. | 232 // to try and use one of these if the session already has a transaction. |
| 222 class ScopedSetSessionWriteTransaction { | 233 class ScopedSetSessionWriteTransaction { |
| 223 public: | 234 public: |
| 224 ScopedSetSessionWriteTransaction(SyncSession* session, | 235 ScopedSetSessionWriteTransaction(SyncSession* session, |
| 225 syncable::WriteTransaction* trans) | 236 syncable::WriteTransaction* trans) |
| 226 : session_(session) { | 237 : session_(session) { |
| 227 DCHECK(!session_->write_transaction_); | 238 DCHECK(!session_->write_transaction_); |
| 228 session_->write_transaction_ = trans; | 239 session_->write_transaction_ = trans; |
| 229 } | 240 } |
| 230 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 241 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
| 231 | 242 |
| 232 private: | 243 private: |
| 233 SyncSession* session_; | 244 SyncSession* session_; |
| 234 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 245 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
| 235 }; | 246 }; |
| 236 | 247 |
| 237 } // namespace sessions | 248 } // namespace sessions |
| 238 } // namespace browser_sync | 249 } // namespace browser_sync |
| 239 | 250 |
| 240 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ | 251 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |