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

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

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: eof 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 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 13 matching lines...) Expand all
170 const std::vector<ModelSafeWorker*>& workers() const { return workers_; } 158 const std::vector<ModelSafeWorker*>& workers() const { return workers_; }
171 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; } 159 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; }
172 const SyncSourceInfo& source() const { return source_; } 160 const SyncSourceInfo& source() const { return source_; }
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 // Mark the session has having finished all the sync steps it needed.
181 void SetFinished();
182
183 private: 168 private:
184 // Extend the encapsulation boundary to utilities for internal member 169 // Extend the encapsulation boundary to utilities for internal member
185 // assignments. This way, the scope of these actions is explicit, they can't 170 // assignments. This way, the scope of these actions is explicit, they can't
186 // be overridden, and assigning is always accompanied by unassigning. 171 // be overridden, and assigning is always accompanied by unassigning.
187 friend class ScopedSetSessionWriteTransaction; 172 friend class ScopedSetSessionWriteTransaction;
188 173
189 // The context for this session, guaranteed to outlive |this|. 174 // The context for this session, guaranteed to outlive |this|.
190 SyncSessionContext* const context_; 175 SyncSessionContext* const context_;
191 176
192 // The source for initiating this sync session. 177 // The source for initiating this sync session.
(...skipping 17 matching lines...) Expand all
210 195
211 // The routing info for the duration of this session, dictating which 196 // The routing info for the duration of this session, dictating which
212 // datatypes should be synced and which workers should be used when working 197 // datatypes should be synced and which workers should be used when working
213 // on those datatypes. 198 // on those datatypes.
214 ModelSafeRoutingInfo routing_info_; 199 ModelSafeRoutingInfo routing_info_;
215 200
216 // The set of groups with enabled types. Computed from 201 // The set of groups with enabled types. Computed from
217 // |routing_info_|. 202 // |routing_info_|.
218 std::set<ModelSafeGroup> enabled_groups_; 203 std::set<ModelSafeGroup> enabled_groups_;
219 204
220 // Whether this session has reached its last step or not. Gets reset on each
221 // new cycle (via PrepareForAnotherSyncCycle).
222 bool finished_;
223
224 DISALLOW_COPY_AND_ASSIGN(SyncSession); 205 DISALLOW_COPY_AND_ASSIGN(SyncSession);
225 }; 206 };
226 207
227 // Installs a WriteTransaction to a given session and later clears it when the 208 // Installs a WriteTransaction to a given session and later clears it when the
228 // utility falls out of scope. Transactions are not nestable, so it is an error 209 // utility falls out of scope. Transactions are not nestable, so it is an error
229 // to try and use one of these if the session already has a transaction. 210 // to try and use one of these if the session already has a transaction.
230 class ScopedSetSessionWriteTransaction { 211 class ScopedSetSessionWriteTransaction {
231 public: 212 public:
232 ScopedSetSessionWriteTransaction(SyncSession* session, 213 ScopedSetSessionWriteTransaction(SyncSession* session,
233 syncable::WriteTransaction* trans) 214 syncable::WriteTransaction* trans)
234 : session_(session) { 215 : session_(session) {
235 DCHECK(!session_->write_transaction_); 216 DCHECK(!session_->write_transaction_);
236 session_->write_transaction_ = trans; 217 session_->write_transaction_ = trans;
237 } 218 }
238 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } 219 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; }
239 220
240 private: 221 private:
241 SyncSession* session_; 222 SyncSession* session_;
242 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); 223 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction);
243 }; 224 };
244 225
245 } // namespace sessions 226 } // namespace sessions
246 } // namespace syncer 227 } // namespace syncer
247 228
248 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ 229 #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