| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/sync/util/extensions_activity_monitor.h" | 28 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
| 29 | 29 |
| 30 namespace syncable { | 30 namespace syncable { |
| 31 class WriteTransaction; | 31 class WriteTransaction; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace browser_sync { | 34 namespace browser_sync { |
| 35 class ModelSafeWorker; | 35 class ModelSafeWorker; |
| 36 | 36 |
| 37 namespace sessions { | 37 namespace sessions { |
| 38 typedef std::pair<sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, | |
| 39 syncable::ModelTypeBitSet> SyncSourceInfo; | |
| 40 | 38 |
| 41 class SyncSession { | 39 class SyncSession { |
| 42 public: | 40 public: |
| 43 // The Delegate services events that occur during the session requiring an | 41 // The Delegate services events that occur during the session requiring an |
| 44 // explicit (and session-global) action, as opposed to events that are simply | 42 // explicit (and session-global) action, as opposed to events that are simply |
| 45 // recorded in per-session state. | 43 // recorded in per-session state. |
| 46 class Delegate { | 44 class Delegate { |
| 47 public: | 45 public: |
| 48 // The client was throttled and should cease-and-desist syncing activity | 46 // The client was throttled and should cease-and-desist syncing activity |
| 49 // until the specified time. | 47 // until the specified time. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const std::vector<ModelSafeWorker*>& workers); | 83 const std::vector<ModelSafeWorker*>& workers); |
| 86 ~SyncSession(); | 84 ~SyncSession(); |
| 87 | 85 |
| 88 // Builds a thread-safe and read-only copy of the current session state. | 86 // Builds a thread-safe and read-only copy of the current session state. |
| 89 SyncSessionSnapshot TakeSnapshot() const; | 87 SyncSessionSnapshot TakeSnapshot() const; |
| 90 | 88 |
| 91 // Returns true if this session contains data that should go through the sync | 89 // Returns true if this session contains data that should go through the sync |
| 92 // engine again. | 90 // engine again. |
| 93 bool HasMoreToSync() const; | 91 bool HasMoreToSync() const; |
| 94 | 92 |
| 95 SyncSessionContext* context() { return context_; } | 93 // Collects all state pertaining to how and why |s| originated and unions it |
| 96 Delegate* delegate() { return delegate_; } | 94 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| |
| 95 // to take on the responsibilities |s| had (e.g. certain data types) in the |
| 96 // next SyncShare operation using |this|, rather than needed two separate |
| 97 // sessions. |
| 98 void Coalesce(const SyncSession& session); |
| 99 |
| 100 // Should be called any time |this| is being re-used in a new call to |
| 101 // SyncShare (e.g., HasMoreToSync returned true). |
| 102 void ResetTransientState(); |
| 103 |
| 104 SyncSessionContext* context() const { return context_; } |
| 105 Delegate* delegate() const { return delegate_; } |
| 97 syncable::WriteTransaction* write_transaction() { return write_transaction_; } | 106 syncable::WriteTransaction* write_transaction() { return write_transaction_; } |
| 98 StatusController* status_controller() { return status_controller_.get(); } | 107 StatusController* status_controller() { return status_controller_.get(); } |
| 99 | 108 |
| 100 const ExtensionsActivityMonitor::Records& extensions_activity() const { | 109 const ExtensionsActivityMonitor::Records& extensions_activity() const { |
| 101 return extensions_activity_; | 110 return extensions_activity_; |
| 102 } | 111 } |
| 103 ExtensionsActivityMonitor::Records* mutable_extensions_activity() { | 112 ExtensionsActivityMonitor::Records* mutable_extensions_activity() { |
| 104 return &extensions_activity_; | 113 return &extensions_activity_; |
| 105 } | 114 } |
| 106 | 115 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 131 // Used to allow various steps to share a transaction. Can be NULL. | 140 // Used to allow various steps to share a transaction. Can be NULL. |
| 132 syncable::WriteTransaction* write_transaction_; | 141 syncable::WriteTransaction* write_transaction_; |
| 133 | 142 |
| 134 // The delegate for this session, must never be NULL. | 143 // The delegate for this session, must never be NULL. |
| 135 Delegate* delegate_; | 144 Delegate* delegate_; |
| 136 | 145 |
| 137 // Our controller for various status and error counters. | 146 // Our controller for various status and error counters. |
| 138 scoped_ptr<StatusController> status_controller_; | 147 scoped_ptr<StatusController> status_controller_; |
| 139 | 148 |
| 140 // The set of active ModelSafeWorkers for the duration of this session. | 149 // The set of active ModelSafeWorkers for the duration of this session. |
| 141 const std::vector<ModelSafeWorker*> workers_; | 150 // This can change if this session is Coalesce()'d with another. |
| 151 std::vector<ModelSafeWorker*> workers_; |
| 142 | 152 |
| 143 // The routing info for the duration of this session, dictating which | 153 // The routing info for the duration of this session, dictating which |
| 144 // datatypes should be synced and which workers should be used when working | 154 // datatypes should be synced and which workers should be used when working |
| 145 // on those datatypes. | 155 // on those datatypes. |
| 146 const ModelSafeRoutingInfo routing_info_; | 156 ModelSafeRoutingInfo routing_info_; |
| 147 | 157 |
| 148 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 158 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 149 }; | 159 }; |
| 150 | 160 |
| 151 // Installs a WriteTransaction to a given session and later clears it when the | 161 // Installs a WriteTransaction to a given session and later clears it when the |
| 152 // utility falls out of scope. Transactions are not nestable, so it is an error | 162 // utility falls out of scope. Transactions are not nestable, so it is an error |
| 153 // to try and use one of these if the session already has a transaction. | 163 // to try and use one of these if the session already has a transaction. |
| 154 class ScopedSetSessionWriteTransaction { | 164 class ScopedSetSessionWriteTransaction { |
| 155 public: | 165 public: |
| 156 ScopedSetSessionWriteTransaction(SyncSession* session, | 166 ScopedSetSessionWriteTransaction(SyncSession* session, |
| 157 syncable::WriteTransaction* trans) | 167 syncable::WriteTransaction* trans) |
| 158 : session_(session) { | 168 : session_(session) { |
| 159 DCHECK(!session_->write_transaction_); | 169 DCHECK(!session_->write_transaction_); |
| 160 session_->write_transaction_ = trans; | 170 session_->write_transaction_ = trans; |
| 161 } | 171 } |
| 162 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 172 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
| 163 | 173 |
| 164 private: | 174 private: |
| 165 SyncSession* session_; | 175 SyncSession* session_; |
| 166 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 176 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
| 167 }; | 177 }; |
| 168 | 178 |
| 169 } // namespace sessions | 179 } // namespace sessions |
| 170 } // namespace browser_sync | 180 } // namespace browser_sync |
| 171 | 181 |
| 172 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 182 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |