Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: sync/sessions/sync_session_context.h

Issue 10454105: sync: Refactor per-datatype throttling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/sync_manager.cc ('k') | sync/sessions/sync_session_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/sync_engine_event.h" 27 #include "sync/engine/sync_engine_event.h"
29 #include "sync/engine/syncer_types.h" 28 #include "sync/engine/syncer_types.h"
30 #include "sync/engine/traffic_recorder.h" 29 #include "sync/engine/traffic_recorder.h"
31 #include "sync/internal_api/public/engine/model_safe_worker.h" 30 #include "sync/internal_api/public/engine/model_safe_worker.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 ServerConnectionManager; 41 class ServerConnectionManager;
42 class ThrottledDataTypeTracker;
43 43
44 // Default number of items a client can commit in a single message. 44 // Default number of items a client can commit in a single message.
45 static const int kDefaultMaxCommitBatchSize = 25; 45 static const int kDefaultMaxCommitBatchSize = 25;
46 46
47 namespace sessions { 47 namespace sessions {
48 class ScopedSessionContextConflictResolver; 48 class ScopedSessionContextConflictResolver;
49 class TestScopedSessionEventListener; 49 class TestScopedSessionEventListener;
50 50
51 class SyncSessionContext { 51 class SyncSessionContext {
52 public: 52 public:
53 SyncSessionContext(ServerConnectionManager* connection_manager, 53 SyncSessionContext(ServerConnectionManager* connection_manager,
54 syncable::Directory* directory, 54 syncable::Directory* directory,
55 const ModelSafeRoutingInfo& model_safe_routing_info, 55 const ModelSafeRoutingInfo& model_safe_routing_info,
56 const std::vector<ModelSafeWorker*>& workers, 56 const std::vector<ModelSafeWorker*>& workers,
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();
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 const ModelSafeRoutingInfo& routing_info() const { 72 const ModelSafeRoutingInfo& routing_info() const {
75 return routing_info_; 73 return routing_info_;
76 } 74 }
77 75
78 void set_routing_info(const ModelSafeRoutingInfo& routing_info) { 76 void set_routing_info(const ModelSafeRoutingInfo& routing_info) {
79 routing_info_ = routing_info; 77 routing_info_ = routing_info;
80 } 78 }
81 79
82 const std::vector<ModelSafeWorker*> workers() const { 80 const std::vector<ModelSafeWorker*> workers() const {
83 return workers_; 81 return workers_;
84 } 82 }
85 83
86 ExtensionsActivityMonitor* extensions_monitor() { 84 ExtensionsActivityMonitor* extensions_monitor() {
87 return extensions_activity_monitor_; 85 return extensions_activity_monitor_;
88 } 86 }
89 87
88 ThrottledDataTypeTracker* throttled_data_type_tracker() {
89 return throttled_data_type_tracker_;
90 }
91
90 DebugInfoGetter* debug_info_getter() { 92 DebugInfoGetter* debug_info_getter() {
91 return debug_info_getter_; 93 return debug_info_getter_;
92 } 94 }
93 95
94 // Talk notification status. 96 // Talk notification status.
95 void set_notifications_enabled(bool enabled) { 97 void set_notifications_enabled(bool enabled) {
96 notifications_enabled_ = enabled; 98 notifications_enabled_ = enabled;
97 } 99 }
98 bool notifications_enabled() { return notifications_enabled_; } 100 bool notifications_enabled() { return notifications_enabled_; }
99 101
(...skipping 15 matching lines...) Expand all
115 117
116 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) { 118 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) {
117 previous_session_routing_info_ = info; 119 previous_session_routing_info_ = info;
118 } 120 }
119 121
120 void NotifyListeners(const SyncEngineEvent& event) { 122 void NotifyListeners(const SyncEngineEvent& event) {
121 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_, 123 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_,
122 OnSyncEngineEvent(event)); 124 OnSyncEngineEvent(event));
123 } 125 }
124 126
125 // This is virtual for unit tests.
126 virtual void SetUnthrottleTime(syncable::ModelTypeSet types,
127 const base::TimeTicks& time);
128
129 // This prunes the |unthrottle_time_| map based on the |time| passed in. This
130 // is called by syncer at the SYNCER_BEGIN stage.
131 void PruneUnthrottledTypes(const base::TimeTicks& time);
132
133 // This returns the list of currently throttled types. Unless server returns
134 // new throttled types this will remain constant through out the sync cycle.
135 syncable::ModelTypeSet GetThrottledTypes() const;
136
137 browser_sync::TrafficRecorder* traffic_recorder() { 127 browser_sync::TrafficRecorder* traffic_recorder() {
138 return traffic_recorder_; 128 return traffic_recorder_;
139 } 129 }
140 130
141 private: 131 private:
142 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes;
143
144 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest);
145 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest,
146 GetCurrentlyThrottledTypesTest);
147
148 // Rather than force clients to set and null-out various context members, we 132 // Rather than force clients to set and null-out various context members, we
149 // extend our encapsulation boundary to scoped helpers that take care of this 133 // extend our encapsulation boundary to scoped helpers that take care of this
150 // once they are allocated. See definitions of these below. 134 // once they are allocated. See definitions of these below.
151 friend class ScopedSessionContextConflictResolver; 135 friend class ScopedSessionContextConflictResolver;
152 friend class TestScopedSessionEventListener; 136 friend class TestScopedSessionEventListener;
153 137
154 // This is installed by Syncer objects when needed and may be NULL. 138 // This is installed by Syncer objects when needed and may be NULL.
155 ConflictResolver* resolver_; 139 ConflictResolver* resolver_;
156 140
157 ObserverList<SyncEngineEventListener> listeners_; 141 ObserverList<SyncEngineEventListener> listeners_;
(...skipping 19 matching lines...) Expand all
177 // The name of the account being synced. 161 // The name of the account being synced.
178 std::string account_name_; 162 std::string account_name_;
179 163
180 // The server limits the number of items a client can commit in one batch. 164 // The server limits the number of items a client can commit in one batch.
181 int max_commit_batch_size_; 165 int max_commit_batch_size_;
182 166
183 // Some routing info history to help us clean up types that get disabled 167 // Some routing info history to help us clean up types that get disabled
184 // by the user. 168 // by the user.
185 ModelSafeRoutingInfo previous_session_routing_info_; 169 ModelSafeRoutingInfo previous_session_routing_info_;
186 170
171 ThrottledDataTypeTracker* throttled_data_type_tracker_;
172
187 // We use this to get debug info to send to the server for debugging 173 // We use this to get debug info to send to the server for debugging
188 // client behavior on server side. 174 // client behavior on server side.
189 DebugInfoGetter* const debug_info_getter_; 175 DebugInfoGetter* const debug_info_getter_;
190 176
191 // This is a map from throttled data types to the time at which they can be
192 // unthrottled.
193 UnthrottleTimes unthrottle_times_;
194
195 browser_sync::TrafficRecorder* traffic_recorder_; 177 browser_sync::TrafficRecorder* traffic_recorder_;
196 178
197 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); 179 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
198 }; 180 };
199 181
200 // Installs a ConflictResolver to a given session context for the lifetime of 182 // Installs a ConflictResolver to a given session context for the lifetime of
201 // the ScopedSessionContextConflictResolver. There should never be more than 183 // the ScopedSessionContextConflictResolver. There should never be more than
202 // one ConflictResolver in the system, so it is an error to use this if the 184 // one ConflictResolver in the system, so it is an error to use this if the
203 // context already has a resolver. 185 // context already has a resolver.
204 class ScopedSessionContextConflictResolver { 186 class ScopedSessionContextConflictResolver {
(...skipping 12 matching lines...) Expand all
217 private: 199 private:
218 SyncSessionContext* context_; 200 SyncSessionContext* context_;
219 ConflictResolver* resolver_; 201 ConflictResolver* resolver_;
220 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); 202 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver);
221 }; 203 };
222 204
223 } // namespace sessions 205 } // namespace sessions
224 } // namespace browser_sync 206 } // namespace browser_sync
225 207
226 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 208 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager.cc ('k') | sync/sessions/sync_session_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698