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

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

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