| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| 155 private: | 162 private: |
| 156 // Extend the encapsulation boundary to utilities for internal member | 163 // Extend the encapsulation boundary to utilities for internal member |
| 157 // assignments. This way, the scope of these actions is explicit, they can't | 164 // assignments. This way, the scope of these actions is explicit, they can't |
| 158 // be overridden, and assigning is always accompanied by unassigning. | 165 // be overridden, and assigning is always accompanied by unassigning. |
| 159 friend class ScopedSetSessionWriteTransaction; | 166 friend class ScopedSetSessionWriteTransaction; |
| 160 | 167 |
| 161 // The context for this session, guaranteed to outlive |this|. | 168 // The context for this session, guaranteed to outlive |this|. |
| 162 SyncSessionContext* const context_; | 169 SyncSessionContext* const context_; |
| 163 | 170 |
| 164 // The source for initiating this sync session. | 171 // The source for initiating this sync session. |
| 165 SyncSourceInfo source_; | 172 SyncSourceInfo source_; |
| 166 | 173 |
| 167 // Information about extensions activity since the last successful commit. | 174 // Information about extensions activity since the last successful commit. |
| 168 ExtensionsActivityMonitor::Records extensions_activity_; | 175 ExtensionsActivityMonitor::Records extensions_activity_; |
| 169 | 176 |
| 170 // Used to allow various steps to share a transaction. Can be NULL. | 177 // Used to allow various steps to share a transaction. Can be NULL. |
| 171 syncable::WriteTransaction* write_transaction_; | 178 syncable::WriteTransaction* write_transaction_; |
| 172 | 179 |
| 173 // The delegate for this session, must never be NULL. | 180 // The delegate for this session, must never be NULL. |
| 174 Delegate* delegate_; | 181 Delegate* const delegate_; |
| 175 | 182 |
| 176 // Our controller for various status and error counters. | 183 // Our controller for various status and error counters. |
| 177 scoped_ptr<StatusController> status_controller_; | 184 scoped_ptr<StatusController> status_controller_; |
| 178 | 185 |
| 179 // The set of active ModelSafeWorkers for the duration of this session. | 186 // The set of active ModelSafeWorkers for the duration of this session. |
| 180 // This can change if this session is Coalesce()'d with another. | 187 // This can change if this session is Coalesce()'d with another. |
| 181 std::vector<ModelSafeWorker*> workers_; | 188 std::vector<ModelSafeWorker*> workers_; |
| 182 | 189 |
| 183 // The routing info for the duration of this session, dictating which | 190 // The routing info for the duration of this session, dictating which |
| 184 // datatypes should be synced and which workers should be used when working | 191 // datatypes should be synced and which workers should be used when working |
| 185 // on those datatypes. | 192 // on those datatypes. |
| 186 ModelSafeRoutingInfo routing_info_; | 193 ModelSafeRoutingInfo routing_info_; |
| 187 | 194 |
| 195 // The set of groups with enabled types. Computed from |
| 196 // |routing_info_|. |
| 197 std::set<ModelSafeGroup> enabled_groups_; |
| 198 |
| 188 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 199 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 189 }; | 200 }; |
| 190 | 201 |
| 191 // Installs a WriteTransaction to a given session and later clears it when the | 202 // 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 | 203 // 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. | 204 // to try and use one of these if the session already has a transaction. |
| 194 class ScopedSetSessionWriteTransaction { | 205 class ScopedSetSessionWriteTransaction { |
| 195 public: | 206 public: |
| 196 ScopedSetSessionWriteTransaction(SyncSession* session, | 207 ScopedSetSessionWriteTransaction(SyncSession* session, |
| 197 syncable::WriteTransaction* trans) | 208 syncable::WriteTransaction* trans) |
| 198 : session_(session) { | 209 : session_(session) { |
| 199 DCHECK(!session_->write_transaction_); | 210 DCHECK(!session_->write_transaction_); |
| 200 session_->write_transaction_ = trans; | 211 session_->write_transaction_ = trans; |
| 201 } | 212 } |
| 202 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 213 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
| 203 | 214 |
| 204 private: | 215 private: |
| 205 SyncSession* session_; | 216 SyncSession* session_; |
| 206 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 217 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
| 207 }; | 218 }; |
| 208 | 219 |
| 209 } // namespace sessions | 220 } // namespace sessions |
| 210 } // namespace browser_sync | 221 } // namespace browser_sync |
| 211 | 222 |
| 212 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 223 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |