| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // SyncSessionContext encapsulates the contextual information and engine | 5 // SyncSessionContext encapsulates the contextual information and engine |
| 6 // components specific to a SyncSession. A context is accessible via | 6 // components specific to a SyncSession. A context is accessible via |
| 7 // a SyncSession so that session SyncerCommands and parts of the engine have | 7 // a SyncSession so that session SyncerCommands and parts of the engine have |
| 8 // a convenient way to access other parts. In this way it can be thought of as | 8 // a convenient way to access other parts. In this way it can be thought of as |
| 9 // the surrounding environment for the SyncSession. The components of this | 9 // the surrounding environment for the SyncSession. The components of this |
| 10 // environment are either valid or not valid for the entire context lifetime, | 10 // environment are either valid or not valid for the entire context lifetime, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "sync/engine/sync_engine_event.h" | 27 #include "sync/engine/sync_engine_event.h" |
| 28 #include "sync/engine/syncer_types.h" | 28 #include "sync/engine/syncer_types.h" |
| 29 #include "sync/engine/traffic_recorder.h" | 29 #include "sync/engine/traffic_recorder.h" |
| 30 #include "sync/internal_api/public/engine/model_safe_worker.h" | 30 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 31 #include "sync/sessions/debug_info_getter.h" | 31 #include "sync/sessions/debug_info_getter.h" |
| 32 | 32 |
| 33 namespace syncable { | 33 namespace syncable { |
| 34 class Directory; | 34 class Directory; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace csync { | 37 namespace syncer { |
| 38 | 38 |
| 39 class ConflictResolver; | 39 class ConflictResolver; |
| 40 class ExtensionsActivityMonitor; | 40 class ExtensionsActivityMonitor; |
| 41 class ServerConnectionManager; | 41 class ServerConnectionManager; |
| 42 class ThrottledDataTypeTracker; | 42 class ThrottledDataTypeTracker; |
| 43 | 43 |
| 44 // Default number of items a client can commit in a single message. | 44 // Default number of items a client can commit in a single message. |
| 45 static const int kDefaultMaxCommitBatchSize = 25; | 45 static const int kDefaultMaxCommitBatchSize = 25; |
| 46 | 46 |
| 47 namespace sessions { | 47 namespace sessions { |
| 48 class ScopedSessionContextConflictResolver; | 48 class ScopedSessionContextConflictResolver; |
| 49 class TestScopedSessionEventListener; | 49 class TestScopedSessionEventListener; |
| 50 | 50 |
| 51 class SyncSessionContext { | 51 class SyncSessionContext { |
| 52 public: | 52 public: |
| 53 SyncSessionContext(ServerConnectionManager* connection_manager, | 53 SyncSessionContext(ServerConnectionManager* connection_manager, |
| 54 syncable::Directory* directory, | 54 syncable::Directory* directory, |
| 55 const ModelSafeRoutingInfo& model_safe_routing_info, | 55 const ModelSafeRoutingInfo& model_safe_routing_info, |
| 56 const std::vector<ModelSafeWorker*>& workers, | 56 const std::vector<ModelSafeWorker*>& workers, |
| 57 ExtensionsActivityMonitor* extensions_activity_monitor, | 57 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 58 ThrottledDataTypeTracker* throttled_data_type_tracker, | 58 ThrottledDataTypeTracker* throttled_data_type_tracker, |
| 59 const std::vector<SyncEngineEventListener*>& listeners, | 59 const std::vector<SyncEngineEventListener*>& listeners, |
| 60 DebugInfoGetter* debug_info_getter, | 60 DebugInfoGetter* debug_info_getter, |
| 61 csync::TrafficRecorder* traffic_recorder); | 61 syncer::TrafficRecorder* traffic_recorder); |
| 62 ~SyncSessionContext(); | 62 ~SyncSessionContext(); |
| 63 | 63 |
| 64 ConflictResolver* resolver() { return resolver_; } | 64 ConflictResolver* resolver() { return resolver_; } |
| 65 ServerConnectionManager* connection_manager() { | 65 ServerConnectionManager* connection_manager() { |
| 66 return connection_manager_; | 66 return connection_manager_; |
| 67 } | 67 } |
| 68 syncable::Directory* directory() { | 68 syncable::Directory* directory() { |
| 69 return directory_; | 69 return directory_; |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { | 118 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { |
| 119 previous_session_routing_info_ = info; | 119 previous_session_routing_info_ = info; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void NotifyListeners(const SyncEngineEvent& event) { | 122 void NotifyListeners(const SyncEngineEvent& event) { |
| 123 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, | 123 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, |
| 124 OnSyncEngineEvent(event)); | 124 OnSyncEngineEvent(event)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 csync::TrafficRecorder* traffic_recorder() { | 127 syncer::TrafficRecorder* traffic_recorder() { |
| 128 return traffic_recorder_; | 128 return traffic_recorder_; |
| 129 } | 129 } |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 // Rather than force clients to set and null-out various context members, we | 132 // Rather than force clients to set and null-out various context members, we |
| 133 // extend our encapsulation boundary to scoped helpers that take care of this | 133 // extend our encapsulation boundary to scoped helpers that take care of this |
| 134 // once they are allocated. See definitions of these below. | 134 // once they are allocated. See definitions of these below. |
| 135 friend class ScopedSessionContextConflictResolver; | 135 friend class ScopedSessionContextConflictResolver; |
| 136 friend class TestScopedSessionEventListener; | 136 friend class TestScopedSessionEventListener; |
| 137 | 137 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 167 // Some routing info history to help us clean up types that get disabled | 167 // Some routing info history to help us clean up types that get disabled |
| 168 // by the user. | 168 // by the user. |
| 169 ModelSafeRoutingInfo previous_session_routing_info_; | 169 ModelSafeRoutingInfo previous_session_routing_info_; |
| 170 | 170 |
| 171 ThrottledDataTypeTracker* throttled_data_type_tracker_; | 171 ThrottledDataTypeTracker* throttled_data_type_tracker_; |
| 172 | 172 |
| 173 // We use this to get debug info to send to the server for debugging | 173 // We use this to get debug info to send to the server for debugging |
| 174 // client behavior on server side. | 174 // client behavior on server side. |
| 175 DebugInfoGetter* const debug_info_getter_; | 175 DebugInfoGetter* const debug_info_getter_; |
| 176 | 176 |
| 177 csync::TrafficRecorder* traffic_recorder_; | 177 syncer::TrafficRecorder* traffic_recorder_; |
| 178 | 178 |
| 179 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); | 179 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 // Installs a ConflictResolver to a given session context for the lifetime of | 182 // Installs a ConflictResolver to a given session context for the lifetime of |
| 183 // the ScopedSessionContextConflictResolver. There should never be more than | 183 // the ScopedSessionContextConflictResolver. There should never be more than |
| 184 // one ConflictResolver in the system, so it is an error to use this if the | 184 // one ConflictResolver in the system, so it is an error to use this if the |
| 185 // context already has a resolver. | 185 // context already has a resolver. |
| 186 class ScopedSessionContextConflictResolver { | 186 class ScopedSessionContextConflictResolver { |
| 187 public: | 187 public: |
| 188 // Note: |context| and |resolver| should outlive |this|. | 188 // Note: |context| and |resolver| should outlive |this|. |
| 189 ScopedSessionContextConflictResolver(SyncSessionContext* context, | 189 ScopedSessionContextConflictResolver(SyncSessionContext* context, |
| 190 ConflictResolver* resolver) | 190 ConflictResolver* resolver) |
| 191 : context_(context), resolver_(resolver) { | 191 : context_(context), resolver_(resolver) { |
| 192 DCHECK(NULL == context->resolver_); | 192 DCHECK(NULL == context->resolver_); |
| 193 context->resolver_ = resolver; | 193 context->resolver_ = resolver; |
| 194 } | 194 } |
| 195 ~ScopedSessionContextConflictResolver() { | 195 ~ScopedSessionContextConflictResolver() { |
| 196 context_->resolver_ = NULL; | 196 context_->resolver_ = NULL; |
| 197 } | 197 } |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 SyncSessionContext* context_; | 200 SyncSessionContext* context_; |
| 201 ConflictResolver* resolver_; | 201 ConflictResolver* resolver_; |
| 202 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 202 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 } // namespace sessions | 205 } // namespace sessions |
| 206 } // namespace csync | 206 } // namespace syncer |
| 207 | 207 |
| 208 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 208 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| OLD | NEW |