| 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 // 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, |
| 11 // or they are valid for explicitly scoped periods of time by using Scoped | 11 // or they are valid for explicitly scoped periods of time by using Scoped |
| 12 // installation utilities found below. This means that the context assumes no | 12 // installation utilities found below. This means that the context assumes no |
| 13 // ownership whatsoever of any object that was not created by the context | 13 // ownership whatsoever of any object that was not created by the context |
| 14 // itself. | 14 // itself. |
| 15 // | 15 // |
| 16 // It can only be used from the SyncerThread. | 16 // It can only be used from the SyncerThread. |
| 17 | 17 |
| 18 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 18 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| 19 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 19 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| 20 #pragma once | 20 #pragma once |
| 21 | 21 |
| 22 #include <string> | 22 #include <string> |
| 23 | 23 |
| 24 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
| 25 #include "chrome/browser/sync/engine/model_safe_worker.h" | 25 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 26 #include "chrome/browser/sync/engine/syncer_types.h" | 26 #include "chrome/browser/sync/engine/syncer_types.h" |
| 27 #include "chrome/browser/sync/sessions/debug_info_getter.h" | |
| 28 | 27 |
| 29 namespace syncable { | 28 namespace syncable { |
| 30 class DirectoryManager; | 29 class DirectoryManager; |
| 31 } | 30 } |
| 32 | 31 |
| 33 namespace browser_sync { | 32 namespace browser_sync { |
| 34 | 33 |
| 35 class ConflictResolver; | 34 class ConflictResolver; |
| 36 class ExtensionsActivityMonitor; | 35 class ExtensionsActivityMonitor; |
| 37 class ModelSafeWorkerRegistrar; | 36 class ModelSafeWorkerRegistrar; |
| 38 class ServerConnectionManager; | 37 class ServerConnectionManager; |
| 39 | 38 |
| 40 // Default number of items a client can commit in a single message. | 39 // Default number of items a client can commit in a single message. |
| 41 static const int kDefaultMaxCommitBatchSize = 25; | 40 static const int kDefaultMaxCommitBatchSize = 25; |
| 42 | 41 |
| 43 namespace sessions { | 42 namespace sessions { |
| 44 class ScopedSessionContextConflictResolver; | 43 class ScopedSessionContextConflictResolver; |
| 45 struct SyncSessionSnapshot; | 44 struct SyncSessionSnapshot; |
| 46 class TestScopedSessionEventListener; | 45 class TestScopedSessionEventListener; |
| 47 | 46 |
| 48 class SyncSessionContext { | 47 class SyncSessionContext { |
| 49 public: | 48 public: |
| 50 SyncSessionContext(ServerConnectionManager* connection_manager, | 49 SyncSessionContext(ServerConnectionManager* connection_manager, |
| 51 syncable::DirectoryManager* directory_manager, | 50 syncable::DirectoryManager* directory_manager, |
| 52 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 51 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 53 const std::vector<SyncEngineEventListener*>& listeners, | 52 const std::vector<SyncEngineEventListener*>& listeners); |
| 54 DebugInfoGetter* debug_info_getter); | |
| 55 ~SyncSessionContext(); | 53 ~SyncSessionContext(); |
| 56 | 54 |
| 57 ConflictResolver* resolver() { return resolver_; } | 55 ConflictResolver* resolver() { return resolver_; } |
| 58 ServerConnectionManager* connection_manager() { | 56 ServerConnectionManager* connection_manager() { |
| 59 return connection_manager_; | 57 return connection_manager_; |
| 60 } | 58 } |
| 61 syncable::DirectoryManager* directory_manager() { | 59 syncable::DirectoryManager* directory_manager() { |
| 62 return directory_manager_; | 60 return directory_manager_; |
| 63 } | 61 } |
| 64 ModelSafeWorkerRegistrar* registrar() { | 62 ModelSafeWorkerRegistrar* registrar() { |
| 65 return registrar_; | 63 return registrar_; |
| 66 } | 64 } |
| 67 ExtensionsActivityMonitor* extensions_monitor() { | 65 ExtensionsActivityMonitor* extensions_monitor() { |
| 68 return extensions_activity_monitor_; | 66 return extensions_activity_monitor_; |
| 69 } | 67 } |
| 70 | 68 |
| 71 DebugInfoGetter* debug_info_getter() { | |
| 72 return debug_info_getter_; | |
| 73 } | |
| 74 | |
| 75 // Talk notification status. | 69 // Talk notification status. |
| 76 void set_notifications_enabled(bool enabled) { | 70 void set_notifications_enabled(bool enabled) { |
| 77 notifications_enabled_ = enabled; | 71 notifications_enabled_ = enabled; |
| 78 } | 72 } |
| 79 bool notifications_enabled() { return notifications_enabled_; } | 73 bool notifications_enabled() { return notifications_enabled_; } |
| 80 | 74 |
| 81 // Account name, set once a directory has been opened. | 75 // Account name, set once a directory has been opened. |
| 82 void set_account_name(const std::string name) { | 76 void set_account_name(const std::string name) { |
| 83 DCHECK(account_name_.empty()); | 77 DCHECK(account_name_.empty()); |
| 84 account_name_ = name; | 78 account_name_ = name; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // The server limits the number of items a client can commit in one batch. | 130 // The server limits the number of items a client can commit in one batch. |
| 137 int max_commit_batch_size_; | 131 int max_commit_batch_size_; |
| 138 | 132 |
| 139 // Some routing info history to help us clean up types that get disabled | 133 // Some routing info history to help us clean up types that get disabled |
| 140 // by the user. | 134 // by the user. |
| 141 ModelSafeRoutingInfo previous_session_routing_info_; | 135 ModelSafeRoutingInfo previous_session_routing_info_; |
| 142 | 136 |
| 143 // Cache of last session snapshot information. | 137 // Cache of last session snapshot information. |
| 144 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; | 138 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; |
| 145 | 139 |
| 146 // We use this to get debug info to send to the server for debugging | |
| 147 // client behavior on server side. | |
| 148 DebugInfoGetter* const debug_info_getter_; | |
| 149 | |
| 150 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); | 140 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); |
| 151 }; | 141 }; |
| 152 | 142 |
| 153 // Installs a ConflictResolver to a given session context for the lifetime of | 143 // Installs a ConflictResolver to a given session context for the lifetime of |
| 154 // the ScopedSessionContextConflictResolver. There should never be more than | 144 // the ScopedSessionContextConflictResolver. There should never be more than |
| 155 // one ConflictResolver in the system, so it is an error to use this if the | 145 // one ConflictResolver in the system, so it is an error to use this if the |
| 156 // context already has a resolver. | 146 // context already has a resolver. |
| 157 class ScopedSessionContextConflictResolver { | 147 class ScopedSessionContextConflictResolver { |
| 158 public: | 148 public: |
| 159 // Note: |context| and |resolver| should outlive |this|. | 149 // Note: |context| and |resolver| should outlive |this|. |
| 160 ScopedSessionContextConflictResolver(SyncSessionContext* context, | 150 ScopedSessionContextConflictResolver(SyncSessionContext* context, |
| 161 ConflictResolver* resolver) | 151 ConflictResolver* resolver) |
| 162 : context_(context), resolver_(resolver) { | 152 : context_(context), resolver_(resolver) { |
| 163 DCHECK(NULL == context->resolver_); | 153 DCHECK(NULL == context->resolver_); |
| 164 context->resolver_ = resolver; | 154 context->resolver_ = resolver; |
| 165 } | 155 } |
| 166 ~ScopedSessionContextConflictResolver() { | 156 ~ScopedSessionContextConflictResolver() { |
| 167 context_->resolver_ = NULL; | 157 context_->resolver_ = NULL; |
| 168 } | 158 } |
| 169 private: | 159 private: |
| 170 SyncSessionContext* context_; | 160 SyncSessionContext* context_; |
| 171 ConflictResolver* resolver_; | 161 ConflictResolver* resolver_; |
| 172 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 162 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
| 173 }; | 163 }; |
| 174 | 164 |
| 175 } // namespace sessions | 165 } // namespace sessions |
| 176 } // namespace browser_sync | 166 } // namespace browser_sync |
| 177 | 167 |
| 178 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 168 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| OLD | NEW |