| 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 <string> | 19 #include <string> |
| 20 #include <utility> | 20 #include <utility> |
| 21 #include <vector> | 21 #include <vector> |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
| 25 #include "base/location.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" |
| 29 #include "chrome/browser/sync/sessions/status_controller.h" | 30 #include "chrome/browser/sync/sessions/status_controller.h" |
| 30 #include "chrome/browser/sync/sessions/sync_session_context.h" | 31 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 32 #include "chrome/browser/sync/sessions/unrecoverable_error_info.h" |
| 31 #include "chrome/browser/sync/syncable/model_type.h" | 33 #include "chrome/browser/sync/syncable/model_type.h" |
| 32 #include "chrome/browser/sync/util/extensions_activity_monitor.h" | 34 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
| 33 | 35 |
| 34 namespace syncable { | 36 namespace syncable { |
| 35 class WriteTransaction; | 37 class WriteTransaction; |
| 36 } | 38 } |
| 37 | 39 |
| 38 namespace browser_sync { | 40 namespace browser_sync { |
| 39 class ModelSafeWorker; | 41 class ModelSafeWorker; |
| 40 | 42 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // stops the current sync cycle and purges the client. In the new model | 85 // stops the current sync cycle and purges the client. In the new model |
| 84 // the former would be done by the |SyncProtocolError| and | 86 // the former would be done by the |SyncProtocolError| and |
| 85 // the latter(which is an action) would be done in ProfileSyncService | 87 // the latter(which is an action) would be done in ProfileSyncService |
| 86 // along with the rest of the actions. | 88 // along with the rest of the actions. |
| 87 virtual void OnShouldStopSyncingPermanently() = 0; | 89 virtual void OnShouldStopSyncingPermanently() = 0; |
| 88 | 90 |
| 89 // Called for the syncer to respond to the error sent by the server. | 91 // Called for the syncer to respond to the error sent by the server. |
| 90 virtual void OnSyncProtocolError( | 92 virtual void OnSyncProtocolError( |
| 91 const sessions::SyncSessionSnapshot& snapshot) = 0; | 93 const sessions::SyncSessionSnapshot& snapshot) = 0; |
| 92 | 94 |
| 95 // Called when the syncer encounters an unrecoverable error. |
| 96 virtual void OnUnrecoverableError( |
| 97 const tracked_objects::Location& from_here, |
| 98 const std::string& message) = 0; |
| 99 |
| 93 protected: | 100 protected: |
| 94 virtual ~Delegate() {} | 101 virtual ~Delegate() {} |
| 95 }; | 102 }; |
| 96 | 103 |
| 97 SyncSession(SyncSessionContext* context, | 104 SyncSession(SyncSessionContext* context, |
| 98 Delegate* delegate, | 105 Delegate* delegate, |
| 99 const SyncSourceInfo& source, | 106 const SyncSourceInfo& source, |
| 100 const ModelSafeRoutingInfo& routing_info, | 107 const ModelSafeRoutingInfo& routing_info, |
| 101 const std::vector<ModelSafeWorker*>& workers); | 108 const std::vector<ModelSafeWorker*>& workers); |
| 102 ~SyncSession(); | 109 ~SyncSession(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 146 |
| 140 // 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 |
| 141 // 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 |
| 142 // been read. | 149 // been read. |
| 143 SyncSourceInfo TestAndSetSource(); | 150 SyncSourceInfo TestAndSetSource(); |
| 144 | 151 |
| 145 const std::vector<ModelSafeWorker*>& workers() const { return workers_; } | 152 const std::vector<ModelSafeWorker*>& workers() const { return workers_; } |
| 146 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; } | 153 const ModelSafeRoutingInfo& routing_info() const { return routing_info_; } |
| 147 const SyncSourceInfo& source() const { return source_; } | 154 const SyncSourceInfo& source() const { return source_; } |
| 148 | 155 |
| 156 // This can be called from any thread. We just cache the value of |
| 157 // unrecoverable error info. When on the correct thread using this info |
| 158 // delegate's OnUnrecoverableError method should be called. |
| 159 void SetUnrecoverableError(const tracked_objects::Location& location, |
| 160 const std::string& message, |
| 161 syncable::BaseTransaction* trans); |
| 162 |
| 163 bool unrecoverable_error() const { return unrecoverable_error_; } |
| 164 UnrecoverableErrorInfo* unrecoverable_error_info() { |
| 165 return unrecoverable_error_info_.get(); |
| 166 } |
| 167 |
| 149 private: | 168 private: |
| 150 // Extend the encapsulation boundary to utilities for internal member | 169 // Extend the encapsulation boundary to utilities for internal member |
| 151 // 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 |
| 152 // be overridden, and assigning is always accompanied by unassigning. | 171 // be overridden, and assigning is always accompanied by unassigning. |
| 153 friend class ScopedSetSessionWriteTransaction; | 172 friend class ScopedSetSessionWriteTransaction; |
| 154 | 173 |
| 155 // The context for this session, guaranteed to outlive |this|. | 174 // The context for this session, guaranteed to outlive |this|. |
| 156 SyncSessionContext* const context_; | 175 SyncSessionContext* const context_; |
| 157 | 176 |
| 158 // The source for initiating this sync session. | 177 // The source for initiating this sync session. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 172 | 191 |
| 173 // The set of active ModelSafeWorkers for the duration of this session. | 192 // The set of active ModelSafeWorkers for the duration of this session. |
| 174 // This can change if this session is Coalesce()'d with another. | 193 // This can change if this session is Coalesce()'d with another. |
| 175 std::vector<ModelSafeWorker*> workers_; | 194 std::vector<ModelSafeWorker*> workers_; |
| 176 | 195 |
| 177 // The routing info for the duration of this session, dictating which | 196 // The routing info for the duration of this session, dictating which |
| 178 // 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 |
| 179 // on those datatypes. | 198 // on those datatypes. |
| 180 ModelSafeRoutingInfo routing_info_; | 199 ModelSafeRoutingInfo routing_info_; |
| 181 | 200 |
| 201 scoped_ptr<UnrecoverableErrorInfo> unrecoverable_error_info_; |
| 202 bool unrecoverable_error_; |
| 203 |
| 182 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 204 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 183 }; | 205 }; |
| 184 | 206 |
| 185 // Installs a WriteTransaction to a given session and later clears it when the | 207 // Installs a WriteTransaction to a given session and later clears it when the |
| 186 // utility falls out of scope. Transactions are not nestable, so it is an error | 208 // utility falls out of scope. Transactions are not nestable, so it is an error |
| 187 // to try and use one of these if the session already has a transaction. | 209 // to try and use one of these if the session already has a transaction. |
| 188 class ScopedSetSessionWriteTransaction { | 210 class ScopedSetSessionWriteTransaction { |
| 189 public: | 211 public: |
| 190 ScopedSetSessionWriteTransaction(SyncSession* session, | 212 ScopedSetSessionWriteTransaction(SyncSession* session, |
| 191 syncable::WriteTransaction* trans) | 213 syncable::WriteTransaction* trans) |
| 192 : session_(session) { | 214 : session_(session) { |
| 193 DCHECK(!session_->write_transaction_); | 215 DCHECK(!session_->write_transaction_); |
| 194 session_->write_transaction_ = trans; | 216 session_->write_transaction_ = trans; |
| 195 } | 217 } |
| 196 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 218 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
| 197 | 219 |
| 198 private: | 220 private: |
| 199 SyncSession* session_; | 221 SyncSession* session_; |
| 200 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 222 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
| 201 }; | 223 }; |
| 202 | 224 |
| 203 } // namespace sessions | 225 } // namespace sessions |
| 204 } // namespace browser_sync | 226 } // namespace browser_sync |
| 205 | 227 |
| 206 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 228 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |