Chromium Code Reviews| 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 <map> |
| 23 #include <string> | 23 #include <string> |
| 24 | 24 |
| 25 #include "base/gtest_prod_util.h" | |
| 25 #include "base/memory/scoped_ptr.h" | 26 #include "base/memory/scoped_ptr.h" |
| 26 #include "base/time.h" | 27 #include "base/time.h" |
| 27 #include "chrome/browser/sync/engine/model_safe_worker.h" | 28 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 28 #include "chrome/browser/sync/engine/syncer_types.h" | 29 #include "chrome/browser/sync/engine/syncer_types.h" |
| 29 #include "chrome/browser/sync/sessions/debug_info_getter.h" | 30 #include "chrome/browser/sync/sessions/debug_info_getter.h" |
| 30 | 31 |
| 31 namespace syncable { | 32 namespace syncable { |
| 32 class DirectoryManager; | 33 class DirectoryManager; |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace browser_sync { | 36 namespace browser_sync { |
| 36 | 37 |
| 37 class ConflictResolver; | 38 class ConflictResolver; |
| 38 class ExtensionsActivityMonitor; | 39 class ExtensionsActivityMonitor; |
| 39 class ModelSafeWorkerRegistrar; | 40 class ModelSafeWorkerRegistrar; |
| 40 class ServerConnectionManager; | 41 class ServerConnectionManager; |
| 41 | 42 |
| 42 // Default number of items a client can commit in a single message. | 43 // Default number of items a client can commit in a single message. |
| 43 static const int kDefaultMaxCommitBatchSize = 25; | 44 static const int kDefaultMaxCommitBatchSize = 25; |
| 44 | 45 |
| 45 namespace sessions { | 46 namespace sessions { |
| 46 class ScopedSessionContextConflictResolver; | 47 class ScopedSessionContextConflictResolver; |
| 48 class SyncSessionContextTest; | |
|
akalin
2011/11/23 03:44:33
there's actually no need to forward-declare for FR
| |
| 47 struct SyncSessionSnapshot; | 49 struct SyncSessionSnapshot; |
| 48 class TestScopedSessionEventListener; | 50 class TestScopedSessionEventListener; |
| 49 | 51 |
| 50 class SyncSessionContext { | 52 class SyncSessionContext { |
| 51 public: | 53 public: |
| 52 SyncSessionContext(ServerConnectionManager* connection_manager, | 54 SyncSessionContext(ServerConnectionManager* connection_manager, |
| 53 syncable::DirectoryManager* directory_manager, | 55 syncable::DirectoryManager* directory_manager, |
| 54 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 56 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 55 const std::vector<SyncEngineEventListener*>& listeners, | 57 const std::vector<SyncEngineEventListener*>& listeners, |
| 56 DebugInfoGetter* debug_info_getter); | 58 DebugInfoGetter* debug_info_getter); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { | 104 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { |
| 103 previous_session_routing_info_ = info; | 105 previous_session_routing_info_ = info; |
| 104 } | 106 } |
| 105 | 107 |
| 106 void NotifyListeners(const SyncEngineEvent& event) { | 108 void NotifyListeners(const SyncEngineEvent& event) { |
| 107 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, | 109 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, |
| 108 OnSyncEngineEvent(event)); | 110 OnSyncEngineEvent(event)); |
| 109 } | 111 } |
| 110 | 112 |
| 111 // This is virtual for unit tests. | 113 // 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, | 114 virtual void SetUnthrottleTime(const syncable::ModelTypeSet& types, |
| 115 const base::TimeTicks& time); | 115 const base::TimeTicks& time); |
| 116 | 116 |
| 117 void UpdateThrottledTypes(const base::TimeTicks& time); | |
|
akalin
2011/11/23 03:44:33
maybe a better name would be: "PruneUnthrottledTyp
| |
| 118 syncable::ModelTypeSet GetThrottledTypes() const; | |
|
akalin
2011/11/23 03:44:33
Add comment explaining what this does, and that it
| |
| 119 | |
| 117 private: | 120 private: |
| 118 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; | 121 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; |
| 119 | 122 |
| 123 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest); | |
| 124 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, | |
| 125 GetCurrentlyThrottledTypesTest); | |
| 126 | |
| 120 // Rather than force clients to set and null-out various context members, we | 127 // Rather than force clients to set and null-out various context members, we |
| 121 // extend our encapsulation boundary to scoped helpers that take care of this | 128 // extend our encapsulation boundary to scoped helpers that take care of this |
| 122 // once they are allocated. See definitions of these below. | 129 // once they are allocated. See definitions of these below. |
| 123 friend class ScopedSessionContextConflictResolver; | 130 friend class ScopedSessionContextConflictResolver; |
| 124 friend class TestScopedSessionEventListener; | 131 friend class TestScopedSessionEventListener; |
| 125 | 132 |
| 126 // This is installed by Syncer objects when needed and may be NULL. | 133 // This is installed by Syncer objects when needed and may be NULL. |
| 127 ConflictResolver* resolver_; | 134 ConflictResolver* resolver_; |
| 128 | 135 |
| 129 ObserverList<SyncEngineEventListener> listeners_; | 136 ObserverList<SyncEngineEventListener> listeners_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 private: | 193 private: |
| 187 SyncSessionContext* context_; | 194 SyncSessionContext* context_; |
| 188 ConflictResolver* resolver_; | 195 ConflictResolver* resolver_; |
| 189 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 196 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
| 190 }; | 197 }; |
| 191 | 198 |
| 192 } // namespace sessions | 199 } // namespace sessions |
| 193 } // namespace browser_sync | 200 } // namespace browser_sync |
| 194 | 201 |
| 195 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 202 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
| OLD | NEW |