| 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 <map> |
| 22 #include <string> | 23 #include <string> |
| 23 | 24 |
| 24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 26 #include "base/time.h" |
| 25 #include "chrome/browser/sync/engine/model_safe_worker.h" | 27 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 26 #include "chrome/browser/sync/engine/syncer_types.h" | 28 #include "chrome/browser/sync/engine/syncer_types.h" |
| 27 #include "chrome/browser/sync/sessions/debug_info_getter.h" | 29 #include "chrome/browser/sync/sessions/debug_info_getter.h" |
| 28 | 30 |
| 29 namespace syncable { | 31 namespace syncable { |
| 30 class DirectoryManager; | 32 class DirectoryManager; |
| 31 } | 33 } |
| 32 | 34 |
| 33 namespace browser_sync { | 35 namespace browser_sync { |
| 34 | 36 |
| 35 class ConflictResolver; | 37 class ConflictResolver; |
| 36 class ExtensionsActivityMonitor; | 38 class ExtensionsActivityMonitor; |
| 37 class ModelSafeWorkerRegistrar; | 39 class ModelSafeWorkerRegistrar; |
| 38 class ServerConnectionManager; | 40 class ServerConnectionManager; |
| 39 | 41 |
| 40 // Default number of items a client can commit in a single message. | 42 // Default number of items a client can commit in a single message. |
| 41 static const int kDefaultMaxCommitBatchSize = 25; | 43 static const int kDefaultMaxCommitBatchSize = 25; |
| 42 | 44 |
| 43 namespace sessions { | 45 namespace sessions { |
| 44 class ScopedSessionContextConflictResolver; | 46 class ScopedSessionContextConflictResolver; |
| 45 struct SyncSessionSnapshot; | 47 struct SyncSessionSnapshot; |
| 46 class TestScopedSessionEventListener; | 48 class TestScopedSessionEventListener; |
| 47 | 49 |
| 50 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; |
| 51 |
| 48 class SyncSessionContext { | 52 class SyncSessionContext { |
| 49 public: | 53 public: |
| 50 SyncSessionContext(ServerConnectionManager* connection_manager, | 54 SyncSessionContext(ServerConnectionManager* connection_manager, |
| 51 syncable::DirectoryManager* directory_manager, | 55 syncable::DirectoryManager* directory_manager, |
| 52 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 56 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 53 const std::vector<SyncEngineEventListener*>& listeners, | 57 const std::vector<SyncEngineEventListener*>& listeners, |
| 54 DebugInfoGetter* debug_info_getter); | 58 DebugInfoGetter* debug_info_getter); |
| 59 |
| 60 // Empty constructor for unit tests. |
| 61 SyncSessionContext(); |
| 55 ~SyncSessionContext(); | 62 ~SyncSessionContext(); |
| 56 | 63 |
| 57 ConflictResolver* resolver() { return resolver_; } | 64 ConflictResolver* resolver() { return resolver_; } |
| 58 ServerConnectionManager* connection_manager() { | 65 ServerConnectionManager* connection_manager() { |
| 59 return connection_manager_; | 66 return connection_manager_; |
| 60 } | 67 } |
| 61 syncable::DirectoryManager* directory_manager() { | 68 syncable::DirectoryManager* directory_manager() { |
| 62 return directory_manager_; | 69 return directory_manager_; |
| 63 } | 70 } |
| 64 ModelSafeWorkerRegistrar* registrar() { | 71 ModelSafeWorkerRegistrar* registrar() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 103 |
| 97 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { | 104 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { |
| 98 previous_session_routing_info_ = info; | 105 previous_session_routing_info_ = info; |
| 99 } | 106 } |
| 100 | 107 |
| 101 void NotifyListeners(const SyncEngineEvent& event) { | 108 void NotifyListeners(const SyncEngineEvent& event) { |
| 102 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, | 109 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, |
| 103 OnSyncEngineEvent(event)); | 110 OnSyncEngineEvent(event)); |
| 104 } | 111 } |
| 105 | 112 |
| 113 virtual void AddUnthrottleTime(const syncable::ModelTypeSet& types, |
| 114 const base::TimeTicks& time); |
| 115 |
| 106 private: | 116 private: |
| 107 // Rather than force clients to set and null-out various context members, we | 117 // Rather than force clients to set and null-out various context members, we |
| 108 // extend our encapsulation boundary to scoped helpers that take care of this | 118 // extend our encapsulation boundary to scoped helpers that take care of this |
| 109 // once they are allocated. See definitions of these below. | 119 // once they are allocated. See definitions of these below. |
| 110 friend class ScopedSessionContextConflictResolver; | 120 friend class ScopedSessionContextConflictResolver; |
| 111 friend class TestScopedSessionEventListener; | 121 friend class TestScopedSessionEventListener; |
| 112 | 122 |
| 113 // This is installed by Syncer objects when needed and may be NULL. | 123 // This is installed by Syncer objects when needed and may be NULL. |
| 114 ConflictResolver* resolver_; | 124 ConflictResolver* resolver_; |
| 115 | 125 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 140 // by the user. | 150 // by the user. |
| 141 ModelSafeRoutingInfo previous_session_routing_info_; | 151 ModelSafeRoutingInfo previous_session_routing_info_; |
| 142 | 152 |
| 143 // Cache of last session snapshot information. | 153 // Cache of last session snapshot information. |
| 144 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; | 154 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; |
| 145 | 155 |
| 146 // We use this to get debug info to send to the server for debugging | 156 // We use this to get debug info to send to the server for debugging |
| 147 // client behavior on server side. | 157 // client behavior on server side. |
| 148 DebugInfoGetter* const debug_info_getter_; | 158 DebugInfoGetter* const debug_info_getter_; |
| 149 | 159 |
| 160 UnthrottleTimes unthrottle_times_; |
| 161 |
| 150 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); | 162 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); |
| 151 }; | 163 }; |
| 152 | 164 |
| 153 // Installs a ConflictResolver to a given session context for the lifetime of | 165 // Installs a ConflictResolver to a given session context for the lifetime of |
| 154 // the ScopedSessionContextConflictResolver. There should never be more than | 166 // the ScopedSessionContextConflictResolver. There should never be more than |
| 155 // one ConflictResolver in the system, so it is an error to use this if the | 167 // one ConflictResolver in the system, so it is an error to use this if the |
| 156 // context already has a resolver. | 168 // context already has a resolver. |
| 157 class ScopedSessionContextConflictResolver { | 169 class ScopedSessionContextConflictResolver { |
| 158 public: | 170 public: |
| 159 // Note: |context| and |resolver| should outlive |this|. | 171 // Note: |context| and |resolver| should outlive |this|. |
| 160 ScopedSessionContextConflictResolver(SyncSessionContext* context, | 172 ScopedSessionContextConflictResolver(SyncSessionContext* context, |
| 161 ConflictResolver* resolver) | 173 ConflictResolver* resolver) |
| 162 : context_(context), resolver_(resolver) { | 174 : context_(context), resolver_(resolver) { |
| 163 DCHECK(NULL == context->resolver_); | 175 DCHECK(NULL == context->resolver_); |
| 164 context->resolver_ = resolver; | 176 context->resolver_ = resolver; |
| 165 } | 177 } |
| 166 ~ScopedSessionContextConflictResolver() { | 178 ~ScopedSessionContextConflictResolver() { |
| 167 context_->resolver_ = NULL; | 179 context_->resolver_ = NULL; |
| 168 } | 180 } |
| 169 private: | 181 private: |
| 170 SyncSessionContext* context_; | 182 SyncSessionContext* context_; |
| 171 ConflictResolver* resolver_; | 183 ConflictResolver* resolver_; |
| 172 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 184 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
| 173 }; | 185 }; |
| 174 | 186 |
| 175 } // namespace sessions | 187 } // namespace sessions |
| 176 } // namespace browser_sync | 188 } // namespace browser_sync |
| 177 | 189 |
| 178 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 190 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| OLD | NEW |