| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 5 #ifndef SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| 6 #define SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 6 #define SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "net/base/network_change_notifier.h" | 11 #include "net/base/network_change_notifier.h" |
| 12 #include "sync/engine/all_status.h" | 12 #include "sync/engine/all_status.h" |
| 13 #include "sync/engine/net/server_connection_manager.h" | 13 #include "sync/engine/net/server_connection_manager.h" |
| 14 #include "sync/engine/sync_engine_event.h" | 14 #include "sync/engine/sync_engine_event.h" |
| 15 #include "sync/engine/throttled_data_type_tracker.h" | 15 #include "sync/engine/throttled_data_type_tracker.h" |
| 16 #include "sync/engine/traffic_recorder.h" | 16 #include "sync/engine/traffic_recorder.h" |
| 17 #include "sync/internal_api/change_reorder_buffer.h" | 17 #include "sync/internal_api/change_reorder_buffer.h" |
| 18 #include "sync/internal_api/debug_info_event_listener.h" | 18 #include "sync/internal_api/debug_info_event_listener.h" |
| 19 #include "sync/internal_api/js_mutation_event_observer.h" | 19 #include "sync/internal_api/js_mutation_event_observer.h" |
| 20 #include "sync/internal_api/js_sync_encryption_handler_observer.h" |
| 20 #include "sync/internal_api/js_sync_manager_observer.h" | 21 #include "sync/internal_api/js_sync_manager_observer.h" |
| 21 #include "sync/internal_api/public/sync_manager.h" | 22 #include "sync/internal_api/public/sync_manager.h" |
| 23 #include "sync/internal_api/sync_encryption_handler_impl.h" |
| 22 #include "sync/js/js_backend.h" | 24 #include "sync/js/js_backend.h" |
| 23 #include "sync/notifier/notifications_disabled_reason.h" | 25 #include "sync/notifier/notifications_disabled_reason.h" |
| 24 #include "sync/notifier/sync_notifier_observer.h" | 26 #include "sync/notifier/sync_notifier_observer.h" |
| 25 #include "sync/syncable/directory_change_delegate.h" | 27 #include "sync/syncable/directory_change_delegate.h" |
| 26 #include "sync/util/cryptographer.h" | 28 #include "sync/util/cryptographer.h" |
| 27 #include "sync/util/time.h" | 29 #include "sync/util/time.h" |
| 28 | 30 |
| 29 namespace syncer { | 31 namespace syncer { |
| 30 | 32 |
| 31 class SyncAPIServerConnectionManager; | 33 class SyncAPIServerConnectionManager; |
| 32 class WriteNode; | 34 class WriteNode; |
| 33 class WriteTransaction; | 35 class WriteTransaction; |
| 34 | 36 |
| 35 namespace sessions { | 37 namespace sessions { |
| 36 class SyncSessionContext; | 38 class SyncSessionContext; |
| 37 } | 39 } |
| 38 | 40 |
| 39 // SyncManager encapsulates syncable::Directory and serves as the parent of all | 41 // SyncManager encapsulates syncable::Directory and serves as the parent of all |
| 40 // other objects in the sync API. If multiple threads interact with the same | 42 // other objects in the sync API. If multiple threads interact with the same |
| 41 // local sync repository (i.e. the same sqlite database), they should share a | 43 // local sync repository (i.e. the same sqlite database), they should share a |
| 42 // single SyncManager instance. The caller should typically create one | 44 // single SyncManager instance. The caller should typically create one |
| 43 // SyncManager for the lifetime of a user session. | 45 // SyncManager for the lifetime of a user session. |
| 44 // | 46 // |
| 45 // Unless stated otherwise, all methods of SyncManager should be called on the | 47 // Unless stated otherwise, all methods of SyncManager should be called on the |
| 46 // same thread. | 48 // same thread. |
| 47 class SyncManagerImpl : public SyncManager, | 49 class SyncManagerImpl : public SyncManager, |
| 48 public net::NetworkChangeNotifier::IPAddressObserver, | 50 public net::NetworkChangeNotifier::IPAddressObserver, |
| 49 public Cryptographer::Observer, | |
| 50 public SyncNotifierObserver, | 51 public SyncNotifierObserver, |
| 51 public JsBackend, | 52 public JsBackend, |
| 52 public SyncEngineEventListener, | 53 public SyncEngineEventListener, |
| 53 public ServerConnectionEventListener, | 54 public ServerConnectionEventListener, |
| 54 public syncable::DirectoryChangeDelegate { | 55 public syncable::DirectoryChangeDelegate, |
| 56 public SyncEncryptionHandler::Observer { |
| 55 public: | 57 public: |
| 56 // Create an uninitialized SyncManager. Callers must Init() before using. | 58 // Create an uninitialized SyncManager. Callers must Init() before using. |
| 57 explicit SyncManagerImpl(const std::string& name); | 59 explicit SyncManagerImpl(const std::string& name); |
| 58 virtual ~SyncManagerImpl(); | 60 virtual ~SyncManagerImpl(); |
| 59 | 61 |
| 60 // SyncManager implementation. | 62 // SyncManager implementation. |
| 61 virtual void Init( | 63 virtual void Init( |
| 62 const FilePath& database_location, | 64 const FilePath& database_location, |
| 63 const WeakHandle<JsEventHandler>& event_handler, | 65 const WeakHandle<JsEventHandler>& event_handler, |
| 64 const std::string& sync_server_and_path, | 66 const std::string& sync_server_and_path, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 ModelTypeSet types) OVERRIDE; | 87 ModelTypeSet types) OVERRIDE; |
| 86 virtual bool PurgePartiallySyncedTypes() OVERRIDE; | 88 virtual bool PurgePartiallySyncedTypes() OVERRIDE; |
| 87 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; | 89 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; |
| 88 virtual void UpdateEnabledTypes( | 90 virtual void UpdateEnabledTypes( |
| 89 const ModelTypeSet& enabled_types) OVERRIDE; | 91 const ModelTypeSet& enabled_types) OVERRIDE; |
| 90 virtual void UpdateRegisteredInvalidationIds( | 92 virtual void UpdateRegisteredInvalidationIds( |
| 91 SyncNotifierObserver* handler, | 93 SyncNotifierObserver* handler, |
| 92 const ObjectIdSet& ids) OVERRIDE; | 94 const ObjectIdSet& ids) OVERRIDE; |
| 93 virtual void StartSyncingNormally( | 95 virtual void StartSyncingNormally( |
| 94 const ModelSafeRoutingInfo& routing_info) OVERRIDE; | 96 const ModelSafeRoutingInfo& routing_info) OVERRIDE; |
| 95 virtual void SetEncryptionPassphrase(const std::string& passphrase, | |
| 96 bool is_explicit) OVERRIDE; | |
| 97 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; | |
| 98 virtual void ConfigureSyncer( | 97 virtual void ConfigureSyncer( |
| 99 ConfigureReason reason, | 98 ConfigureReason reason, |
| 100 const ModelTypeSet& types_to_config, | 99 const ModelTypeSet& types_to_config, |
| 101 const ModelSafeRoutingInfo& new_routing_info, | 100 const ModelSafeRoutingInfo& new_routing_info, |
| 102 const base::Closure& ready_task, | 101 const base::Closure& ready_task, |
| 103 const base::Closure& retry_task) OVERRIDE; | 102 const base::Closure& retry_task) OVERRIDE; |
| 104 virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; | 103 virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; |
| 105 virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; | 104 virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; |
| 106 virtual SyncStatus GetDetailedStatus() const OVERRIDE; | 105 virtual SyncStatus GetDetailedStatus() const OVERRIDE; |
| 107 virtual bool IsUsingExplicitPassphrase() OVERRIDE; | |
| 108 virtual bool GetKeystoreKeyBootstrapToken(std::string* token) OVERRIDE; | 106 virtual bool GetKeystoreKeyBootstrapToken(std::string* token) OVERRIDE; |
| 109 virtual void SaveChanges() OVERRIDE; | 107 virtual void SaveChanges() OVERRIDE; |
| 110 virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE; | 108 virtual void StopSyncingForShutdown(const base::Closure& callback) OVERRIDE; |
| 111 virtual void ShutdownOnSyncThread() OVERRIDE; | 109 virtual void ShutdownOnSyncThread() OVERRIDE; |
| 112 virtual UserShare* GetUserShare() OVERRIDE; | 110 virtual UserShare* GetUserShare() OVERRIDE; |
| 113 | |
| 114 // Update the Cryptographer from the current nigori node and write back any | |
| 115 // necessary changes to the nigori node. We also detect missing encryption | |
| 116 // keys and write them into the nigori node. | |
| 117 // Also updates or adds the device information into the nigori node. | |
| 118 // Note: opens a transaction and can trigger an ON_PASSPHRASE_REQUIRED, so | |
| 119 // should only be called after syncapi is fully initialized. | |
| 120 // Calls the callback argument with true if cryptographer is ready, false | |
| 121 // otherwise. | |
| 122 virtual void RefreshNigori(const std::string& chrome_version, | |
| 123 const base::Closure& done_callback) OVERRIDE; | |
| 124 | |
| 125 virtual void EnableEncryptEverything() OVERRIDE; | |
| 126 virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; | 111 virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; |
| 127 virtual bool HasUnsyncedItems() OVERRIDE; | 112 virtual bool HasUnsyncedItems() OVERRIDE; |
| 113 virtual SyncEncryptionHandler* GetEncryptionHandler() OVERRIDE; |
| 114 |
| 115 // SyncEncryptionHandler::Observer implementation. |
| 116 virtual void OnPassphraseRequired( |
| 117 PassphraseRequiredReason reason, |
| 118 const sync_pb::EncryptedData& pending_keys) OVERRIDE; |
| 119 virtual void OnPassphraseAccepted() OVERRIDE; |
| 120 virtual void OnBootstrapTokenUpdated( |
| 121 const std::string& bootstrap_token) OVERRIDE; |
| 122 virtual void OnEncryptedTypesChanged( |
| 123 ModelTypeSet encrypted_types, |
| 124 bool encrypt_everything) OVERRIDE; |
| 125 virtual void OnEncryptionComplete() OVERRIDE; |
| 126 virtual void OnCryptographerStateChanged( |
| 127 Cryptographer* cryptographer) OVERRIDE; |
| 128 | 128 |
| 129 // Return the currently active (validated) username for use with syncable | 129 // Return the currently active (validated) username for use with syncable |
| 130 // types. | 130 // types. |
| 131 const std::string& username_for_share() const; | 131 const std::string& username_for_share() const; |
| 132 | 132 |
| 133 static int GetDefaultNudgeDelay(); | 133 static int GetDefaultNudgeDelay(); |
| 134 static int GetPreferencesNudgeDelay(); | 134 static int GetPreferencesNudgeDelay(); |
| 135 | 135 |
| 136 // SyncEngineEventListener implementation. | 136 // SyncEngineEventListener implementation. |
| 137 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; | 137 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 156 virtual ModelTypeSet HandleTransactionEndingChangeEvent( | 156 virtual ModelTypeSet HandleTransactionEndingChangeEvent( |
| 157 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 157 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 158 syncable::BaseTransaction* trans) OVERRIDE; | 158 syncable::BaseTransaction* trans) OVERRIDE; |
| 159 virtual void HandleCalculateChangesChangeEventFromSyncApi( | 159 virtual void HandleCalculateChangesChangeEventFromSyncApi( |
| 160 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 160 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 161 syncable::BaseTransaction* trans) OVERRIDE; | 161 syncable::BaseTransaction* trans) OVERRIDE; |
| 162 virtual void HandleCalculateChangesChangeEventFromSyncer( | 162 virtual void HandleCalculateChangesChangeEventFromSyncer( |
| 163 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 163 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 164 syncable::BaseTransaction* trans) OVERRIDE; | 164 syncable::BaseTransaction* trans) OVERRIDE; |
| 165 | 165 |
| 166 // Cryptographer::Observer implementation. | |
| 167 virtual void OnEncryptedTypesChanged( | |
| 168 ModelTypeSet encrypted_types, | |
| 169 bool encrypt_everything) OVERRIDE; | |
| 170 | |
| 171 // SyncNotifierObserver implementation. | 166 // SyncNotifierObserver implementation. |
| 172 virtual void OnNotificationsEnabled() OVERRIDE; | 167 virtual void OnNotificationsEnabled() OVERRIDE; |
| 173 virtual void OnNotificationsDisabled( | 168 virtual void OnNotificationsDisabled( |
| 174 NotificationsDisabledReason reason) OVERRIDE; | 169 NotificationsDisabledReason reason) OVERRIDE; |
| 175 virtual void OnIncomingNotification( | 170 virtual void OnIncomingNotification( |
| 176 const ObjectIdPayloadMap& id_payloads, | 171 const ObjectIdPayloadMap& id_payloads, |
| 177 IncomingNotificationSource source) OVERRIDE; | 172 IncomingNotificationSource source) OVERRIDE; |
| 178 | 173 |
| 179 // Called only by our NetworkChangeNotifier. | 174 // Called only by our NetworkChangeNotifier. |
| 180 virtual void OnIPAddressChanged() OVERRIDE; | 175 virtual void OnIPAddressChanged() OVERRIDE; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 225 |
| 231 // Purge those types from |previously_enabled_types| that are no longer | 226 // Purge those types from |previously_enabled_types| that are no longer |
| 232 // enabled in |currently_enabled_types|. | 227 // enabled in |currently_enabled_types|. |
| 233 bool PurgeDisabledTypes(ModelTypeSet previously_enabled_types, | 228 bool PurgeDisabledTypes(ModelTypeSet previously_enabled_types, |
| 234 ModelTypeSet currently_enabled_types); | 229 ModelTypeSet currently_enabled_types); |
| 235 | 230 |
| 236 void RequestNudgeForDataTypes( | 231 void RequestNudgeForDataTypes( |
| 237 const tracked_objects::Location& nudge_location, | 232 const tracked_objects::Location& nudge_location, |
| 238 ModelTypeSet type); | 233 ModelTypeSet type); |
| 239 | 234 |
| 240 void NotifyCryptographerState(Cryptographer* cryptographer); | |
| 241 | |
| 242 // If this is a deletion for a password, sets the legacy | 235 // If this is a deletion for a password, sets the legacy |
| 243 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets | 236 // ExtraPasswordChangeRecordData field of |buffer|. Otherwise sets |
| 244 // |buffer|'s specifics field to contain the unencrypted data. | 237 // |buffer|'s specifics field to contain the unencrypted data. |
| 245 void SetExtraChangeRecordData(int64 id, | 238 void SetExtraChangeRecordData(int64 id, |
| 246 ModelType type, | 239 ModelType type, |
| 247 ChangeReorderBuffer* buffer, | 240 ChangeReorderBuffer* buffer, |
| 248 Cryptographer* cryptographer, | 241 Cryptographer* cryptographer, |
| 249 const syncable::EntryKernel& original, | 242 const syncable::EntryKernel& original, |
| 250 bool existed_before, | 243 bool existed_before, |
| 251 bool exists_now); | 244 bool exists_now); |
| 252 | 245 |
| 253 // Stores the current set of encryption keys (if the cryptographer is ready) | 246 // Internal callback used by GetSessionName. |
| 254 // and encrypted types into the nigori node. | 247 // TODO(rlarocque): not currently called from anywhere. This should be |
| 255 void UpdateNigoriEncryptionState(Cryptographer* cryptographer, | 248 // hooked up to something once we start preserving device information again. |
| 256 WriteNode* nigori_node); | 249 void UpdateSessionNameCallback(const std::string& chrome_version, |
| 257 | 250 const std::string& session_name); |
| 258 // Internal callback of UpdateCryptographerAndNigoriCallback. | |
| 259 void UpdateCryptographerAndNigoriCallback( | |
| 260 const std::string& chrome_version, | |
| 261 const base::Closure& done_callback, | |
| 262 const std::string& session_name); | |
| 263 | |
| 264 // Updates the nigori node with any new encrypted types and then | |
| 265 // encrypts the nodes for those new data types as well as other | |
| 266 // nodes that should be encrypted but aren't. Triggers | |
| 267 // OnPassphraseRequired if the cryptographer isn't ready. | |
| 268 void RefreshEncryption(); | |
| 269 | |
| 270 void ReEncryptEverything(WriteTransaction* trans); | |
| 271 | |
| 272 // The final step of SetEncryptionPassphrase and SetDecryptionPassphrase that | |
| 273 // notifies observers of the result of the set passphrase operation, updates | |
| 274 // the nigori node, and does re-encryption. | |
| 275 // |success|: true if the operation was successful and false otherwise. If | |
| 276 // success == false, we send an OnPassphraseRequired notification. | |
| 277 // |bootstrap_token|: used to inform observers if the cryptographer's | |
| 278 // bootstrap token was updated. | |
| 279 // |is_explicit|: used to differentiate between a custom passphrase (true) and | |
| 280 // a GAIA passphrase that is implicitly used for encryption | |
| 281 // (false). | |
| 282 // |trans| and |nigori_node|: used to access data in the cryptographer. | |
| 283 void FinishSetPassphrase( | |
| 284 bool success, | |
| 285 const std::string& bootstrap_token, | |
| 286 bool is_explicit, | |
| 287 WriteTransaction* trans, | |
| 288 WriteNode* nigori_node); | |
| 289 | 251 |
| 290 // Called for every notification. This updates the notification statistics | 252 // Called for every notification. This updates the notification statistics |
| 291 // to be displayed in about:sync. | 253 // to be displayed in about:sync. |
| 292 void UpdateNotificationInfo( | 254 void UpdateNotificationInfo( |
| 293 const ModelTypePayloadMap& type_payloads); | 255 const ModelTypePayloadMap& type_payloads); |
| 294 | 256 |
| 295 // Checks for server reachabilty and requests a nudge. | 257 // Checks for server reachabilty and requests a nudge. |
| 296 void OnIPAddressChangedImpl(); | 258 void OnIPAddressChangedImpl(); |
| 297 | 259 |
| 298 // Helper function used only by the constructor. | 260 // Helper function used only by the constructor. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 354 |
| 393 // Map used to store the notification info to be displayed in | 355 // Map used to store the notification info to be displayed in |
| 394 // about:sync page. | 356 // about:sync page. |
| 395 NotificationInfoMap notification_info_map_; | 357 NotificationInfoMap notification_info_map_; |
| 396 | 358 |
| 397 // These are for interacting with chrome://sync-internals. | 359 // These are for interacting with chrome://sync-internals. |
| 398 JsMessageHandlerMap js_message_handlers_; | 360 JsMessageHandlerMap js_message_handlers_; |
| 399 WeakHandle<JsEventHandler> js_event_handler_; | 361 WeakHandle<JsEventHandler> js_event_handler_; |
| 400 JsSyncManagerObserver js_sync_manager_observer_; | 362 JsSyncManagerObserver js_sync_manager_observer_; |
| 401 JsMutationEventObserver js_mutation_event_observer_; | 363 JsMutationEventObserver js_mutation_event_observer_; |
| 364 JsSyncEncryptionHandlerObserver js_sync_encryption_handler_observer_; |
| 402 | 365 |
| 403 ThrottledDataTypeTracker throttled_data_type_tracker_; | 366 ThrottledDataTypeTracker throttled_data_type_tracker_; |
| 404 | 367 |
| 405 // This is for keeping track of client events to send to the server. | 368 // This is for keeping track of client events to send to the server. |
| 406 DebugInfoEventListener debug_info_event_listener_; | 369 DebugInfoEventListener debug_info_event_listener_; |
| 407 | 370 |
| 408 TrafficRecorder traffic_recorder_; | 371 TrafficRecorder traffic_recorder_; |
| 409 | 372 |
| 410 Encryptor* encryptor_; | 373 Encryptor* encryptor_; |
| 411 UnrecoverableErrorHandler* unrecoverable_error_handler_; | 374 UnrecoverableErrorHandler* unrecoverable_error_handler_; |
| 412 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; | 375 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; |
| 413 | 376 |
| 414 // The number of times we've automatically (i.e. not via SetPassphrase or | 377 // Sync's encryption handler. It tracks the set of encrypted types, manages |
| 415 // conflict resolver) updated the nigori's encryption keys in this chrome | 378 // changing passphrases, and in general handles sync-specific interactions |
| 416 // instantiation. | 379 // with the cryptographer. |
| 417 int nigori_overwrite_count_; | 380 scoped_ptr<SyncEncryptionHandlerImpl> sync_encryption_handler_; |
| 418 | 381 |
| 419 DISALLOW_COPY_AND_ASSIGN(SyncManagerImpl); | 382 DISALLOW_COPY_AND_ASSIGN(SyncManagerImpl); |
| 420 }; | 383 }; |
| 421 | 384 |
| 422 } // namespace syncer | 385 } // namespace syncer |
| 423 | 386 |
| 424 #endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 387 #endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| OLD | NEW |