| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 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. | |
| 12 // | |
| 13 // It can only be used from the SyncerThread. | |
| 14 | |
| 15 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | |
| 16 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | |
| 17 | |
| 18 #include <stdint.h> | |
| 19 | |
| 20 #include <string> | |
| 21 #include <vector> | |
| 22 | |
| 23 #include "base/macros.h" | |
| 24 #include "sync/base/sync_export.h" | |
| 25 #include "sync/engine/sync_engine_event_listener.h" | |
| 26 #include "sync/sessions/debug_info_getter.h" | |
| 27 #include "sync/sessions/model_type_registry.h" | |
| 28 | |
| 29 namespace syncer { | |
| 30 | |
| 31 class ExtensionsActivity; | |
| 32 class ModelTypeRegistry; | |
| 33 class ServerConnectionManager; | |
| 34 | |
| 35 namespace syncable { | |
| 36 class Directory; | |
| 37 } | |
| 38 | |
| 39 // Default number of items a client can commit in a single message. | |
| 40 static const int kDefaultMaxCommitBatchSize = 25; | |
| 41 | |
| 42 namespace sessions { | |
| 43 class TestScopedSessionEventListener; | |
| 44 | |
| 45 class SYNC_EXPORT SyncSessionContext { | |
| 46 public: | |
| 47 SyncSessionContext( | |
| 48 ServerConnectionManager* connection_manager, | |
| 49 syncable::Directory* directory, | |
| 50 ExtensionsActivity* extensions_activity, | |
| 51 const std::vector<SyncEngineEventListener*>& listeners, | |
| 52 DebugInfoGetter* debug_info_getter, | |
| 53 ModelTypeRegistry* model_type_registry, | |
| 54 bool keystore_encryption_enabled, | |
| 55 bool client_enabled_pre_commit_update_avoidance, | |
| 56 const std::string& invalidator_client_id); | |
| 57 | |
| 58 ~SyncSessionContext(); | |
| 59 | |
| 60 ServerConnectionManager* connection_manager() { | |
| 61 return connection_manager_; | |
| 62 } | |
| 63 syncable::Directory* directory() { | |
| 64 return directory_; | |
| 65 } | |
| 66 | |
| 67 ModelTypeSet GetEnabledTypes() const; | |
| 68 | |
| 69 void SetRoutingInfo(const ModelSafeRoutingInfo& routing_info); | |
| 70 | |
| 71 ExtensionsActivity* extensions_activity() { | |
| 72 return extensions_activity_.get(); | |
| 73 } | |
| 74 | |
| 75 DebugInfoGetter* debug_info_getter() { | |
| 76 return debug_info_getter_; | |
| 77 } | |
| 78 | |
| 79 // Talk notification status. | |
| 80 void set_notifications_enabled(bool enabled) { | |
| 81 notifications_enabled_ = enabled; | |
| 82 } | |
| 83 bool notifications_enabled() { return notifications_enabled_; } | |
| 84 | |
| 85 // Account name, set once a directory has been opened. | |
| 86 void set_account_name(const std::string& name) { | |
| 87 account_name_ = name; | |
| 88 } | |
| 89 const std::string& account_name() const { return account_name_; } | |
| 90 | |
| 91 void set_max_commit_batch_size(int batch_size) { | |
| 92 max_commit_batch_size_ = batch_size; | |
| 93 } | |
| 94 int32_t max_commit_batch_size() const { return max_commit_batch_size_; } | |
| 95 | |
| 96 base::ObserverList<SyncEngineEventListener>* listeners() { | |
| 97 return &listeners_; | |
| 98 } | |
| 99 | |
| 100 bool keystore_encryption_enabled() const { | |
| 101 return keystore_encryption_enabled_; | |
| 102 } | |
| 103 | |
| 104 void set_hierarchy_conflict_detected(bool value) { | |
| 105 client_status_.set_hierarchy_conflict_detected(value); | |
| 106 } | |
| 107 | |
| 108 const sync_pb::ClientStatus& client_status() const { | |
| 109 return client_status_; | |
| 110 } | |
| 111 | |
| 112 const std::string& invalidator_client_id() const { | |
| 113 return invalidator_client_id_; | |
| 114 } | |
| 115 | |
| 116 bool ShouldFetchUpdatesBeforeCommit() const { | |
| 117 return !(server_enabled_pre_commit_update_avoidance_ || | |
| 118 client_enabled_pre_commit_update_avoidance_); | |
| 119 } | |
| 120 | |
| 121 void set_server_enabled_pre_commit_update_avoidance(bool value) { | |
| 122 server_enabled_pre_commit_update_avoidance_ = value; | |
| 123 } | |
| 124 | |
| 125 ModelTypeRegistry* model_type_registry() { | |
| 126 return model_type_registry_; | |
| 127 } | |
| 128 | |
| 129 bool cookie_jar_mismatch() const { | |
| 130 return cookie_jar_mismatch_; | |
| 131 } | |
| 132 | |
| 133 void set_cookie_jar_mismatch(bool cookie_jar_mismatch) { | |
| 134 cookie_jar_mismatch_ = cookie_jar_mismatch; | |
| 135 } | |
| 136 | |
| 137 bool cookie_jar_empty() const { return cookie_jar_empty_; } | |
| 138 | |
| 139 void set_cookie_jar_empty(bool empty_jar) { cookie_jar_empty_ = empty_jar; } | |
| 140 | |
| 141 private: | |
| 142 // Rather than force clients to set and null-out various context members, we | |
| 143 // extend our encapsulation boundary to scoped helpers that take care of this | |
| 144 // once they are allocated. See definitions of these below. | |
| 145 friend class TestScopedSessionEventListener; | |
| 146 | |
| 147 base::ObserverList<SyncEngineEventListener> listeners_; | |
| 148 | |
| 149 ServerConnectionManager* const connection_manager_; | |
| 150 syncable::Directory* const directory_; | |
| 151 | |
| 152 // We use this to stuff extensions activity into CommitMessages so the server | |
| 153 // can correlate commit traffic with extension-related bookmark mutations. | |
| 154 scoped_refptr<ExtensionsActivity> extensions_activity_; | |
| 155 | |
| 156 // Kept up to date with talk events to determine whether notifications are | |
| 157 // enabled. True only if the notification channel is authorized and open. | |
| 158 bool notifications_enabled_; | |
| 159 | |
| 160 // The name of the account being synced. | |
| 161 std::string account_name_; | |
| 162 | |
| 163 // The server limits the number of items a client can commit in one batch. | |
| 164 int max_commit_batch_size_; | |
| 165 | |
| 166 // We use this to get debug info to send to the server for debugging | |
| 167 // client behavior on server side. | |
| 168 DebugInfoGetter* const debug_info_getter_; | |
| 169 | |
| 170 ModelTypeRegistry* model_type_registry_; | |
| 171 | |
| 172 // Satus information to be sent up to the server. | |
| 173 sync_pb::ClientStatus client_status_; | |
| 174 | |
| 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_; | |
| 179 | |
| 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_; | |
| 185 | |
| 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_; | |
| 190 | |
| 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_; | |
| 194 | |
| 195 // Whether the account(s) present in the content area's cookie jar match the | |
| 196 // chrome account. If multiple accounts are present in the cookie jar, a | |
| 197 // mismatch implies all of them are different from the chrome account. | |
| 198 bool cookie_jar_mismatch_; | |
| 199 | |
| 200 // If there's a cookie jar mismatch, whether the cookie jar was empty or not. | |
| 201 bool cookie_jar_empty_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); | |
| 204 }; | |
| 205 | |
| 206 } // namespace sessions | |
| 207 } // namespace syncer | |
| 208 | |
| 209 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ | |
| OLD | NEW |