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