Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / sync / sessions / sync_session_context.h
blob7fa417359ad23020afce3f43d26a46599c519de3
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.
8 //
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
11 // context is in use.
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_
18 #include <string>
20 #include "sync/base/sync_export.h"
21 #include "sync/engine/sync_engine_event_listener.h"
22 #include "sync/sessions/debug_info_getter.h"
23 #include "sync/sessions/model_type_registry.h"
25 namespace syncer {
27 class ExtensionsActivity;
28 class ModelTypeRegistry;
29 class ServerConnectionManager;
31 namespace syncable {
32 class Directory;
35 // Default number of items a client can commit in a single message.
36 static const int kDefaultMaxCommitBatchSize = 25;
38 namespace sessions {
39 class TestScopedSessionEventListener;
41 class SYNC_EXPORT_PRIVATE SyncSessionContext {
42 public:
43 SyncSessionContext(
44 ServerConnectionManager* connection_manager,
45 syncable::Directory* directory,
46 ExtensionsActivity* extensions_activity,
47 const std::vector<SyncEngineEventListener*>& listeners,
48 DebugInfoGetter* debug_info_getter,
49 ModelTypeRegistry* model_type_registry,
50 bool keystore_encryption_enabled,
51 bool client_enabled_pre_commit_update_avoidance,
52 const std::string& invalidator_client_id);
54 ~SyncSessionContext();
56 ServerConnectionManager* connection_manager() {
57 return connection_manager_;
59 syncable::Directory* directory() {
60 return directory_;
63 ModelTypeSet GetEnabledTypes() const;
65 void SetRoutingInfo(const ModelSafeRoutingInfo& routing_info);
67 ExtensionsActivity* extensions_activity() {
68 return extensions_activity_.get();
71 DebugInfoGetter* debug_info_getter() {
72 return debug_info_getter_;
75 // Talk notification status.
76 void set_notifications_enabled(bool enabled) {
77 notifications_enabled_ = enabled;
79 bool notifications_enabled() { return notifications_enabled_; }
81 // Account name, set once a directory has been opened.
82 void set_account_name(const std::string& name) {
83 DCHECK(account_name_.empty());
84 account_name_ = name;
86 const std::string& account_name() const { return account_name_; }
88 void set_max_commit_batch_size(int batch_size) {
89 max_commit_batch_size_ = batch_size;
91 int32 max_commit_batch_size() const { return max_commit_batch_size_; }
93 ObserverList<SyncEngineEventListener>* listeners() {
94 return &listeners_;
97 bool keystore_encryption_enabled() const {
98 return keystore_encryption_enabled_;
101 void set_hierarchy_conflict_detected(bool value) {
102 client_status_.set_hierarchy_conflict_detected(value);
105 const sync_pb::ClientStatus& client_status() const {
106 return client_status_;
109 const std::string& invalidator_client_id() const {
110 return invalidator_client_id_;
113 bool ShouldFetchUpdatesBeforeCommit() const {
114 return !(server_enabled_pre_commit_update_avoidance_ ||
115 client_enabled_pre_commit_update_avoidance_);
118 void set_server_enabled_pre_commit_update_avoidance(bool value) {
119 server_enabled_pre_commit_update_avoidance_ = value;
122 ModelTypeRegistry* model_type_registry() {
123 return model_type_registry_;
126 private:
127 // Rather than force clients to set and null-out various context members, we
128 // extend our encapsulation boundary to scoped helpers that take care of this
129 // once they are allocated. See definitions of these below.
130 friend class TestScopedSessionEventListener;
132 ObserverList<SyncEngineEventListener> listeners_;
134 ServerConnectionManager* const connection_manager_;
135 syncable::Directory* const directory_;
137 // We use this to stuff extensions activity into CommitMessages so the server
138 // can correlate commit traffic with extension-related bookmark mutations.
139 scoped_refptr<ExtensionsActivity> extensions_activity_;
141 // Kept up to date with talk events to determine whether notifications are
142 // enabled. True only if the notification channel is authorized and open.
143 bool notifications_enabled_;
145 // The name of the account being synced.
146 std::string account_name_;
148 // The server limits the number of items a client can commit in one batch.
149 int max_commit_batch_size_;
151 // We use this to get debug info to send to the server for debugging
152 // client behavior on server side.
153 DebugInfoGetter* const debug_info_getter_;
155 ModelTypeRegistry* model_type_registry_;
157 // Satus information to be sent up to the server.
158 sync_pb::ClientStatus client_status_;
160 // Temporary variable while keystore encryption is behind a flag. True if
161 // we should attempt performing keystore encryption related work, false if
162 // the experiment is not enabled.
163 bool keystore_encryption_enabled_;
165 // This is a copy of the identifier the that the invalidations client used to
166 // register itself with the invalidations server during startup. We need to
167 // provide this to the sync server when we make changes to enable it to
168 // prevent us from receiving notifications of changes we make ourselves.
169 const std::string invalidator_client_id_;
171 // Flag to enable or disable the no pre-commit GetUpdates experiment. When
172 // this flag is set to false, the syncer has the option of not performing at
173 // GetUpdates request when there is nothing to fetch.
174 bool server_enabled_pre_commit_update_avoidance_;
176 // If true, indicates that we've been passed a command-line flag to force
177 // enable the pre-commit update avoidance experiment described above.
178 const bool client_enabled_pre_commit_update_avoidance_;
180 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
183 } // namespace sessions
184 } // namespace syncer
186 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_