Chromium Code Reviews| 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 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/gtest_prod_util.h" | |
| 27 #include "base/time.h" | 26 #include "base/time.h" |
| 28 #include "sync/engine/model_safe_worker.h" | 27 #include "sync/engine/model_safe_worker.h" |
| 29 #include "sync/engine/syncer_types.h" | 28 #include "sync/engine/syncer_types.h" |
| 30 #include "sync/engine/sync_engine_event.h" | 29 #include "sync/engine/sync_engine_event.h" |
| 31 #include "sync/engine/traffic_recorder.h" | 30 #include "sync/engine/traffic_recorder.h" |
| 32 #include "sync/sessions/debug_info_getter.h" | 31 #include "sync/sessions/debug_info_getter.h" |
| 33 | 32 |
| 34 namespace syncable { | 33 namespace syncable { |
| 35 class Directory; | 34 class Directory; |
| 36 } | 35 } |
| 37 | 36 |
| 38 namespace browser_sync { | 37 namespace browser_sync { |
| 39 | 38 |
| 40 class ConflictResolver; | 39 class ConflictResolver; |
| 41 class ExtensionsActivityMonitor; | 40 class ExtensionsActivityMonitor; |
| 42 class ModelSafeWorkerRegistrar; | 41 class ModelSafeWorkerRegistrar; |
| 43 class ServerConnectionManager; | 42 class ServerConnectionManager; |
| 43 class ThrottledDataTypeTracker; | |
| 44 | 44 |
| 45 // Default number of items a client can commit in a single message. | 45 // Default number of items a client can commit in a single message. |
| 46 static const int kDefaultMaxCommitBatchSize = 25; | 46 static const int kDefaultMaxCommitBatchSize = 25; |
| 47 | 47 |
| 48 namespace sessions { | 48 namespace sessions { |
| 49 class ScopedSessionContextConflictResolver; | 49 class ScopedSessionContextConflictResolver; |
| 50 class TestScopedSessionEventListener; | 50 class TestScopedSessionEventListener; |
| 51 | 51 |
| 52 class SyncSessionContext { | 52 class SyncSessionContext { |
| 53 public: | 53 public: |
| 54 SyncSessionContext(ServerConnectionManager* connection_manager, | 54 SyncSessionContext(ServerConnectionManager* connection_manager, |
| 55 syncable::Directory* directory, | 55 syncable::Directory* directory, |
| 56 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 56 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 57 ExtensionsActivityMonitor* extensions_activity_monitor, | 57 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 58 ThrottledDataTypeTracker* throttled_data_type_tracker, | |
| 58 const std::vector<SyncEngineEventListener*>& listeners, | 59 const std::vector<SyncEngineEventListener*>& listeners, |
| 59 DebugInfoGetter* debug_info_getter, | 60 DebugInfoGetter* debug_info_getter, |
| 60 browser_sync::TrafficRecorder* traffic_recorder); | 61 browser_sync::TrafficRecorder* traffic_recorder); |
| 61 | 62 ~SyncSessionContext(); |
| 62 // Empty constructor for unit tests. | |
| 63 SyncSessionContext(); | |
| 64 virtual ~SyncSessionContext(); | |
|
tim (not reviewing)
2012/06/11 18:53:46
Was MockSyncSessionContext in syncer_proto_util_un
rlarocque
2012/06/11 23:28:51
I assumed so, since a grep for 'public' and 'SyncS
| |
| 65 | 63 |
| 66 ConflictResolver* resolver() { return resolver_; } | 64 ConflictResolver* resolver() { return resolver_; } |
| 67 ServerConnectionManager* connection_manager() { | 65 ServerConnectionManager* connection_manager() { |
| 68 return connection_manager_; | 66 return connection_manager_; |
| 69 } | 67 } |
| 70 syncable::Directory* directory() { | 68 syncable::Directory* directory() { |
| 71 return directory_; | 69 return directory_; |
| 72 } | 70 } |
| 73 | 71 |
| 74 ModelSafeWorkerRegistrar* registrar() { | 72 ModelSafeWorkerRegistrar* registrar() { |
| 75 return registrar_; | 73 return registrar_; |
| 76 } | 74 } |
| 77 ExtensionsActivityMonitor* extensions_monitor() { | 75 ExtensionsActivityMonitor* extensions_monitor() { |
| 78 return extensions_activity_monitor_; | 76 return extensions_activity_monitor_; |
| 79 } | 77 } |
| 80 | 78 |
| 79 ThrottledDataTypeTracker* throttled_data_type_tracker() { | |
| 80 return throttled_data_type_tracker_; | |
| 81 } | |
| 82 | |
| 81 DebugInfoGetter* debug_info_getter() { | 83 DebugInfoGetter* debug_info_getter() { |
| 82 return debug_info_getter_; | 84 return debug_info_getter_; |
| 83 } | 85 } |
| 84 | 86 |
| 85 // Talk notification status. | 87 // Talk notification status. |
| 86 void set_notifications_enabled(bool enabled) { | 88 void set_notifications_enabled(bool enabled) { |
| 87 notifications_enabled_ = enabled; | 89 notifications_enabled_ = enabled; |
| 88 } | 90 } |
| 89 bool notifications_enabled() { return notifications_enabled_; } | 91 bool notifications_enabled() { return notifications_enabled_; } |
| 90 | 92 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 106 | 108 |
| 107 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { | 109 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { |
| 108 previous_session_routing_info_ = info; | 110 previous_session_routing_info_ = info; |
| 109 } | 111 } |
| 110 | 112 |
| 111 void NotifyListeners(const SyncEngineEvent& event) { | 113 void NotifyListeners(const SyncEngineEvent& event) { |
| 112 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, | 114 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, |
| 113 OnSyncEngineEvent(event)); | 115 OnSyncEngineEvent(event)); |
| 114 } | 116 } |
| 115 | 117 |
| 116 // This is virtual for unit tests. | |
| 117 virtual void SetUnthrottleTime(syncable::ModelTypeSet types, | |
| 118 const base::TimeTicks& time); | |
| 119 | |
| 120 // This prunes the |unthrottle_time_| map based on the |time| passed in. This | |
| 121 // is called by syncer at the SYNCER_BEGIN stage. | |
| 122 void PruneUnthrottledTypes(const base::TimeTicks& time); | |
| 123 | |
| 124 // This returns the list of currently throttled types. Unless server returns | |
| 125 // new throttled types this will remain constant through out the sync cycle. | |
| 126 syncable::ModelTypeSet GetThrottledTypes() const; | |
| 127 | |
| 128 browser_sync::TrafficRecorder* traffic_recorder() { | 118 browser_sync::TrafficRecorder* traffic_recorder() { |
| 129 return traffic_recorder_; | 119 return traffic_recorder_; |
| 130 } | 120 } |
| 131 | 121 |
| 132 private: | 122 private: |
| 133 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; | |
| 134 | |
| 135 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest); | |
| 136 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, | |
| 137 GetCurrentlyThrottledTypesTest); | |
| 138 | |
| 139 // Rather than force clients to set and null-out various context members, we | 123 // Rather than force clients to set and null-out various context members, we |
| 140 // extend our encapsulation boundary to scoped helpers that take care of this | 124 // extend our encapsulation boundary to scoped helpers that take care of this |
| 141 // once they are allocated. See definitions of these below. | 125 // once they are allocated. See definitions of these below. |
| 142 friend class ScopedSessionContextConflictResolver; | 126 friend class ScopedSessionContextConflictResolver; |
| 143 friend class TestScopedSessionEventListener; | 127 friend class TestScopedSessionEventListener; |
| 144 | 128 |
| 145 // This is installed by Syncer objects when needed and may be NULL. | 129 // This is installed by Syncer objects when needed and may be NULL. |
| 146 ConflictResolver* resolver_; | 130 ConflictResolver* resolver_; |
| 147 | 131 |
| 148 ObserverList<SyncEngineEventListener> listeners_; | 132 ObserverList<SyncEngineEventListener> listeners_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 165 // The name of the account being synced. | 149 // The name of the account being synced. |
| 166 std::string account_name_; | 150 std::string account_name_; |
| 167 | 151 |
| 168 // The server limits the number of items a client can commit in one batch. | 152 // The server limits the number of items a client can commit in one batch. |
| 169 int max_commit_batch_size_; | 153 int max_commit_batch_size_; |
| 170 | 154 |
| 171 // Some routing info history to help us clean up types that get disabled | 155 // Some routing info history to help us clean up types that get disabled |
| 172 // by the user. | 156 // by the user. |
| 173 ModelSafeRoutingInfo previous_session_routing_info_; | 157 ModelSafeRoutingInfo previous_session_routing_info_; |
| 174 | 158 |
| 159 ThrottledDataTypeTracker* throttled_data_type_tracker_; | |
| 160 | |
| 175 // We use this to get debug info to send to the server for debugging | 161 // We use this to get debug info to send to the server for debugging |
| 176 // client behavior on server side. | 162 // client behavior on server side. |
| 177 DebugInfoGetter* const debug_info_getter_; | 163 DebugInfoGetter* const debug_info_getter_; |
| 178 | 164 |
| 179 // This is a map from throttled data types to the time at which they can be | |
| 180 // unthrottled. | |
| 181 UnthrottleTimes unthrottle_times_; | |
| 182 | |
| 183 browser_sync::TrafficRecorder* traffic_recorder_; | 165 browser_sync::TrafficRecorder* traffic_recorder_; |
| 184 | 166 |
| 185 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); | 167 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); |
| 186 }; | 168 }; |
| 187 | 169 |
| 188 // 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 |
| 189 // the ScopedSessionContextConflictResolver. There should never be more than | 171 // the ScopedSessionContextConflictResolver. There should never be more than |
| 190 // 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 |
| 191 // context already has a resolver. | 173 // context already has a resolver. |
| 192 class ScopedSessionContextConflictResolver { | 174 class ScopedSessionContextConflictResolver { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 205 private: | 187 private: |
| 206 SyncSessionContext* context_; | 188 SyncSessionContext* context_; |
| 207 ConflictResolver* resolver_; | 189 ConflictResolver* resolver_; |
| 208 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 190 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
| 209 }; | 191 }; |
| 210 | 192 |
| 211 } // namespace sessions | 193 } // namespace sessions |
| 212 } // namespace browser_sync | 194 } // namespace browser_sync |
| 213 | 195 |
| 214 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 196 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| OLD | NEW |