Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: sync/sessions/sync_session.h

Issue 11342008: Revert 164565 - sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1311/src/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/sessions/session_state_unittest.cc ('k') | sync/sessions/sync_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 reached the server. Note that "reaching the server" 115 // Returns true if we completely ran the session without errors.
116 // here means that from an HTTP perspective, we succeeded (HTTP 200). The 116 //
117 // server **MAY** have returned a sync protocol error. 117 // There are many errors that could prevent a sync cycle from succeeding.
118 // See SERVER_RETURN_* in the SyncerError enum for values. 118 // These include invalid local state, inability to contact the server,
119 bool DidReachServer() const; 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
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;
120 134
121 // 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
122 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| 136 // with corresponding state in |this|, leaving |s| unchanged. Allows |this|
123 // 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
124 // next SyncShare operation using |this|, rather than needed two separate 138 // next SyncShare operation using |this|, rather than needed two separate
125 // sessions. 139 // sessions.
126 void Coalesce(const SyncSession& session); 140 void Coalesce(const SyncSession& session);
127 141
128 // Compares the routing_info_, workers and payload map with those passed in. 142 // Compares the routing_info_, workers and payload map with the passed in
129 // Purges types from the above 3 which are not present in latest. Useful 143 // session. Purges types from the above 3 which are not in session. Useful
130 // 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
131 // syncing. 145 // syncing.
132 void RebaseRoutingInfoWithLatest( 146 void RebaseRoutingInfoWithLatest(const SyncSession& session);
133 const ModelSafeRoutingInfo& routing_info,
134 const std::vector<ModelSafeWorker*>& workers);
135 147
136 // Should be called any time |this| is being re-used in a new call to 148 // Should be called any time |this| is being re-used in a new call to
137 // SyncShare (e.g., HasMoreToSync returned true). 149 // SyncShare (e.g., HasMoreToSync returned true).
138 void PrepareForAnotherSyncCycle(); 150 void PrepareForAnotherSyncCycle();
139 151
140 // TODO(akalin): Split this into context() and mutable_context(). 152 // TODO(akalin): Split this into context() and mutable_context().
141 SyncSessionContext* context() const { return context_; } 153 SyncSessionContext* context() const { return context_; }
142 Delegate* delegate() const { return delegate_; } 154 Delegate* delegate() const { return delegate_; }
143 syncable::WriteTransaction* write_transaction() { return write_transaction_; } 155 syncable::WriteTransaction* write_transaction() { return write_transaction_; }
144 const StatusController& status_controller() const { 156 const StatusController& status_controller() const {
(...skipping 13 matching lines...) Expand all
158 const std::vector<ModelSafeWorker*>& workers() const { return workers_; } 170 const std::vector<ModelSafeWorker*>& workers() const { return workers_; }
159 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; } 171 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; }
160 const SyncSourceInfo& source() const { return source_; } 172 const SyncSourceInfo& source() const { return source_; }
161 173
162 // Returns the set of groups which have enabled types. 174 // Returns the set of groups which have enabled types.
163 const std::set<ModelSafeGroup>& GetEnabledGroups() const; 175 const std::set<ModelSafeGroup>& GetEnabledGroups() const;
164 176
165 // Returns the set of enabled groups that have conflicts. 177 // Returns the set of enabled groups that have conflicts.
166 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const; 178 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const;
167 179
180 // Mark the session has having finished all the sync steps it needed.
181 void SetFinished();
182
168 private: 183 private:
169 // Extend the encapsulation boundary to utilities for internal member 184 // Extend the encapsulation boundary to utilities for internal member
170 // assignments. This way, the scope of these actions is explicit, they can't 185 // assignments. This way, the scope of these actions is explicit, they can't
171 // be overridden, and assigning is always accompanied by unassigning. 186 // be overridden, and assigning is always accompanied by unassigning.
172 friend class ScopedSetSessionWriteTransaction; 187 friend class ScopedSetSessionWriteTransaction;
173 188
174 // The context for this session, guaranteed to outlive |this|. 189 // The context for this session, guaranteed to outlive |this|.
175 SyncSessionContext* const context_; 190 SyncSessionContext* const context_;
176 191
177 // The source for initiating this sync session. 192 // The source for initiating this sync session.
(...skipping 17 matching lines...) Expand all
195 210
196 // The routing info for the duration of this session, dictating which 211 // The routing info for the duration of this session, dictating which
197 // datatypes should be synced and which workers should be used when working 212 // datatypes should be synced and which workers should be used when working
198 // on those datatypes. 213 // on those datatypes.
199 ModelSafeRoutingInfo routing_info_; 214 ModelSafeRoutingInfo routing_info_;
200 215
201 // The set of groups with enabled types. Computed from 216 // The set of groups with enabled types. Computed from
202 // |routing_info_|. 217 // |routing_info_|.
203 std::set<ModelSafeGroup> enabled_groups_; 218 std::set<ModelSafeGroup> enabled_groups_;
204 219
220 // Whether this session has reached its last step or not. Gets reset on each
221 // new cycle (via PrepareForAnotherSyncCycle).
222 bool finished_;
223
205 DISALLOW_COPY_AND_ASSIGN(SyncSession); 224 DISALLOW_COPY_AND_ASSIGN(SyncSession);
206 }; 225 };
207 226
208 // Installs a WriteTransaction to a given session and later clears it when the 227 // Installs a WriteTransaction to a given session and later clears it when the
209 // utility falls out of scope. Transactions are not nestable, so it is an error 228 // utility falls out of scope. Transactions are not nestable, so it is an error
210 // to try and use one of these if the session already has a transaction. 229 // to try and use one of these if the session already has a transaction.
211 class ScopedSetSessionWriteTransaction { 230 class ScopedSetSessionWriteTransaction {
212 public: 231 public:
213 ScopedSetSessionWriteTransaction(SyncSession* session, 232 ScopedSetSessionWriteTransaction(SyncSession* session,
214 syncable::WriteTransaction* trans) 233 syncable::WriteTransaction* trans)
215 : session_(session) { 234 : session_(session) {
216 DCHECK(!session_->write_transaction_); 235 DCHECK(!session_->write_transaction_);
217 session_->write_transaction_ = trans; 236 session_->write_transaction_ = trans;
218 } 237 }
219 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } 238 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; }
220 239
221 private: 240 private:
222 SyncSession* session_; 241 SyncSession* session_;
223 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); 242 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction);
224 }; 243 };
225 244
226 } // namespace sessions 245 } // namespace sessions
227 } // namespace syncer 246 } // namespace syncer
228 247
229 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ 248 #endif // SYNC_SESSIONS_SYNC_SESSION_H_
OLDNEW
« no previous file with comments | « sync/sessions/session_state_unittest.cc ('k') | sync/sessions/sync_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698