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
3 // found in the LICENSE file.
5 // SyncSessionContext encapsulates the contextual information and engine
6 // components specific to a SyncSession. Unlike the SyncSession, the context
7 // can be reused across several sync cycles.
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
13 // It can only be used from the SyncerThread.
15 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
16 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
20 #include "sync/base/sync_export.h"
21 #include "sync/engine/sync_engine_event_listener.h"
22 #include "sync/engine/traffic_recorder.h"
23 #include "sync/sessions/debug_info_getter.h"
24 #include "sync/sessions/model_type_registry.h"
28 class ExtensionsActivity;
29 class ModelTypeRegistry;
30 class ServerConnectionManager;
36 // Default number of items a client can commit in a single message.
37 static const int kDefaultMaxCommitBatchSize = 25;
40 class TestScopedSessionEventListener;
42 class SYNC_EXPORT_PRIVATE SyncSessionContext {
45 ServerConnectionManager* connection_manager,
46 syncable::Directory* directory,
47 ExtensionsActivity* extensions_activity,
48 const std::vector<SyncEngineEventListener*>& listeners,
49 DebugInfoGetter* debug_info_getter,
50 TrafficRecorder* traffic_recorder,
51 ModelTypeRegistry* model_type_registry,
52 bool keystore_encryption_enabled,
53 bool client_enabled_pre_commit_update_avoidance,
54 const std::string& invalidator_client_id);
56 ~SyncSessionContext();
58 ServerConnectionManager* connection_manager() {
59 return connection_manager_;
61 syncable::Directory* directory() {
65 ModelTypeSet GetEnabledTypes() const;
67 void SetRoutingInfo(const ModelSafeRoutingInfo& routing_info);
69 ExtensionsActivity* extensions_activity() {
70 return extensions_activity_.get();
73 DebugInfoGetter* debug_info_getter() {
74 return debug_info_getter_;
77 // Talk notification status.
78 void set_notifications_enabled(bool enabled) {
79 notifications_enabled_ = enabled;
81 bool notifications_enabled() { return notifications_enabled_; }
83 // Account name, set once a directory has been opened.
84 void set_account_name(const std::string& name) {
85 DCHECK(account_name_.empty());
88 const std::string& account_name() const { return account_name_; }
90 void set_max_commit_batch_size(int batch_size) {
91 max_commit_batch_size_ = batch_size;
93 int32 max_commit_batch_size() const { return max_commit_batch_size_; }
95 ObserverList<SyncEngineEventListener>* listeners() {
99 TrafficRecorder* traffic_recorder() {
100 return traffic_recorder_;
103 bool keystore_encryption_enabled() const {
104 return keystore_encryption_enabled_;
107 void set_hierarchy_conflict_detected(bool value) {
108 client_status_.set_hierarchy_conflict_detected(value);
111 const sync_pb::ClientStatus& client_status() const {
112 return client_status_;
115 const std::string& invalidator_client_id() const {
116 return invalidator_client_id_;
119 bool ShouldFetchUpdatesBeforeCommit() const {
120 return !(server_enabled_pre_commit_update_avoidance_ ||
121 client_enabled_pre_commit_update_avoidance_);
124 void set_server_enabled_pre_commit_update_avoidance(bool value) {
125 server_enabled_pre_commit_update_avoidance_ = value;
128 ModelTypeRegistry* model_type_registry() {
129 return model_type_registry_;
133 // Rather than force clients to set and null-out various context members, we
134 // extend our encapsulation boundary to scoped helpers that take care of this
135 // once they are allocated. See definitions of these below.
136 friend class TestScopedSessionEventListener;
138 ObserverList<SyncEngineEventListener> listeners_;
140 ServerConnectionManager* const connection_manager_;
141 syncable::Directory* const directory_;
143 // We use this to stuff extensions activity into CommitMessages so the server
144 // can correlate commit traffic with extension-related bookmark mutations.
145 scoped_refptr<ExtensionsActivity> extensions_activity_;
147 // Kept up to date with talk events to determine whether notifications are
148 // enabled. True only if the notification channel is authorized and open.
149 bool notifications_enabled_;
151 // The name of the account being synced.
152 std::string account_name_;
154 // The server limits the number of items a client can commit in one batch.
155 int max_commit_batch_size_;
157 // We use this to get debug info to send to the server for debugging
158 // client behavior on server side.
159 DebugInfoGetter* const debug_info_getter_;
161 TrafficRecorder* traffic_recorder_;
163 ModelTypeRegistry* model_type_registry_;
165 // Satus information to be sent up to the server.
166 sync_pb::ClientStatus client_status_;
168 // Temporary variable while keystore encryption is behind a flag. True if
169 // we should attempt performing keystore encryption related work, false if
170 // the experiment is not enabled.
171 bool keystore_encryption_enabled_;
173 // This is a copy of the identifier the that the invalidations client used to
174 // register itself with the invalidations server during startup. We need to
175 // provide this to the sync server when we make changes to enable it to
176 // prevent us from receiving notifications of changes we make ourselves.
177 const std::string invalidator_client_id_;
179 // Flag to enable or disable the no pre-commit GetUpdates experiment. When
180 // this flag is set to false, the syncer has the option of not performing at
181 // GetUpdates request when there is nothing to fetch.
182 bool server_enabled_pre_commit_update_avoidance_;
184 // If true, indicates that we've been passed a command-line flag to force
185 // enable the pre-commit update avoidance experiment described above.
186 const bool client_enabled_pre_commit_update_avoidance_;
188 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
191 } // namespace sessions
192 } // namespace syncer
194 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_