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

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

Issue 93433006: sync: Introduce ModelTypeRegistry and helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leak in tests Created 6 years, 11 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/sessions/model_type_registry_unittest.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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. Unlike the SyncSession, the context 6 // components specific to a SyncSession. Unlike the SyncSession, the context
7 // can be reused across several sync cycles. 7 // can be reused across several sync cycles.
8 // 8 //
9 // The context does not take ownership of its pointer members. It's up to 9 // The context does not take ownership of its pointer members. It's up to
10 // the surrounding classes to ensure those members remain valid while the 10 // the surrounding classes to ensure those members remain valid while the
11 // context is in use. 11 // context is in use.
12 // 12 //
13 // It can only be used from the SyncerThread. 13 // It can only be used from the SyncerThread.
14 14
15 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 15 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
16 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 16 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
17 17
18 #include <map>
19 #include <string> 18 #include <string>
20 #include <vector>
21 19
22 #include "base/stl_util.h"
23 #include "sync/base/sync_export.h" 20 #include "sync/base/sync_export.h"
24 #include "sync/engine/sync_directory_commit_contributor.h"
25 #include "sync/engine/sync_directory_update_handler.h"
26 #include "sync/engine/sync_engine_event.h" 21 #include "sync/engine/sync_engine_event.h"
27 #include "sync/engine/syncer_types.h"
28 #include "sync/engine/traffic_recorder.h" 22 #include "sync/engine/traffic_recorder.h"
29 #include "sync/internal_api/public/engine/model_safe_worker.h"
30 #include "sync/protocol/sync.pb.h"
31 #include "sync/sessions/debug_info_getter.h" 23 #include "sync/sessions/debug_info_getter.h"
24 #include "sync/sessions/model_type_registry.h"
32 25
33 namespace syncer { 26 namespace syncer {
34 27
35 class ExtensionsActivity; 28 class ExtensionsActivity;
29 class ModelTypeRegistry;
36 class ServerConnectionManager; 30 class ServerConnectionManager;
37 31
38 namespace syncable { 32 namespace syncable {
39 class Directory; 33 class Directory;
40 } 34 }
41 35
42 // Default number of items a client can commit in a single message. 36 // Default number of items a client can commit in a single message.
43 static const int kDefaultMaxCommitBatchSize = 25; 37 static const int kDefaultMaxCommitBatchSize = 25;
44 38
45 namespace sessions { 39 namespace sessions {
46 class TestScopedSessionEventListener; 40 class TestScopedSessionEventListener;
47 41
48 class SYNC_EXPORT_PRIVATE SyncSessionContext { 42 class SYNC_EXPORT_PRIVATE SyncSessionContext {
49 public: 43 public:
50 SyncSessionContext( 44 SyncSessionContext(
51 ServerConnectionManager* connection_manager, 45 ServerConnectionManager* connection_manager,
52 syncable::Directory* directory, 46 syncable::Directory* directory,
53 const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
54 ExtensionsActivity* extensions_activity, 47 ExtensionsActivity* extensions_activity,
55 const std::vector<SyncEngineEventListener*>& listeners, 48 const std::vector<SyncEngineEventListener*>& listeners,
56 DebugInfoGetter* debug_info_getter, 49 DebugInfoGetter* debug_info_getter,
57 TrafficRecorder* traffic_recorder, 50 TrafficRecorder* traffic_recorder,
51 ModelTypeRegistry* model_type_registry,
58 bool keystore_encryption_enabled, 52 bool keystore_encryption_enabled,
59 bool client_enabled_pre_commit_update_avoidance, 53 bool client_enabled_pre_commit_update_avoidance,
60 const std::string& invalidator_client_id); 54 const std::string& invalidator_client_id);
61 55
62 ~SyncSessionContext(); 56 ~SyncSessionContext();
63 57
64 ServerConnectionManager* connection_manager() { 58 ServerConnectionManager* connection_manager() {
65 return connection_manager_; 59 return connection_manager_;
66 } 60 }
67 syncable::Directory* directory() { 61 syncable::Directory* directory() {
68 return directory_; 62 return directory_;
69 } 63 }
70 64
71 ModelTypeSet enabled_types() const { 65 ModelTypeSet enabled_types() const {
72 return enabled_types_; 66 return enabled_types_;
73 } 67 }
74 68
75 void set_routing_info(const ModelSafeRoutingInfo& routing_info); 69 void SetRoutingInfo(const ModelSafeRoutingInfo& routing_info);
76
77 UpdateHandlerMap* update_handler_map() {
78 return &update_handler_map_;
79 }
80
81 CommitContributorMap* commit_contributor_map() {
82 return &commit_contributor_map_;
83 }
84 70
85 ExtensionsActivity* extensions_activity() { 71 ExtensionsActivity* extensions_activity() {
86 return extensions_activity_.get(); 72 return extensions_activity_.get();
87 } 73 }
88 74
89 DebugInfoGetter* debug_info_getter() { 75 DebugInfoGetter* debug_info_getter() {
90 return debug_info_getter_; 76 return debug_info_getter_;
91 } 77 }
92 78
93 // Talk notification status. 79 // Talk notification status.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 121
136 bool ShouldFetchUpdatesBeforeCommit() const { 122 bool ShouldFetchUpdatesBeforeCommit() const {
137 return !(server_enabled_pre_commit_update_avoidance_ || 123 return !(server_enabled_pre_commit_update_avoidance_ ||
138 client_enabled_pre_commit_update_avoidance_); 124 client_enabled_pre_commit_update_avoidance_);
139 } 125 }
140 126
141 void set_server_enabled_pre_commit_update_avoidance(bool value) { 127 void set_server_enabled_pre_commit_update_avoidance(bool value) {
142 server_enabled_pre_commit_update_avoidance_ = value; 128 server_enabled_pre_commit_update_avoidance_ = value;
143 } 129 }
144 130
131 ModelTypeRegistry* model_type_registry() {
132 return model_type_registry_;
133 }
134
145 private: 135 private:
146 // Rather than force clients to set and null-out various context members, we 136 // Rather than force clients to set and null-out various context members, we
147 // extend our encapsulation boundary to scoped helpers that take care of this 137 // extend our encapsulation boundary to scoped helpers that take care of this
148 // once they are allocated. See definitions of these below. 138 // once they are allocated. See definitions of these below.
149 friend class TestScopedSessionEventListener; 139 friend class TestScopedSessionEventListener;
150 140
151 ObserverList<SyncEngineEventListener> listeners_; 141 ObserverList<SyncEngineEventListener> listeners_;
152 142
153 ServerConnectionManager* const connection_manager_; 143 ServerConnectionManager* const connection_manager_;
154 syncable::Directory* const directory_; 144 syncable::Directory* const directory_;
155 145
156 // The set of enabled types. Derrived from the routing info set with 146 // The set of enabled types. Derrived from the routing info set with
157 // set_routing_info(). 147 // set_routing_info().
158 ModelTypeSet enabled_types_; 148 ModelTypeSet enabled_types_;
159 149
160 // A map of 'update handlers', one for each enabled type.
161 // This must be kept in sync with the routing info. Our temporary solution to
162 // that problem is to initialize this map in set_routing_info().
163 UpdateHandlerMap update_handler_map_;
164
165 // Deleter for the |update_handler_map_|.
166 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_;
167
168 // A map of 'commit contributors', one for each enabled type.
169 // This must be kept in sync with the routing info. Our temporary solution to
170 // that problem is to initialize this map in set_routing_info().
171 CommitContributorMap commit_contributor_map_;
172
173 // Deleter for the |commit_contributor_map_|.
174 STLValueDeleter<CommitContributorMap> commit_contributor_deleter_;
175
176 // The set of ModelSafeWorkers. Used to execute tasks of various threads.
177 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_;
178
179 // We use this to stuff extensions activity into CommitMessages so the server 150 // We use this to stuff extensions activity into CommitMessages so the server
180 // can correlate commit traffic with extension-related bookmark mutations. 151 // can correlate commit traffic with extension-related bookmark mutations.
181 scoped_refptr<ExtensionsActivity> extensions_activity_; 152 scoped_refptr<ExtensionsActivity> extensions_activity_;
182 153
183 // Kept up to date with talk events to determine whether notifications are 154 // Kept up to date with talk events to determine whether notifications are
184 // enabled. True only if the notification channel is authorized and open. 155 // enabled. True only if the notification channel is authorized and open.
185 bool notifications_enabled_; 156 bool notifications_enabled_;
186 157
187 // The name of the account being synced. 158 // The name of the account being synced.
188 std::string account_name_; 159 std::string account_name_;
189 160
190 // The server limits the number of items a client can commit in one batch. 161 // The server limits the number of items a client can commit in one batch.
191 int max_commit_batch_size_; 162 int max_commit_batch_size_;
192 163
193 // We use this to get debug info to send to the server for debugging 164 // We use this to get debug info to send to the server for debugging
194 // client behavior on server side. 165 // client behavior on server side.
195 DebugInfoGetter* const debug_info_getter_; 166 DebugInfoGetter* const debug_info_getter_;
196 167
197 TrafficRecorder* traffic_recorder_; 168 TrafficRecorder* traffic_recorder_;
198 169
170 ModelTypeRegistry* model_type_registry_;
171
199 // Satus information to be sent up to the server. 172 // Satus information to be sent up to the server.
200 sync_pb::ClientStatus client_status_; 173 sync_pb::ClientStatus client_status_;
201 174
202 // Temporary variable while keystore encryption is behind a flag. True if 175 // Temporary variable while keystore encryption is behind a flag. True if
203 // we should attempt performing keystore encryption related work, false if 176 // we should attempt performing keystore encryption related work, false if
204 // the experiment is not enabled. 177 // the experiment is not enabled.
205 bool keystore_encryption_enabled_; 178 bool keystore_encryption_enabled_;
206 179
207 // This is a copy of the identifier the that the invalidations client used to 180 // This is a copy of the identifier the that the invalidations client used to
208 // register itself with the invalidations server during startup. We need to 181 // register itself with the invalidations server during startup. We need to
(...skipping 10 matching lines...) Expand all
219 // enable the pre-commit update avoidance experiment described above. 192 // enable the pre-commit update avoidance experiment described above.
220 const bool client_enabled_pre_commit_update_avoidance_; 193 const bool client_enabled_pre_commit_update_avoidance_;
221 194
222 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); 195 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
223 }; 196 };
224 197
225 } // namespace sessions 198 } // namespace sessions
226 } // namespace syncer 199 } // namespace syncer
227 200
228 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 201 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
OLDNEW
« no previous file with comments | « sync/sessions/model_type_registry_unittest.cc ('k') | sync/sessions/sync_session_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698