| 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, |
| 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 SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 18 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| 19 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 19 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| 20 #pragma once | 20 #pragma once |
| 21 | 21 |
| 22 #include <map> | 22 #include <map> |
| 23 #include <string> | 23 #include <string> |
| 24 | 24 |
| 25 #include "base/gtest_prod_util.h" | 25 #include "base/gtest_prod_util.h" |
| 26 #include "base/memory/scoped_ptr.h" | 26 #include "base/memory/scoped_ptr.h" |
| 27 #include "base/time.h" | 27 #include "base/time.h" |
| 28 #include "sync/engine/model_safe_worker.h" | 28 #include "sync/engine/model_safe_worker.h" |
| 29 #include "sync/engine/syncer_types.h" | 29 #include "sync/engine/syncer_types.h" |
| 30 #include "sync/engine/traffic_recorder.h" |
| 30 #include "sync/sessions/debug_info_getter.h" | 31 #include "sync/sessions/debug_info_getter.h" |
| 31 | 32 |
| 32 namespace syncable { | 33 namespace syncable { |
| 33 class Directory; | 34 class Directory; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace browser_sync { | 37 namespace browser_sync { |
| 37 | 38 |
| 38 class ConflictResolver; | 39 class ConflictResolver; |
| 39 class ExtensionsActivityMonitor; | 40 class ExtensionsActivityMonitor; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const base::TimeTicks& time); | 117 const base::TimeTicks& time); |
| 117 | 118 |
| 118 // This prunes the |unthrottle_time_| map based on the |time| passed in. This | 119 // This prunes the |unthrottle_time_| map based on the |time| passed in. This |
| 119 // is called by syncer at the SYNCER_BEGIN stage. | 120 // is called by syncer at the SYNCER_BEGIN stage. |
| 120 void PruneUnthrottledTypes(const base::TimeTicks& time); | 121 void PruneUnthrottledTypes(const base::TimeTicks& time); |
| 121 | 122 |
| 122 // This returns the list of currently throttled types. Unless server returns | 123 // This returns the list of currently throttled types. Unless server returns |
| 123 // new throttled types this will remain constant through out the sync cycle. | 124 // new throttled types this will remain constant through out the sync cycle. |
| 124 syncable::ModelTypeSet GetThrottledTypes() const; | 125 syncable::ModelTypeSet GetThrottledTypes() const; |
| 125 | 126 |
| 127 browser_sync::TrafficRecorder* traffic_recorder() { |
| 128 return &traffic_recorder_; |
| 129 } |
| 130 |
| 126 private: | 131 private: |
| 127 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; | 132 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; |
| 128 | 133 |
| 129 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest); | 134 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest); |
| 130 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, | 135 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, |
| 131 GetCurrentlyThrottledTypesTest); | 136 GetCurrentlyThrottledTypesTest); |
| 132 | 137 |
| 133 // Rather than force clients to set and null-out various context members, we | 138 // Rather than force clients to set and null-out various context members, we |
| 134 // extend our encapsulation boundary to scoped helpers that take care of this | 139 // extend our encapsulation boundary to scoped helpers that take care of this |
| 135 // once they are allocated. See definitions of these below. | 140 // once they are allocated. See definitions of these below. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; | 175 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; |
| 171 | 176 |
| 172 // We use this to get debug info to send to the server for debugging | 177 // We use this to get debug info to send to the server for debugging |
| 173 // client behavior on server side. | 178 // client behavior on server side. |
| 174 DebugInfoGetter* const debug_info_getter_; | 179 DebugInfoGetter* const debug_info_getter_; |
| 175 | 180 |
| 176 // This is a map from throttled data types to the time at which they can be | 181 // This is a map from throttled data types to the time at which they can be |
| 177 // unthrottled. | 182 // unthrottled. |
| 178 UnthrottleTimes unthrottle_times_; | 183 UnthrottleTimes unthrottle_times_; |
| 179 | 184 |
| 185 // TODO(lipalani): Move the creation of this to |SyncManager|. |
| 186 browser_sync::TrafficRecorder traffic_recorder_; |
| 187 |
| 180 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); | 188 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); |
| 181 }; | 189 }; |
| 182 | 190 |
| 183 // Installs a ConflictResolver to a given session context for the lifetime of | 191 // Installs a ConflictResolver to a given session context for the lifetime of |
| 184 // the ScopedSessionContextConflictResolver. There should never be more than | 192 // the ScopedSessionContextConflictResolver. There should never be more than |
| 185 // one ConflictResolver in the system, so it is an error to use this if the | 193 // one ConflictResolver in the system, so it is an error to use this if the |
| 186 // context already has a resolver. | 194 // context already has a resolver. |
| 187 class ScopedSessionContextConflictResolver { | 195 class ScopedSessionContextConflictResolver { |
| 188 public: | 196 public: |
| 189 // Note: |context| and |resolver| should outlive |this|. | 197 // Note: |context| and |resolver| should outlive |this|. |
| 190 ScopedSessionContextConflictResolver(SyncSessionContext* context, | 198 ScopedSessionContextConflictResolver(SyncSessionContext* context, |
| 191 ConflictResolver* resolver) | 199 ConflictResolver* resolver) |
| 192 : context_(context), resolver_(resolver) { | 200 : context_(context), resolver_(resolver) { |
| 193 DCHECK(NULL == context->resolver_); | 201 DCHECK(NULL == context->resolver_); |
| 194 context->resolver_ = resolver; | 202 context->resolver_ = resolver; |
| 195 } | 203 } |
| 196 ~ScopedSessionContextConflictResolver() { | 204 ~ScopedSessionContextConflictResolver() { |
| 197 context_->resolver_ = NULL; | 205 context_->resolver_ = NULL; |
| 198 } | 206 } |
| 199 private: | 207 private: |
| 200 SyncSessionContext* context_; | 208 SyncSessionContext* context_; |
| 201 ConflictResolver* resolver_; | 209 ConflictResolver* resolver_; |
| 202 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 210 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
| 203 }; | 211 }; |
| 204 | 212 |
| 205 } // namespace sessions | 213 } // namespace sessions |
| 206 } // namespace browser_sync | 214 } // namespace browser_sync |
| 207 | 215 |
| 208 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 216 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| OLD | NEW |