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

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: Add missing files 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
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" 21 #include "sync/engine/model_type_registry.h"
25 #include "sync/engine/sync_directory_update_handler.h"
26 #include "sync/engine/sync_engine_event.h" 22 #include "sync/engine/sync_engine_event.h"
27 #include "sync/engine/syncer_types.h"
28 #include "sync/engine/traffic_recorder.h" 23 #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" 24 #include "sync/sessions/debug_info_getter.h"
32 25
33 namespace syncer { 26 namespace syncer {
34 27
35 class ExtensionsActivity; 28 class ExtensionsActivity;
36 class ServerConnectionManager; 29 class ServerConnectionManager;
30 class ModelTypeRegistry;
Nicolas Zea 2014/01/04 02:09:34 nit: abc order
rlarocque 2014/01/06 20:03:33 Done.
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(ServerConnectionManager* connection_manager, 44 SyncSessionContext(ServerConnectionManager* connection_manager,
51 syncable::Directory* directory, 45 syncable::Directory* directory,
52 const std::vector<ModelSafeWorker*>& workers,
53 ExtensionsActivity* extensions_activity, 46 ExtensionsActivity* extensions_activity,
54 const std::vector<SyncEngineEventListener*>& listeners, 47 const std::vector<SyncEngineEventListener*>& listeners,
55 DebugInfoGetter* debug_info_getter, 48 DebugInfoGetter* debug_info_getter,
56 TrafficRecorder* traffic_recorder, 49 TrafficRecorder* traffic_recorder,
50 ModelTypeRegistry* model_type_registry,
57 bool keystore_encryption_enabled, 51 bool keystore_encryption_enabled,
58 bool client_enabled_pre_commit_update_avoidance, 52 bool client_enabled_pre_commit_update_avoidance,
59 const std::string& invalidator_client_id); 53 const std::string& invalidator_client_id);
60 54
61 ~SyncSessionContext(); 55 ~SyncSessionContext();
62 56
63 ServerConnectionManager* connection_manager() { 57 ServerConnectionManager* connection_manager() {
64 return connection_manager_; 58 return connection_manager_;
65 } 59 }
66 syncable::Directory* directory() { 60 syncable::Directory* directory() {
67 return directory_; 61 return directory_;
68 } 62 }
69 63
70 ModelTypeSet enabled_types() const { 64 ModelTypeSet enabled_types() const {
71 return enabled_types_; 65 return enabled_types_;
72 } 66 }
73 67
74 void set_routing_info(const ModelSafeRoutingInfo& routing_info); 68 void SetRoutingInfo(const ModelSafeRoutingInfo& routing_info);
75
76 UpdateHandlerMap* update_handler_map() {
77 return &update_handler_map_;
78 }
79
80 CommitContributorMap* commit_contributor_map() {
81 return &commit_contributor_map_;
82 }
83 69
84 ExtensionsActivity* extensions_activity() { 70 ExtensionsActivity* extensions_activity() {
85 return extensions_activity_.get(); 71 return extensions_activity_.get();
86 } 72 }
87 73
88 DebugInfoGetter* debug_info_getter() { 74 DebugInfoGetter* debug_info_getter() {
89 return debug_info_getter_; 75 return debug_info_getter_;
90 } 76 }
91 77
92 // Talk notification status. 78 // Talk notification status.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 120
135 bool ShouldFetchUpdatesBeforeCommit() const { 121 bool ShouldFetchUpdatesBeforeCommit() const {
136 return !(server_enabled_pre_commit_update_avoidance_ || 122 return !(server_enabled_pre_commit_update_avoidance_ ||
137 client_enabled_pre_commit_update_avoidance_); 123 client_enabled_pre_commit_update_avoidance_);
138 } 124 }
139 125
140 void set_server_enabled_pre_commit_update_avoidance(bool value) { 126 void set_server_enabled_pre_commit_update_avoidance(bool value) {
141 server_enabled_pre_commit_update_avoidance_ = value; 127 server_enabled_pre_commit_update_avoidance_ = value;
142 } 128 }
143 129
130 UpdaterList* updater_list() {
131 return model_type_registry_->updater_list();
132 }
133
134 CommitterList* committer_list() {
135 return model_type_registry_->committer_list();
136 }
137
144 private: 138 private:
145 // Rather than force clients to set and null-out various context members, we 139 // Rather than force clients to set and null-out various context members, we
146 // extend our encapsulation boundary to scoped helpers that take care of this 140 // extend our encapsulation boundary to scoped helpers that take care of this
147 // once they are allocated. See definitions of these below. 141 // once they are allocated. See definitions of these below.
148 friend class TestScopedSessionEventListener; 142 friend class TestScopedSessionEventListener;
149 143
150 ObserverList<SyncEngineEventListener> listeners_; 144 ObserverList<SyncEngineEventListener> listeners_;
151 145
152 ServerConnectionManager* const connection_manager_; 146 ServerConnectionManager* const connection_manager_;
153 syncable::Directory* const directory_; 147 syncable::Directory* const directory_;
154 148
155 // The set of enabled types. Derrived from the routing info set with 149 // The set of enabled types. Derrived from the routing info set with
156 // set_routing_info(). 150 // set_routing_info().
157 ModelTypeSet enabled_types_; 151 ModelTypeSet enabled_types_;
158 152
159 // A map of 'update handlers', one for each enabled type.
160 // This must be kept in sync with the routing info. Our temporary solution to
161 // that problem is to initialize this map in set_routing_info().
162 UpdateHandlerMap update_handler_map_;
163
164 // Deleter for the |update_handler_map_|.
165 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_;
166
167 // A map of 'commit contributors', one for each enabled type.
168 // This must be kept in sync with the routing info. Our temporary solution to
169 // that problem is to initialize this map in set_routing_info().
170 CommitContributorMap commit_contributor_map_;
171
172 // Deleter for the |commit_contributor_map_|.
173 STLValueDeleter<CommitContributorMap> commit_contributor_deleter_;
174
175 // The set of ModelSafeWorkers. Used to execute tasks of various threads.
176 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> > workers_;
177
178 // We use this to stuff extensions activity into CommitMessages so the server 153 // We use this to stuff extensions activity into CommitMessages so the server
179 // can correlate commit traffic with extension-related bookmark mutations. 154 // can correlate commit traffic with extension-related bookmark mutations.
180 scoped_refptr<ExtensionsActivity> extensions_activity_; 155 scoped_refptr<ExtensionsActivity> extensions_activity_;
181 156
182 // Kept up to date with talk events to determine whether notifications are 157 // Kept up to date with talk events to determine whether notifications are
183 // enabled. True only if the notification channel is authorized and open. 158 // enabled. True only if the notification channel is authorized and open.
184 bool notifications_enabled_; 159 bool notifications_enabled_;
185 160
186 // The name of the account being synced. 161 // The name of the account being synced.
187 std::string account_name_; 162 std::string account_name_;
188 163
189 // 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.
190 int max_commit_batch_size_; 165 int max_commit_batch_size_;
191 166
192 // We use this to get debug info to send to the server for debugging 167 // We use this to get debug info to send to the server for debugging
193 // client behavior on server side. 168 // client behavior on server side.
194 DebugInfoGetter* const debug_info_getter_; 169 DebugInfoGetter* const debug_info_getter_;
195 170
196 TrafficRecorder* traffic_recorder_; 171 TrafficRecorder* traffic_recorder_;
197 172
173 ModelTypeRegistry* model_type_registry_;
174
198 // Satus information to be sent up to the server. 175 // Satus information to be sent up to the server.
199 sync_pb::ClientStatus client_status_; 176 sync_pb::ClientStatus client_status_;
200 177
201 // Temporary variable while keystore encryption is behind a flag. True if 178 // Temporary variable while keystore encryption is behind a flag. True if
202 // we should attempt performing keystore encryption related work, false if 179 // we should attempt performing keystore encryption related work, false if
203 // the experiment is not enabled. 180 // the experiment is not enabled.
204 bool keystore_encryption_enabled_; 181 bool keystore_encryption_enabled_;
205 182
206 // This is a copy of the identifier the that the invalidations client used to 183 // This is a copy of the identifier the that the invalidations client used to
207 // register itself with the invalidations server during startup. We need to 184 // register itself with the invalidations server during startup. We need to
(...skipping 10 matching lines...) Expand all
218 // enable the pre-commit update avoidance experiment described above. 195 // enable the pre-commit update avoidance experiment described above.
219 const bool client_enabled_pre_commit_update_avoidance_; 196 const bool client_enabled_pre_commit_update_avoidance_;
220 197
221 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); 198 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
222 }; 199 };
223 200
224 } // namespace sessions 201 } // namespace sessions
225 } // namespace syncer 202 } // namespace syncer
226 203
227 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 204 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698