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.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
enabled_types() const {
66 return enabled_types_
;
69 void SetRoutingInfo(const ModelSafeRoutingInfo
& routing_info
);
71 ExtensionsActivity
* extensions_activity() {
72 return extensions_activity_
.get();
75 DebugInfoGetter
* debug_info_getter() {
76 return debug_info_getter_
;
79 // Talk notification status.
80 void set_notifications_enabled(bool enabled
) {
81 notifications_enabled_
= enabled
;
83 bool notifications_enabled() { return notifications_enabled_
; }
85 // Account name, set once a directory has been opened.
86 void set_account_name(const std::string
& name
) {
87 DCHECK(account_name_
.empty());
90 const std::string
& account_name() const { return account_name_
; }
92 void set_max_commit_batch_size(int batch_size
) {
93 max_commit_batch_size_
= batch_size
;
95 int32
max_commit_batch_size() const { return max_commit_batch_size_
; }
97 void NotifyListeners(const SyncEngineEvent
& event
) {
98 FOR_EACH_OBSERVER(SyncEngineEventListener
, listeners_
,
99 OnSyncEngineEvent(event
));
102 TrafficRecorder
* traffic_recorder() {
103 return traffic_recorder_
;
106 bool keystore_encryption_enabled() const {
107 return keystore_encryption_enabled_
;
110 void set_hierarchy_conflict_detected(bool value
) {
111 client_status_
.set_hierarchy_conflict_detected(value
);
114 const sync_pb::ClientStatus
& client_status() const {
115 return client_status_
;
118 const std::string
& invalidator_client_id() const {
119 return invalidator_client_id_
;
122 bool ShouldFetchUpdatesBeforeCommit() const {
123 return !(server_enabled_pre_commit_update_avoidance_
||
124 client_enabled_pre_commit_update_avoidance_
);
127 void set_server_enabled_pre_commit_update_avoidance(bool value
) {
128 server_enabled_pre_commit_update_avoidance_
= value
;
131 ModelTypeRegistry
* model_type_registry() {
132 return model_type_registry_
;
136 // Rather than force clients to set and null-out various context members, we
137 // extend our encapsulation boundary to scoped helpers that take care of this
138 // once they are allocated. See definitions of these below.
139 friend class TestScopedSessionEventListener
;
141 ObserverList
<SyncEngineEventListener
> listeners_
;
143 ServerConnectionManager
* const connection_manager_
;
144 syncable::Directory
* const directory_
;
146 // The set of enabled types. Derrived from the routing info set with
147 // set_routing_info().
148 ModelTypeSet enabled_types_
;
150 // We use this to stuff extensions activity into CommitMessages so the server
151 // can correlate commit traffic with extension-related bookmark mutations.
152 scoped_refptr
<ExtensionsActivity
> extensions_activity_
;
154 // Kept up to date with talk events to determine whether notifications are
155 // enabled. True only if the notification channel is authorized and open.
156 bool notifications_enabled_
;
158 // The name of the account being synced.
159 std::string account_name_
;
161 // The server limits the number of items a client can commit in one batch.
162 int max_commit_batch_size_
;
164 // We use this to get debug info to send to the server for debugging
165 // client behavior on server side.
166 DebugInfoGetter
* const debug_info_getter_
;
168 TrafficRecorder
* traffic_recorder_
;
170 ModelTypeRegistry
* model_type_registry_
;
172 // Satus information to be sent up to the server.
173 sync_pb::ClientStatus client_status_
;
175 // Temporary variable while keystore encryption is behind a flag. True if
176 // we should attempt performing keystore encryption related work, false if
177 // the experiment is not enabled.
178 bool keystore_encryption_enabled_
;
180 // This is a copy of the identifier the that the invalidations client used to
181 // register itself with the invalidations server during startup. We need to
182 // provide this to the sync server when we make changes to enable it to
183 // prevent us from receiving notifications of changes we make ourselves.
184 const std::string invalidator_client_id_
;
186 // Flag to enable or disable the no pre-commit GetUpdates experiment. When
187 // this flag is set to false, the syncer has the option of not performing at
188 // GetUpdates request when there is nothing to fetch.
189 bool server_enabled_pre_commit_update_avoidance_
;
191 // If true, indicates that we've been passed a command-line flag to force
192 // enable the pre-commit update avoidance experiment described above.
193 const bool client_enabled_pre_commit_update_avoidance_
;
195 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext
);
198 } // namespace sessions
199 } // namespace syncer
201 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_