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 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { | 103 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { |
103 previous_session_routing_info_ = info; | 104 previous_session_routing_info_ = info; |
104 } | 105 } |
105 | 106 |
106 void NotifyListeners(const SyncEngineEvent& event) { | 107 void NotifyListeners(const SyncEngineEvent& event) { |
107 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, | 108 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, |
108 OnSyncEngineEvent(event)); | 109 OnSyncEngineEvent(event)); |
109 } | 110 } |
110 | 111 |
111 // This is virtual for unit tests. | 112 // 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, | 113 virtual void SetUnthrottleTime(const syncable::ModelTypeSet& types, |
115 const base::TimeTicks& time); | 114 const base::TimeTicks& time); |
116 | 115 |
| 116 // This prunes the |unthrottle_time_| map based on the |time| passed in. This |
| 117 // is called by syncer at the SYNCER_BEGIN stage. |
| 118 void PruneUnthrottledTypes(const base::TimeTicks& time); |
| 119 |
| 120 // This returns the list of currently throttled types. Unless server returns |
| 121 // new throttled types this will remain constant through out the sync cycle. |
| 122 syncable::ModelTypeSet GetThrottledTypes() const; |
| 123 |
117 private: | 124 private: |
118 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; | 125 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; |
119 | 126 |
| 127 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest); |
| 128 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, |
| 129 GetCurrentlyThrottledTypesTest); |
| 130 |
120 // Rather than force clients to set and null-out various context members, we | 131 // 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 | 132 // extend our encapsulation boundary to scoped helpers that take care of this |
122 // once they are allocated. See definitions of these below. | 133 // once they are allocated. See definitions of these below. |
123 friend class ScopedSessionContextConflictResolver; | 134 friend class ScopedSessionContextConflictResolver; |
124 friend class TestScopedSessionEventListener; | 135 friend class TestScopedSessionEventListener; |
125 | 136 |
126 // This is installed by Syncer objects when needed and may be NULL. | 137 // This is installed by Syncer objects when needed and may be NULL. |
127 ConflictResolver* resolver_; | 138 ConflictResolver* resolver_; |
128 | 139 |
129 ObserverList<SyncEngineEventListener> listeners_; | 140 ObserverList<SyncEngineEventListener> listeners_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 private: | 197 private: |
187 SyncSessionContext* context_; | 198 SyncSessionContext* context_; |
188 ConflictResolver* resolver_; | 199 ConflictResolver* resolver_; |
189 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); | 200 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); |
190 }; | 201 }; |
191 | 202 |
192 } // namespace sessions | 203 } // namespace sessions |
193 } // namespace browser_sync | 204 } // namespace browser_sync |
194 | 205 |
195 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | 206 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ |
OLD | NEW |