| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 16 |
| 17 #include <string> | 17 #include <string> |
| 18 #include <vector> |
| 18 | 19 |
| 19 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 20 #include "base/scoped_ptr.h" | 21 #include "base/scoped_ptr.h" |
| 21 #include "base/time.h" | 22 #include "base/time.h" |
| 22 #include "chrome/browser/sync/sessions/session_state.h" | 23 #include "chrome/browser/sync/sessions/session_state.h" |
| 23 #include "chrome/browser/sync/sessions/status_controller.h" | 24 #include "chrome/browser/sync/sessions/status_controller.h" |
| 24 #include "chrome/browser/sync/sessions/sync_session_context.h" | 25 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 25 #include "chrome/browser/sync/util/extensions_activity_monitor.h" | 26 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
| 26 | 27 |
| 27 namespace syncable { | 28 namespace syncable { |
| 28 class WriteTransaction; | 29 class WriteTransaction; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace browser_sync { | 32 namespace browser_sync { |
| 33 class ModelSafeWorker; |
| 34 |
| 32 namespace sessions { | 35 namespace sessions { |
| 33 | 36 |
| 34 class SyncSession { | 37 class SyncSession { |
| 35 public: | 38 public: |
| 36 // The Delegate services events that occur during the session requiring an | 39 // The Delegate services events that occur during the session requiring an |
| 37 // explicit (and session-global) action, as opposed to events that are simply | 40 // explicit (and session-global) action, as opposed to events that are simply |
| 38 // recorded in per-session state. | 41 // recorded in per-session state. |
| 39 class Delegate { | 42 class Delegate { |
| 40 public: | 43 public: |
| 41 // The client was throttled and should cease-and-desist syncing activity | 44 // The client was throttled and should cease-and-desist syncing activity |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void clear_auth_failure_occurred() { auth_failure_occurred_ = false; } | 95 void clear_auth_failure_occurred() { auth_failure_occurred_ = false; } |
| 93 | 96 |
| 94 // Volatile reader for the source member of the sync session object. The | 97 // Volatile reader for the source member of the sync session object. The |
| 95 // value is set to the SYNC_CYCLE_CONTINUATION value to signal that it has | 98 // value is set to the SYNC_CYCLE_CONTINUATION value to signal that it has |
| 96 // been read. | 99 // been read. |
| 97 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource TestAndSetSource(); | 100 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource TestAndSetSource(); |
| 98 void set_source(sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { | 101 void set_source(sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source) { |
| 99 source_ = source; | 102 source_ = source; |
| 100 } | 103 } |
| 101 | 104 |
| 105 const std::vector<ModelSafeWorker*>& workers() const { return workers_; } |
| 106 |
| 102 private: | 107 private: |
| 103 // Extend the encapsulation boundary to utilities for internal member | 108 // Extend the encapsulation boundary to utilities for internal member |
| 104 // assignments. This way, the scope of these actions is explicit, they can't | 109 // assignments. This way, the scope of these actions is explicit, they can't |
| 105 // be overridden, and assigning is always accompanied by unassigning. | 110 // be overridden, and assigning is always accompanied by unassigning. |
| 106 friend class ScopedSetSessionWriteTransaction; | 111 friend class ScopedSetSessionWriteTransaction; |
| 112 friend class ScopedModelSafeGroupRestriction; |
| 107 | 113 |
| 108 // The context for this session, guaranteed to outlive |this|. | 114 // The context for this session, guaranteed to outlive |this|. |
| 109 SyncSessionContext* const context_; | 115 SyncSessionContext* const context_; |
| 110 | 116 |
| 111 // The source for initiating this sync session. | 117 // The source for initiating this sync session. |
| 112 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source_; | 118 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source_; |
| 113 | 119 |
| 114 // Information about extensions activity since the last successful commit. | 120 // Information about extensions activity since the last successful commit. |
| 115 ExtensionsActivityMonitor::Records extensions_activity_; | 121 ExtensionsActivityMonitor::Records extensions_activity_; |
| 116 | 122 |
| 117 // Used to allow various steps to share a transaction. Can be NULL. | 123 // Used to allow various steps to share a transaction. Can be NULL. |
| 118 syncable::WriteTransaction* write_transaction_; | 124 syncable::WriteTransaction* write_transaction_; |
| 119 | 125 |
| 120 // The delegate for this session, must never be NULL. | 126 // The delegate for this session, must never be NULL. |
| 121 Delegate* delegate_; | 127 Delegate* delegate_; |
| 122 | 128 |
| 123 // Our controller for various status and error counters. | 129 // Our controller for various status and error counters. |
| 124 StatusController status_controller_; | 130 StatusController status_controller_; |
| 125 | 131 |
| 126 // Used to determine if an auth error notification should be sent out. | 132 // Used to determine if an auth error notification should be sent out. |
| 127 bool auth_failure_occurred_; | 133 bool auth_failure_occurred_; |
| 128 | 134 |
| 135 // The set of active ModelSafeWorkers for the duration of this session. |
| 136 const std::vector<ModelSafeWorker*> workers_; |
| 137 |
| 138 // Used to fail read/write operations on this SyncSession that don't obey the |
| 139 // currently active ModelSafeWorker contract. |
| 140 bool group_restriction_in_effect_; |
| 141 ModelSafeGroup group_restriction_; |
| 142 |
| 129 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 143 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 130 }; | 144 }; |
| 131 | 145 |
| 132 // Installs a WriteTransaction to a given session and later clears it when the | 146 // Installs a WriteTransaction to a given session and later clears it when the |
| 133 // utility falls out of scope. Transactions are not nestable, so it is an error | 147 // utility falls out of scope. Transactions are not nestable, so it is an error |
| 134 // to try and use one of these if the session already has a transaction. | 148 // to try and use one of these if the session already has a transaction. |
| 135 class ScopedSetSessionWriteTransaction { | 149 class ScopedSetSessionWriteTransaction { |
| 136 public: | 150 public: |
| 137 ScopedSetSessionWriteTransaction(SyncSession* session, | 151 ScopedSetSessionWriteTransaction(SyncSession* session, |
| 138 syncable::WriteTransaction* trans) | 152 syncable::WriteTransaction* trans) |
| 139 : session_(session) { | 153 : session_(session) { |
| 140 DCHECK(!session_->write_transaction_); | 154 DCHECK(!session_->write_transaction_); |
| 141 session_->write_transaction_ = trans; | 155 session_->write_transaction_ = trans; |
| 142 } | 156 } |
| 143 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } | 157 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; } |
| 144 | 158 |
| 145 private: | 159 private: |
| 146 SyncSession* session_; | 160 SyncSession* session_; |
| 147 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 161 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
| 148 }; | 162 }; |
| 149 | 163 |
| 164 // A utility to restrict access to only those parts of the given SyncSession |
| 165 // that pertain to the specified ModelSafeGroup. See |
| 166 // SyncSession::ModelSafetyRestriction. |
| 167 class ScopedModelSafeGroupRestriction { |
| 168 public: |
| 169 ScopedModelSafeGroupRestriction(SyncSession* to_restrict, |
| 170 ModelSafeGroup restriction) |
| 171 : session_(to_restrict) { |
| 172 DCHECK(!session_->group_restriction_in_effect_); |
| 173 session_->group_restriction_in_effect_ = true; |
| 174 session_->group_restriction_ = restriction; |
| 175 } |
| 176 ~ScopedModelSafeGroupRestriction() { |
| 177 session_->group_restriction_in_effect_ = true; |
| 178 } |
| 179 private: |
| 180 SyncSession* session_; |
| 181 DISALLOW_COPY_AND_ASSIGN(ScopedModelSafeGroupRestriction); |
| 182 }; |
| 183 |
| 150 } // namespace sessions | 184 } // namespace sessions |
| 151 } // namespace browser_sync | 185 } // namespace browser_sync |
| 152 | 186 |
| 153 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 187 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |