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 // | |
130 // Note: this method ignore Sync Protocol and Client Actionable errors. | |
129 bool Succeeded() const; | 131 bool Succeeded() const; |
130 | 132 |
133 // Returns true if we reached the server successfully and the server did not | |
134 // return any error codes. Returns false if no connection was attempted. | |
135 bool SuccessfullyReachServer() const; | |
rlarocque
2012/06/06 19:32:32
SuccessfullyReachedServer()?
Nicolas Zea
2012/06/06 20:36:15
Done.
| |
136 | |
131 // Collects all state pertaining to how and why |s| originated and unions it | 137 // Collects all state pertaining to how and why |s| originated and unions it |
132 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| | 138 // 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 | 139 // 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 | 140 // next SyncShare operation using |this|, rather than needed two separate |
135 // sessions. | 141 // sessions. |
136 void Coalesce(const SyncSession& session); | 142 void Coalesce(const SyncSession& session); |
137 | 143 |
138 // Compares the routing_info_, workers and payload map with the passed in | 144 // 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 | 145 // 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 | 146 // to update the sync session when the user has disabled some types from |
(...skipping 28 matching lines...) Expand all Loading... | |
169 | 175 |
170 // Returns the set of groups which have enabled types. | 176 // Returns the set of groups which have enabled types. |
171 const std::set<ModelSafeGroup>& GetEnabledGroups() const; | 177 const std::set<ModelSafeGroup>& GetEnabledGroups() const; |
172 | 178 |
173 // Returns the set of enabled groups that have conflicts. | 179 // Returns the set of enabled groups that have conflicts. |
174 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; | 180 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; |
175 | 181 |
176 // Returns the set of enabled groups that have verified updates. | 182 // Returns the set of enabled groups that have verified updates. |
177 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const; | 183 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const; |
178 | 184 |
185 // Mark the session has having finished all the sync steps it needed. | |
186 void SetFinished(); | |
187 | |
179 private: | 188 private: |
180 // Extend the encapsulation boundary to utilities for internal member | 189 // Extend the encapsulation boundary to utilities for internal member |
181 // assignments. This way, the scope of these actions is explicit, they can't | 190 // assignments. This way, the scope of these actions is explicit, they can't |
182 // be overridden, and assigning is always accompanied by unassigning. | 191 // be overridden, and assigning is always accompanied by unassigning. |
183 friend class ScopedSetSessionWriteTransaction; | 192 friend class ScopedSetSessionWriteTransaction; |
184 | 193 |
185 // The context for this session, guaranteed to outlive |this|. | 194 // The context for this session, guaranteed to outlive |this|. |
186 SyncSessionContext* const context_; | 195 SyncSessionContext* const context_; |
187 | 196 |
188 // The source for initiating this sync session. | 197 // The source for initiating this sync session. |
(...skipping 17 matching lines...) Expand all Loading... | |
206 | 215 |
207 // The routing info for the duration of this session, dictating which | 216 // The routing info for the duration of this session, dictating which |
208 // datatypes should be synced and which workers should be used when working | 217 // datatypes should be synced and which workers should be used when working |
209 // on those datatypes. | 218 // on those datatypes. |
210 ModelSafeRoutingInfo routing_info_; | 219 ModelSafeRoutingInfo routing_info_; |
211 | 220 |
212 // The set of groups with enabled types. Computed from | 221 // The set of groups with enabled types. Computed from |
213 // |routing_info_|. | 222 // |routing_info_|. |
214 std::set<ModelSafeGroup> enabled_groups_; | 223 std::set<ModelSafeGroup> enabled_groups_; |
215 | 224 |
225 // Whether this session has reached its last step or not. | |
226 bool finished_; | |
227 | |
216 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 228 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
217 }; | 229 }; |
218 | 230 |
219 // Installs a WriteTransaction to a given session and later clears it when the | 231 // 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 | 232 // 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. | 233 // to try and use one of these if the session already has a transaction. |
222 class ScopedSetSessionWriteTransaction { | 234 class ScopedSetSessionWriteTransaction { |
223 public: | 235 public: |
224 ScopedSetSessionWriteTransaction(SyncSession* session, | 236 ScopedSetSessionWriteTransaction(SyncSession* session, |
225 syncable::WriteTransaction* trans) | 237 syncable::WriteTransaction* trans) |
226 : session_(session) { | 238 : session_(session) { |
227 DCHECK(!session_->write_transaction_); | 239 DCHECK(!session_->write_transaction_); |
228 session_->write_transaction_ = trans; | 240 session_->write_transaction_ = trans; |
229 } | 241 } |
230 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 242 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
231 | 243 |
232 private: | 244 private: |
233 SyncSession* session_; | 245 SyncSession* session_; |
234 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 246 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
235 }; | 247 }; |
236 | 248 |
237 } // namespace sessions | 249 } // namespace sessions |
238 } // namespace browser_sync | 250 } // namespace browser_sync |
239 | 251 |
240 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ | 252 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ |
OLD | NEW |