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

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

Issue 8771044: Revert 112743 - [Sync] Make syncer commands avoid posting tasks on threads with no work to do (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
11 // server updates, and access the SyncSessionContext for the current session 11 // server updates, and access the SyncSessionContext for the current session
12 // via SyncSession instances. 12 // via SyncSession instances.
13 13
14 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ 14 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_
15 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ 15 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_
16 #pragma once 16 #pragma once
17 17
18 #include <map> 18 #include <map>
19 #include <set>
20 #include <string> 19 #include <string>
21 #include <utility> 20 #include <utility>
22 #include <vector> 21 #include <vector>
23 22
24 #include "base/basictypes.h" 23 #include "base/basictypes.h"
25 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
26 #include "base/time.h" 25 #include "base/time.h"
27 #include "chrome/browser/sync/engine/model_safe_worker.h" 26 #include "chrome/browser/sync/engine/model_safe_worker.h"
28 #include "chrome/browser/sync/sessions/ordered_commit_set.h" 27 #include "chrome/browser/sync/sessions/ordered_commit_set.h"
29 #include "chrome/browser/sync/sessions/session_state.h" 28 #include "chrome/browser/sync/sessions/session_state.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| 112 // with corresponding state in |this|, leaving |s| unchanged. Allows |this|
114 // to take on the responsibilities |s| had (e.g. certain data types) in the 113 // to take on the responsibilities |s| had (e.g. certain data types) in the
115 // next SyncShare operation using |this|, rather than needed two separate 114 // next SyncShare operation using |this|, rather than needed two separate
116 // sessions. 115 // sessions.
117 void Coalesce(const SyncSession& session); 116 void Coalesce(const SyncSession& session);
118 117
119 // Compares the routing_info_, workers and payload map with the passed in 118 // Compares the routing_info_, workers and payload map with the passed in
120 // session. Purges types from the above 3 which are not in session. Useful 119 // session. Purges types from the above 3 which are not in session. Useful
121 // to update the sync session when the user has disabled some types from 120 // to update the sync session when the user has disabled some types from
122 // syncing. 121 // syncing.
123 void RebaseRoutingInfoWithLatest(const SyncSession& session); 122 void RebaseRoutingInfoWithLatest(SyncSession* session);
124 123
125 // Should be called any time |this| is being re-used in a new call to 124 // Should be called any time |this| is being re-used in a new call to
126 // SyncShare (e.g., HasMoreToSync returned true). 125 // SyncShare (e.g., HasMoreToSync returned true).
127 void ResetTransientState(); 126 void ResetTransientState();
128 127
129 // TODO(akalin): Split this into context() and mutable_context(). 128 // TODO(akalin): Split this into context() and mutable_context().
130 SyncSessionContext* context() const { return context_; } 129 SyncSessionContext* context() const { return context_; }
131 Delegate* delegate() const { return delegate_; } 130 Delegate* delegate() const { return delegate_; }
132 syncable::WriteTransaction* write_transaction() { return write_transaction_; } 131 syncable::WriteTransaction* write_transaction() { return write_transaction_; }
133 const StatusController& status_controller() const { 132 const StatusController& status_controller() const {
(...skipping 12 matching lines...) Expand all
146 145
147 // Volatile reader for the source member of the sync session object. The 146 // Volatile reader for the source member of the sync session object. The
148 // value is set to the SYNC_CYCLE_CONTINUATION value to signal that it has 147 // value is set to the SYNC_CYCLE_CONTINUATION value to signal that it has
149 // been read. 148 // been read.
150 SyncSourceInfo TestAndSetSource(); 149 SyncSourceInfo TestAndSetSource();
151 150
152 const std::vector<ModelSafeWorker*>& workers() const { return workers_; } 151 const std::vector<ModelSafeWorker*>& workers() const { return workers_; }
153 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; } 152 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; }
154 const SyncSourceInfo& source() const { return source_; } 153 const SyncSourceInfo& source() const { return source_; }
155 154
156 // Returns the set of groups which have enabled types.
157 const std::set<ModelSafeGroup>& GetEnabledGroups() const;
158
159 // Returns the set of enabled groups that have conflicts.
160 std::set<ModelSafeGroup> GetEnabledGroupsWithConflicts() const;
161
162 // Returns the set of enabled groups that have verified updates.
163 std::set<ModelSafeGroup> GetEnabledGroupsWithVerifiedUpdates() const;
164
165 private: 155 private:
166 // Extend the encapsulation boundary to utilities for internal member 156 // Extend the encapsulation boundary to utilities for internal member
167 // assignments. This way, the scope of these actions is explicit, they can't 157 // assignments. This way, the scope of these actions is explicit, they can't
168 // be overridden, and assigning is always accompanied by unassigning. 158 // be overridden, and assigning is always accompanied by unassigning.
169 friend class ScopedSetSessionWriteTransaction; 159 friend class ScopedSetSessionWriteTransaction;
170 160
171 // The context for this session, guaranteed to outlive |this|. 161 // The context for this session, guaranteed to outlive |this|.
172 SyncSessionContext* const context_; 162 SyncSessionContext* const context_;
173 163
174 // The source for initiating this sync session. 164 // The source for initiating this sync session.
175 SyncSourceInfo source_; 165 SyncSourceInfo source_;
176 166
177 // Information about extensions activity since the last successful commit. 167 // Information about extensions activity since the last successful commit.
178 ExtensionsActivityMonitor::Records extensions_activity_; 168 ExtensionsActivityMonitor::Records extensions_activity_;
179 169
180 // Used to allow various steps to share a transaction. Can be NULL. 170 // Used to allow various steps to share a transaction. Can be NULL.
181 syncable::WriteTransaction* write_transaction_; 171 syncable::WriteTransaction* write_transaction_;
182 172
183 // The delegate for this session, must never be NULL. 173 // The delegate for this session, must never be NULL.
184 Delegate* const delegate_; 174 Delegate* delegate_;
185 175
186 // Our controller for various status and error counters. 176 // Our controller for various status and error counters.
187 scoped_ptr<StatusController> status_controller_; 177 scoped_ptr<StatusController> status_controller_;
188 178
189 // The set of active ModelSafeWorkers for the duration of this session. 179 // The set of active ModelSafeWorkers for the duration of this session.
190 // This can change if this session is Coalesce()'d with another. 180 // This can change if this session is Coalesce()'d with another.
191 std::vector<ModelSafeWorker*> workers_; 181 std::vector<ModelSafeWorker*> workers_;
192 182
193 // The routing info for the duration of this session, dictating which 183 // The routing info for the duration of this session, dictating which
194 // datatypes should be synced and which workers should be used when working 184 // datatypes should be synced and which workers should be used when working
195 // on those datatypes. 185 // on those datatypes.
196 ModelSafeRoutingInfo routing_info_; 186 ModelSafeRoutingInfo routing_info_;
197 187
198 // The set of groups with enabled types. Computed from
199 // |routing_info_|.
200 std::set<ModelSafeGroup> enabled_groups_;
201
202 DISALLOW_COPY_AND_ASSIGN(SyncSession); 188 DISALLOW_COPY_AND_ASSIGN(SyncSession);
203 }; 189 };
204 190
205 // Installs a WriteTransaction to a given session and later clears it when the 191 // Installs a WriteTransaction to a given session and later clears it when the
206 // utility falls out of scope. Transactions are not nestable, so it is an error 192 // utility falls out of scope. Transactions are not nestable, so it is an error
207 // to try and use one of these if the session already has a transaction. 193 // to try and use one of these if the session already has a transaction.
208 class ScopedSetSessionWriteTransaction { 194 class ScopedSetSessionWriteTransaction {
209 public: 195 public:
210 ScopedSetSessionWriteTransaction(SyncSession* session, 196 ScopedSetSessionWriteTransaction(SyncSession* session,
211 syncable::WriteTransaction* trans) 197 syncable::WriteTransaction* trans)
212 : session_(session) { 198 : session_(session) {
213 DCHECK(!session_->write_transaction_); 199 DCHECK(!session_->write_transaction_);
214 session_->write_transaction_ = trans; 200 session_->write_transaction_ = trans;
215 } 201 }
216 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } 202 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; }
217 203
218 private: 204 private:
219 SyncSession* session_; 205 SyncSession* session_;
220 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); 206 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction);
221 }; 207 };
222 208
223 } // namespace sessions 209 } // namespace sessions
224 } // namespace browser_sync 210 } // namespace browser_sync
225 211
226 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ 212 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/status_controller.cc ('k') | chrome/browser/sync/sessions/sync_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698